lorj 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
data/lib/rh.rb
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'yaml'
|
|
20
|
+
|
|
21
|
+
# Recursive Hash added to the Hash class
|
|
22
|
+
class Hash
|
|
23
|
+
# Recursive Hash deep level found counter
|
|
24
|
+
# This function will returns the count of deep level of recursive hash.
|
|
25
|
+
# * *Args* :
|
|
26
|
+
# - +p+ : Array of string or symbols. keys tree to follow and check
|
|
27
|
+
# existence in yVal.
|
|
28
|
+
#
|
|
29
|
+
# * *Returns* :
|
|
30
|
+
# - +integer+ : Represents how many deep level was found in the recursive
|
|
31
|
+
# hash
|
|
32
|
+
#
|
|
33
|
+
# * *Raises* :
|
|
34
|
+
# No exceptions
|
|
35
|
+
#
|
|
36
|
+
# Example: (implemented in spec)
|
|
37
|
+
#
|
|
38
|
+
# yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
|
|
39
|
+
# :test4 => 'value3'}
|
|
40
|
+
#
|
|
41
|
+
# yVal can be represented like:
|
|
42
|
+
#
|
|
43
|
+
# yVal:
|
|
44
|
+
# test:
|
|
45
|
+
# test2 = 'value1'
|
|
46
|
+
# test3 = 'value2'
|
|
47
|
+
# test4 = 'value3'
|
|
48
|
+
#
|
|
49
|
+
# so:
|
|
50
|
+
# # test is found
|
|
51
|
+
# yVal.rh_lexist?(:test) => 1
|
|
52
|
+
#
|
|
53
|
+
# # no test5
|
|
54
|
+
# yVal.rh_lexist?(:test5) => 0
|
|
55
|
+
#
|
|
56
|
+
# # :test/:test2 tree is found
|
|
57
|
+
# yVal.rh_lexist?(:test, :test2) => 2
|
|
58
|
+
#
|
|
59
|
+
# # :test/:test2 is found (value = 2), but :test5 was not found in this tree
|
|
60
|
+
# yVal.rh_lexist?(:test, :test2, :test5) => 2
|
|
61
|
+
#
|
|
62
|
+
# # :test was found. but :test/:test5 tree was not found. so level 1, ok.
|
|
63
|
+
# yVal.rh_lexist?(:test, :test5 ) => 1
|
|
64
|
+
#
|
|
65
|
+
# # it is like searching for nothing...
|
|
66
|
+
# yVal.rh_lexist? => 0
|
|
67
|
+
|
|
68
|
+
def rh_lexist?(*p)
|
|
69
|
+
return 0 if p.length == 0
|
|
70
|
+
|
|
71
|
+
p = p.flatten
|
|
72
|
+
if p.length == 1
|
|
73
|
+
return 1 if self.key?(p[0])
|
|
74
|
+
return 0
|
|
75
|
+
end
|
|
76
|
+
return 0 unless self.key?(p[0])
|
|
77
|
+
ret = 0
|
|
78
|
+
ret = self[p[0]].rh_lexist?(p.drop(1)) if self[p[0]].is_a?(Hash)
|
|
79
|
+
1 + ret
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Recursive Hash deep level existence
|
|
83
|
+
#
|
|
84
|
+
# * *Args* :
|
|
85
|
+
# - +p+ : Array of string or symbols. keys tree to follow and check
|
|
86
|
+
# existence in yVal.
|
|
87
|
+
#
|
|
88
|
+
# * *Returns* :
|
|
89
|
+
# - +boolean+ : Returns True if the deep level of recursive hash is found.
|
|
90
|
+
# false otherwise
|
|
91
|
+
#
|
|
92
|
+
# * *Raises* :
|
|
93
|
+
# No exceptions
|
|
94
|
+
#
|
|
95
|
+
# Example:(implemented in spec)
|
|
96
|
+
#
|
|
97
|
+
# yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
|
|
98
|
+
# :test4 => 'value3'}
|
|
99
|
+
#
|
|
100
|
+
# yVal can be represented like:
|
|
101
|
+
#
|
|
102
|
+
# yVal:
|
|
103
|
+
# test:
|
|
104
|
+
# test2 = 'value1'
|
|
105
|
+
# test3 = 'value2'
|
|
106
|
+
# test4 = 'value3'
|
|
107
|
+
#
|
|
108
|
+
# so:
|
|
109
|
+
# # test is found
|
|
110
|
+
# yVal.rh_exist?(:test) => True
|
|
111
|
+
#
|
|
112
|
+
# # no test5
|
|
113
|
+
# yVal.rh_exist?(:test5) => False
|
|
114
|
+
#
|
|
115
|
+
# # :test/:test2 tree is found
|
|
116
|
+
# yVal.rh_exist?(:test, :test2) => True
|
|
117
|
+
#
|
|
118
|
+
# # :test/:test2 is found (value = 2), but :test5 was not found in this tree
|
|
119
|
+
# yVal.rh_exist?(:test, :test2, :test5) => False
|
|
120
|
+
#
|
|
121
|
+
# # :test was found. but :test/:test5 tree was not found. so level 1, ok.
|
|
122
|
+
# yVal.rh_exist?(:test, :test5 ) => False
|
|
123
|
+
#
|
|
124
|
+
# # it is like searching for nothing...
|
|
125
|
+
# yVal.rh_exist? => nil
|
|
126
|
+
def rh_exist?(*p)
|
|
127
|
+
return nil if p.length == 0
|
|
128
|
+
|
|
129
|
+
count = p.length
|
|
130
|
+
(rh_lexist?(*p) == count)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Recursive Hash Get
|
|
134
|
+
# This function will returns the level of recursive hash was found.
|
|
135
|
+
# * *Args* :
|
|
136
|
+
# - +p+ : Array of string or symbols. keys tree to follow and check
|
|
137
|
+
# existence in yVal.
|
|
138
|
+
#
|
|
139
|
+
# * *Returns* :
|
|
140
|
+
# - +value+ : Represents the data found in the tree. Can be of any type.
|
|
141
|
+
#
|
|
142
|
+
# * *Raises* :
|
|
143
|
+
# No exceptions
|
|
144
|
+
#
|
|
145
|
+
# Example:(implemented in spec)
|
|
146
|
+
#
|
|
147
|
+
# yVal = { :test => {:test2 => 'value1', :test3 => 'value2'},
|
|
148
|
+
# :test4 => 'value3'}
|
|
149
|
+
#
|
|
150
|
+
# yVal can be represented like:
|
|
151
|
+
#
|
|
152
|
+
# yVal:
|
|
153
|
+
# test:
|
|
154
|
+
# test2 = 'value1'
|
|
155
|
+
# test3 = 'value2'
|
|
156
|
+
# test4 = 'value3'
|
|
157
|
+
#
|
|
158
|
+
# so:
|
|
159
|
+
# yVal.rh_get(:test) => {:test2 => 'value1', :test3 => 'value2'}
|
|
160
|
+
# yVal.rh_get(:test5) => nil
|
|
161
|
+
# yVal.rh_get(:test, :test2) => 'value1'
|
|
162
|
+
# yVal.rh_get(:test, :test2, :test5) => nil
|
|
163
|
+
# yVal.rh_get(:test, :test5 ) => nil
|
|
164
|
+
# yVal.rh_get => { :test => {:test2 => 'value1', :test3 => 'value2'},
|
|
165
|
+
# :test4 => 'value3'}
|
|
166
|
+
def rh_get(*p)
|
|
167
|
+
p = p.flatten
|
|
168
|
+
return self if p.length == 0
|
|
169
|
+
|
|
170
|
+
if p.length == 1
|
|
171
|
+
return self[p[0]] if self.key?(p[0])
|
|
172
|
+
return nil
|
|
173
|
+
end
|
|
174
|
+
return self[p[0]].rh_get(p.drop(1)) if self[p[0]].is_a?(Hash)
|
|
175
|
+
nil
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Recursive Hash Set
|
|
179
|
+
# This function will build a recursive hash according to the '*p' key tree.
|
|
180
|
+
# if yVal is not nil, it will be updated.
|
|
181
|
+
#
|
|
182
|
+
# * *Args* :
|
|
183
|
+
# - +p+ : Array of string or symbols. keys tree to follow and check
|
|
184
|
+
# existence in yVal.
|
|
185
|
+
#
|
|
186
|
+
# * *Returns* :
|
|
187
|
+
# - +value+ : the value set.
|
|
188
|
+
#
|
|
189
|
+
# * *Raises* :
|
|
190
|
+
# No exceptions
|
|
191
|
+
#
|
|
192
|
+
# Example:(implemented in spec)
|
|
193
|
+
#
|
|
194
|
+
# yVal = {}
|
|
195
|
+
#
|
|
196
|
+
# yVal.rh_set(:test) => nil
|
|
197
|
+
# # yVal = {}
|
|
198
|
+
#
|
|
199
|
+
# yVal.rh_set(:test5) => nil
|
|
200
|
+
# # yVal = {}
|
|
201
|
+
#
|
|
202
|
+
# yVal.rh_set(:test, :test2) => :test
|
|
203
|
+
# # yVal = {:test2 => :test}
|
|
204
|
+
#
|
|
205
|
+
# yVal.rh_set(:test, :test2, :test5) => :test
|
|
206
|
+
# # yVal = {:test2 => {:test5 => :test} }
|
|
207
|
+
#
|
|
208
|
+
# yVal.rh_set(:test, :test5 ) => :test
|
|
209
|
+
# # yVal = {:test2 => {:test5 => :test}, :test5 => :test }
|
|
210
|
+
#
|
|
211
|
+
# yVal.rh_set('blabla', :test2, 'text') => :test
|
|
212
|
+
# # yVal = {:test2 => {:test5 => :test, 'text' => 'blabla'},
|
|
213
|
+
# :test5 => :test }
|
|
214
|
+
def rh_set(value, *p)
|
|
215
|
+
return nil if p.length == 0
|
|
216
|
+
|
|
217
|
+
p = p.flatten
|
|
218
|
+
if p.length == 1
|
|
219
|
+
self[p[0]] = value
|
|
220
|
+
return value
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
self[p[0]] = {} unless self[p[0]].is_a?(Hash)
|
|
224
|
+
self[p[0]].rh_set(value, p.drop(1))
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Recursive Hash delete
|
|
228
|
+
# This function will remove the last key defined by the key tree
|
|
229
|
+
#
|
|
230
|
+
# * *Args* :
|
|
231
|
+
# - +p+ : Array of string or symbols. keys tree to follow and check
|
|
232
|
+
# existence in yVal.
|
|
233
|
+
#
|
|
234
|
+
# * *Returns* :
|
|
235
|
+
# - +value+ : The Hash updated.
|
|
236
|
+
#
|
|
237
|
+
# * *Raises* :
|
|
238
|
+
# No exceptions
|
|
239
|
+
#
|
|
240
|
+
# Example:(implemented in spec)
|
|
241
|
+
#
|
|
242
|
+
# yVal = {{:test2 => { :test5 => :test,
|
|
243
|
+
# 'text' => 'blabla' },
|
|
244
|
+
# :test5 => :test}}
|
|
245
|
+
#
|
|
246
|
+
#
|
|
247
|
+
# yVal.rh_del(:test) => nil
|
|
248
|
+
# # yVal = no change
|
|
249
|
+
#
|
|
250
|
+
# yVal.rh_del(:test, :test2) => nil
|
|
251
|
+
# # yVal = no change
|
|
252
|
+
#
|
|
253
|
+
# yVal.rh_del(:test2, :test5) => {:test5 => :test}
|
|
254
|
+
# # yVal = {:test2 => {:test5 => :test} }
|
|
255
|
+
#
|
|
256
|
+
# yVal.rh_del(:test, :test2)
|
|
257
|
+
# # yVal = {:test2 => {:test5 => :test} }
|
|
258
|
+
#
|
|
259
|
+
# yVal.rh_del(:test, :test5)
|
|
260
|
+
# # yVal = {:test2 => {} }
|
|
261
|
+
#
|
|
262
|
+
def rh_del(*p)
|
|
263
|
+
return nil if p.length == 0
|
|
264
|
+
|
|
265
|
+
p = p.flatten
|
|
266
|
+
return delete(p[0]) if p.length == 1
|
|
267
|
+
|
|
268
|
+
return nil if self[p[0]].nil?
|
|
269
|
+
self[p[0]].rh_del(p.drop(1))
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Move levels (default level 1) of tree keys to become symbol.
|
|
273
|
+
#
|
|
274
|
+
# * *Args* :
|
|
275
|
+
# - +levels+: level of key tree to update.
|
|
276
|
+
# * *Returns* :
|
|
277
|
+
# - a new hash of hashes updated. Original Hash is not updated anymore.
|
|
278
|
+
#
|
|
279
|
+
# examples:
|
|
280
|
+
# With hdata = { :test => { :test2 => { :test5 => :test,
|
|
281
|
+
# 'text' => 'blabla' },
|
|
282
|
+
# 'test5' => 'test' }}
|
|
283
|
+
#
|
|
284
|
+
# rh_key_to_symbol(1) return no diff
|
|
285
|
+
# rh_key_to_symbol(2) return "test5" is replaced by :test5
|
|
286
|
+
# # hdata = { :test => { :test2 => { :test5 => :test,
|
|
287
|
+
# # 'text' => 'blabla' },
|
|
288
|
+
# # :test5 => 'test' }}
|
|
289
|
+
# rh_key_to_symbol(3) return "test5" replaced by :test5, and "text" to :text
|
|
290
|
+
# # hdata = { :test => { :test2 => { :test5 => :test,
|
|
291
|
+
# # :text => 'blabla' },
|
|
292
|
+
# # :test5 => 'test' }}
|
|
293
|
+
# rh_key_to_symbol(4) same like rh_key_to_symbol(3)
|
|
294
|
+
|
|
295
|
+
def rh_key_to_symbol(levels = 1)
|
|
296
|
+
result = {}
|
|
297
|
+
each do | key, value |
|
|
298
|
+
new_key = key
|
|
299
|
+
new_key = key.to_sym if key.is_a?(String)
|
|
300
|
+
if value.is_a?(Hash) && levels > 1
|
|
301
|
+
value = value.rh_key_to_symbol(levels - 1)
|
|
302
|
+
end
|
|
303
|
+
result[new_key] = value
|
|
304
|
+
end
|
|
305
|
+
result
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Check if levels of tree keys are all symbols.
|
|
309
|
+
#
|
|
310
|
+
# * *Args* :
|
|
311
|
+
# - +levels+: level of key tree to update.
|
|
312
|
+
# * *Returns* :
|
|
313
|
+
# - true : one key path is not symbol.
|
|
314
|
+
# - false : all key path are symbols.
|
|
315
|
+
# * *Raises* :
|
|
316
|
+
# Nothing
|
|
317
|
+
#
|
|
318
|
+
# examples:
|
|
319
|
+
# With hdata = { :test => { :test2 => { :test5 => :test,
|
|
320
|
+
# 'text' => 'blabla' },
|
|
321
|
+
# 'test5' => 'test' }}
|
|
322
|
+
#
|
|
323
|
+
# rh_key_to_symbol?(1) return false
|
|
324
|
+
# rh_key_to_symbol?(2) return true
|
|
325
|
+
# rh_key_to_symbol?(3) return true
|
|
326
|
+
# rh_key_to_symbol?(4) return true
|
|
327
|
+
def rh_key_to_symbol?(levels = 1)
|
|
328
|
+
each do | key, value |
|
|
329
|
+
return true if key.is_a?(String)
|
|
330
|
+
|
|
331
|
+
res = false
|
|
332
|
+
if levels > 1 && value.is_a?(Hash)
|
|
333
|
+
res = value.rh_key_to_symbol?(levels - 1)
|
|
334
|
+
end
|
|
335
|
+
return true if res
|
|
336
|
+
end
|
|
337
|
+
false
|
|
338
|
+
end
|
|
339
|
+
end
|
data/lorj-spec/defaults.yaml
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
# Defaults yaml file used for rspec.
|
|
16
16
|
:default:
|
|
17
17
|
:maestro_url: http://example.org
|
|
18
|
+
:keypair_name: default_key
|
|
19
|
+
:data: None
|
|
18
20
|
|
|
19
21
|
:description:
|
|
20
22
|
:FORJ_HPC: Testing extra application default value.
|
|
@@ -22,5 +24,7 @@
|
|
|
22
24
|
:sections:
|
|
23
25
|
:credentials:
|
|
24
26
|
:keypair_name:
|
|
27
|
+
:data:
|
|
28
|
+
:account_exclusive: true
|
|
25
29
|
:maestro:
|
|
26
30
|
:maestro_url:
|
data/lorj.gemspec
CHANGED
|
@@ -3,6 +3,11 @@ lib = File.expand_path('../lib', __FILE__)
|
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'lorj/version'
|
|
5
5
|
|
|
6
|
+
require 'rbconfig'
|
|
7
|
+
ruby_conf = defined?(RbConfig) ? RbConfig::CONFIG : Config::CONFIG
|
|
8
|
+
less_than_one_nine = ruby_conf['MAJOR'].to_i == 1 && ruby_conf['MINOR'].to_i < 9
|
|
9
|
+
less_than_two = ruby_conf['MAJOR'].to_i < 2
|
|
10
|
+
|
|
6
11
|
Gem::Specification.new do |spec|
|
|
7
12
|
spec.name = 'lorj'
|
|
8
13
|
spec.version = Lorj::VERSION
|
|
@@ -24,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
|
24
29
|
spec.add_development_dependency 'bundler'
|
|
25
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
26
31
|
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
|
32
|
+
spec.add_development_dependency 'byebug' unless less_than_two
|
|
27
33
|
spec.rdoc_options << \
|
|
28
34
|
'--title Lorj - The Process Controllers framework system' << \
|
|
29
35
|
'--main README.md'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
# require 'rubygems'
|
|
19
|
+
# require 'byebug'
|
|
20
|
+
# require 'bundler/setup'
|
|
21
|
+
|
|
22
|
+
app_path = File.dirname(File.dirname(__FILE__))
|
|
23
|
+
|
|
24
|
+
$LOAD_PATH << './lib'
|
|
25
|
+
|
|
26
|
+
# This spec HAVE to the the first one executed!
|
|
27
|
+
# Do never create a file or rename this file, which will
|
|
28
|
+
# move this spec later in the spec test system
|
|
29
|
+
# as soon as a first message is sent, the object gets created.
|
|
30
|
+
# Any PrcLib::level should be moved in the first test code executed.
|
|
31
|
+
# otherwise, you will break the first test in this file.
|
|
32
|
+
|
|
33
|
+
describe 'Module: Lorj,' do
|
|
34
|
+
context 'Initializing' do
|
|
35
|
+
it 'PrcLib module exist' do
|
|
36
|
+
require 'lorj' # Load lorj framework
|
|
37
|
+
expect(PrcLib.class).to equal(Module)
|
|
38
|
+
|
|
39
|
+
expect(PrcLib.log).to be_nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'create PrcLib.log object at first message' do
|
|
43
|
+
PrcLib.log_file = 'lorj-rspec.log'
|
|
44
|
+
PrcLib.level = Logger::FATAL
|
|
45
|
+
PrcLib.app_name = 'lorj-spec'
|
|
46
|
+
PrcLib.app_defaults = File.join(app_path, 'lorj-spec')
|
|
47
|
+
|
|
48
|
+
PrcLib.debug 'Rspec logging ...'
|
|
49
|
+
|
|
50
|
+
expect(PrcLib.log).to_not be_nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
|
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH << File.join('..', 'lib')
|
|
19
|
+
|
|
20
|
+
require 'rh'
|
|
21
|
+
|
|
22
|
+
describe 'Recursive Hash extension,' do
|
|
23
|
+
context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
|
|
24
|
+
":test4 => 'value3'}" do
|
|
25
|
+
before(:all) do
|
|
26
|
+
@hdata = { :test => { :test2 => 'value1', :test3 => 'value2' },
|
|
27
|
+
:test4 => 'value3' }
|
|
28
|
+
end
|
|
29
|
+
it 'rh_lexist?(:test) return 1' do
|
|
30
|
+
expect(@hdata.rh_lexist?(:test)).to eq(1)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'rh_lexist?(:test5) return 0' do
|
|
34
|
+
expect(@hdata.rh_lexist?(:test5)).to eq(0)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'rh_lexist?(:test, :test2) return 2' do
|
|
38
|
+
expect(@hdata.rh_lexist?(:test, :test2)).to eq(2)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'rh_lexist?(:test, :test2, :test5) return 2' do
|
|
42
|
+
expect(@hdata.rh_lexist?(:test, :test2, :test5)).to eq(2)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'rh_lexist?(:test, :test5 ) return 1' do
|
|
46
|
+
expect(@hdata.rh_lexist?(:test, :test5)).to eq(1)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'rh_lexist? return 0' do
|
|
50
|
+
expect(@hdata.rh_lexist?).to eq(0)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
|
|
55
|
+
":test4 => 'value3'}" do
|
|
56
|
+
before(:all) do
|
|
57
|
+
@hdata = { :test => { :test2 => 'value1', :test3 => 'value2' },
|
|
58
|
+
:test4 => 'value3' }
|
|
59
|
+
end
|
|
60
|
+
it 'rh_exist?(:test) return true' do
|
|
61
|
+
expect(@hdata.rh_exist?(:test)).to equal(true)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'rh_exist?(:test5) return false' do
|
|
65
|
+
expect(@hdata.rh_exist?(:test5)).to equal(false)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'rh_exist?(:test, :test2) return true' do
|
|
69
|
+
expect(@hdata.rh_exist?(:test, :test2)).to equal(true)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'rh_exist?(:test, :test2, :test5) return false' do
|
|
73
|
+
expect(@hdata.rh_exist?(:test, :test2, :test5)).to equal(false)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'rh_exist?(:test, :test5 ) return false' do
|
|
77
|
+
expect(@hdata.rh_exist?(:test, :test5)).to equal(false)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'rh_exist? return nil' do
|
|
81
|
+
expect(@hdata.rh_exist?).to eq(nil)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "With { :test => {:test2 => 'value1', :test3 => 'value2'},"\
|
|
86
|
+
":test4 => 'value3'}" do
|
|
87
|
+
before(:all) do
|
|
88
|
+
@hdata = { :test => { :test2 => 'value1',
|
|
89
|
+
:test3 => 'value2' },
|
|
90
|
+
:test4 => 'value3' }
|
|
91
|
+
end
|
|
92
|
+
it "rh_get(:test) return {:test2 => 'value1', :test3 => 'value2'}" do
|
|
93
|
+
expect(@hdata.rh_get(:test)).to eq(:test2 => 'value1',
|
|
94
|
+
:test3 => 'value2')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'rh_get(:test5) return nil' do
|
|
98
|
+
expect(@hdata.rh_get(:test5)).to equal(nil)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "rh_get(:test, :test2) return 'value1'" do
|
|
102
|
+
expect(@hdata.rh_get(:test, :test2)).to eq('value1')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'rh_get(:test, :test2, :test5) return nil' do
|
|
106
|
+
expect(@hdata.rh_get(:test, :test2, :test5)).to equal(nil)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'rh_get(:test, :test5) return nil' do
|
|
110
|
+
expect(@hdata.rh_get(:test, :test5)).to equal(nil)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'rh_get return original data' do
|
|
114
|
+
expect(@hdata.rh_get).to eq(:test => { :test2 => 'value1',
|
|
115
|
+
:test3 => 'value2' },
|
|
116
|
+
:test4 => 'value3')
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context 'With hdata = {}' do
|
|
121
|
+
before(:all) do
|
|
122
|
+
@hdata = {}
|
|
123
|
+
end
|
|
124
|
+
it 'rh_set(:test) return nil, with no change to hdata.' do
|
|
125
|
+
expect(@hdata.rh_set(:test)).to equal(nil)
|
|
126
|
+
expect(@hdata).to eq({})
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'rh_set(:test, :test2) add a new element :test2 => :test' do
|
|
130
|
+
expect(@hdata.rh_set(:test, :test2)).to eq(:test)
|
|
131
|
+
expect(@hdata).to eq(:test2 => :test)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'rh_set(:test, :test2, :test5) replace :test2 by :test5 => :test' do
|
|
135
|
+
expect(@hdata.rh_set(:test, :test2, :test5)).to eq(:test)
|
|
136
|
+
expect(@hdata).to eq(:test2 => { :test5 => :test })
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'rh_set(:test, :test5 ) add :test5 => :test, colocated with :test2' do
|
|
140
|
+
expect(@hdata.rh_set(:test, :test5)).to equal(:test)
|
|
141
|
+
expect(@hdata).to eq(:test2 => { :test5 => :test },
|
|
142
|
+
:test5 => :test)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "rh_set('blabla', :test2, 'text') add a 'test' => 'blabla' under"\
|
|
146
|
+
' :test2, colocated with ẗest5 ' do
|
|
147
|
+
expect(@hdata.rh_set('blabla', :test2, 'text')).to eq('blabla')
|
|
148
|
+
expect(@hdata).to eq(:test2 => { :test5 => :test,
|
|
149
|
+
'text' => 'blabla' },
|
|
150
|
+
:test5 => :test)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'rh_set(nil, :test2) remove :test2 value' do
|
|
154
|
+
expect(@hdata.rh_set(nil, :test2)).to equal(nil)
|
|
155
|
+
expect(@hdata).to eq(:test2 => nil,
|
|
156
|
+
:test5 => :test)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context 'With hdata = {:test2 => { :test5 => :test,'\
|
|
161
|
+
"'text' => 'blabla' },"\
|
|
162
|
+
':test5 => :test}' do
|
|
163
|
+
before(:all) do
|
|
164
|
+
@hdata = { :test2 => { :test5 => :test,
|
|
165
|
+
'text' => 'blabla' },
|
|
166
|
+
:test5 => :test }
|
|
167
|
+
end
|
|
168
|
+
it 'rh_del(:test) return nil, with no change to hdata.' do
|
|
169
|
+
expect(@hdata.rh_del(:test)).to equal(nil)
|
|
170
|
+
expect(@hdata).to eq(:test2 => { :test5 => :test,
|
|
171
|
+
'text' => 'blabla' },
|
|
172
|
+
:test5 => :test)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'rh_del(:test, :test2) return nil, with no change to hdata.' do
|
|
176
|
+
expect(@hdata.rh_del(:test, :test2)).to eq(nil)
|
|
177
|
+
expect(@hdata).to eq(:test2 => { :test5 => :test,
|
|
178
|
+
'text' => 'blabla' },
|
|
179
|
+
:test5 => :test)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it 'rh_del(:test2, :test5) remove :test5 keys tree from :test2' do
|
|
183
|
+
expect(@hdata.rh_del(:test2, :test5)).to eq(:test)
|
|
184
|
+
expect(@hdata).to eq(:test2 => { 'text' => 'blabla' },
|
|
185
|
+
:test5 => :test)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'rh_del(:test5 ) remove :test5' do
|
|
189
|
+
expect(@hdata.rh_del(:test5)).to equal(:test)
|
|
190
|
+
expect(@hdata).to eq(:test2 => { 'text' => 'blabla' })
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'rh_del(:test2) remove the :test2. hdata is now {}.'\
|
|
194
|
+
' :test2, colocated with ẗest5 ' do
|
|
195
|
+
expect(@hdata.rh_del(:test2)).to eq('text' => 'blabla')
|
|
196
|
+
expect(@hdata).to eq({})
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
context 'With hdata = { :test => { :test2 => { :test5 => :test,'\
|
|
200
|
+
"'text' => 'blabla' },"\
|
|
201
|
+
"'test5' => 'test' }}" do
|
|
202
|
+
before(:all) do
|
|
203
|
+
@hdata = { :test => { :test2 => { :test5 => :test,
|
|
204
|
+
'text' => 'blabla' },
|
|
205
|
+
'test5' => 'test' } }
|
|
206
|
+
end
|
|
207
|
+
it 'rh_key_to_symbol?(1) return false' do
|
|
208
|
+
expect(@hdata.rh_key_to_symbol?(1)).to equal(false)
|
|
209
|
+
end
|
|
210
|
+
it 'rh_key_to_symbol?(2) return true' do
|
|
211
|
+
expect(@hdata.rh_key_to_symbol?(2)).to equal(true)
|
|
212
|
+
end
|
|
213
|
+
it 'rh_key_to_symbol?(3) return true' do
|
|
214
|
+
expect(@hdata.rh_key_to_symbol?(3)).to equal(true)
|
|
215
|
+
end
|
|
216
|
+
it 'rh_key_to_symbol?(4) return true' do
|
|
217
|
+
expect(@hdata.rh_key_to_symbol?(4)).to equal(true)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it 'rh_key_to_symbol(1) return no diff' do
|
|
221
|
+
expect(@hdata.rh_key_to_symbol(1)
|
|
222
|
+
).to eq(:test => { :test2 => { :test5 => :test,
|
|
223
|
+
'text' => 'blabla' },
|
|
224
|
+
'test5' => 'test' })
|
|
225
|
+
end
|
|
226
|
+
it 'rh_key_to_symbol(2) return "test5" is replaced by :ẗest5' do
|
|
227
|
+
expect(@hdata.rh_key_to_symbol(2)
|
|
228
|
+
).to eq(:test => { :test2 => { :test5 => :test,
|
|
229
|
+
'text' => 'blabla' },
|
|
230
|
+
:test5 => 'test' })
|
|
231
|
+
end
|
|
232
|
+
it 'rh_key_to_symbol(3) return "test5" replaced by :ẗest5, '\
|
|
233
|
+
'and "text" to :text' do
|
|
234
|
+
expect(@hdata.rh_key_to_symbol(3)
|
|
235
|
+
).to eq(:test => { :test2 => { :test5 => :test,
|
|
236
|
+
:text => 'blabla' },
|
|
237
|
+
:test5 => 'test' })
|
|
238
|
+
end
|
|
239
|
+
it 'rh_key_to_symbol(4) same like rh_key_to_symbol(3)' do
|
|
240
|
+
expect(@hdata.rh_key_to_symbol(4)).to eq(@hdata.rh_key_to_symbol(3))
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|