lorj 1.0.3 → 1.0.4

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/example/students_1/students.rb +5 -6
  3. data/example/students_2/students.rb +4 -5
  4. data/example/students_3/students.rb +4 -5
  5. data/example/students_4/students.rb +4 -5
  6. data/example/students_5/students.rb +5 -5
  7. data/lib/core/core.rb +6 -1
  8. data/lib/core/core_controller.rb +1 -9
  9. data/lib/core/core_internal.rb +2 -1
  10. data/lib/core/core_model.rb +2 -10
  11. data/lib/core/core_object_data.rb +18 -0
  12. data/lib/core/core_object_params.rb +43 -4
  13. data/lib/core/core_process.rb +1 -9
  14. data/lib/core/core_process_setup.rb +32 -6
  15. data/lib/core/core_setup_ask.rb +41 -33
  16. data/lib/core/core_setup_encrypt.rb +29 -6
  17. data/lib/core/core_setup_init.rb +2 -2
  18. data/lib/core/definition.rb +33 -10
  19. data/lib/core/definition_internal.rb +10 -14
  20. data/lib/core/lorj_basedefinition.rb +16 -24
  21. data/lib/core/lorj_baseprocess.rb +113 -44
  22. data/lib/core/lorj_data.rb +2 -9
  23. data/lib/core/lorj_keypath.rb +5 -2
  24. data/lib/core_process/cloud/process/common.rb +4 -7
  25. data/lib/core_process/cloud/process/connection.rb +44 -45
  26. data/lib/core_process/cloud/process/external_network.rb +24 -28
  27. data/lib/core_process/cloud/process/flavor.rb +31 -34
  28. data/lib/core_process/cloud/process/images.rb +12 -15
  29. data/lib/core_process/cloud/process/internet_network.rb +13 -14
  30. data/lib/core_process/cloud/process/internet_server.rb +9 -10
  31. data/lib/core_process/cloud/process/keypairs.rb +34 -27
  32. data/lib/core_process/cloud/process/network.rb +21 -23
  33. data/lib/core_process/cloud/process/public_ip.rb +17 -18
  34. data/lib/core_process/cloud/process/router.rb +86 -92
  35. data/lib/core_process/cloud/process/rules.rb +30 -31
  36. data/lib/core_process/cloud/process/security_groups.rb +21 -22
  37. data/lib/core_process/cloud/process/server.rb +30 -31
  38. data/lib/core_process/cloud/process/server_log.rb +13 -14
  39. data/lib/core_process/cloud/process/subnetwork.rb +25 -40
  40. data/lib/logging.rb +4 -17
  41. data/lib/lorj/version.rb +1 -1
  42. data/lib/lorj.rb +2 -1
  43. data/lib/lorj_account.rb +137 -90
  44. data/lib/lorj_config.rb +13 -19
  45. data/lib/lorj_defaults.rb +46 -292
  46. data/lib/lorj_meta.rb +729 -0
  47. data/lib/prc.rb +119 -30
  48. data/lib/prc_base_config.rb +53 -47
  49. data/lib/prc_core_config.rb +837 -565
  50. data/lib/prc_section_config.rb +44 -16
  51. data/lib/providers/hpcloud/hpcloud.rb +1 -1
  52. data/lib/providers/openstack/openstack.rb +278 -21
  53. data/lib/providers/openstack/openstack_create.rb +205 -0
  54. data/lib/providers/openstack/openstack_delete.rb +28 -0
  55. data/lib/providers/openstack/openstack_get.rb +39 -0
  56. data/lib/providers/openstack/openstack_process.rb +26 -0
  57. data/lib/providers/openstack/openstack_query.rb +96 -0
  58. data/lib/providers/openstack/openstack_update.rb +35 -0
  59. data/lib/rh.rb +91 -6
  60. data/lorj-spec/defaults.yaml +18 -12
  61. data/lorj.gemspec +1 -0
  62. data/spec/01_hash_rh_spec.rb +41 -2
  63. data/spec/02_prc_base_config_spec.rb +1 -1
  64. data/spec/03_prc_section_config_spec.rb +1 -1
  65. data/spec/04_prc_core_config_spec.rb +148 -4
  66. data/spec/09_prc_spec.rb +104 -0
  67. data/spec/{00_lorj_log_spec.rb → 10_lorj_log_spec.rb} +23 -2
  68. data/spec/11_lorj_config_spec.rb +9 -27
  69. data/spec/12_lorj_account_spec.rb +36 -20
  70. data/spec/20_lorj_meta_spec.rb +271 -0
  71. data/spec/21_lorj_defaults_spec.rb +85 -0
  72. metadata +31 -4
@@ -0,0 +1,104 @@
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 'byebug'
19
+
20
+ app_path = File.dirname(__FILE__)
21
+ $LOAD_PATH << File.join(app_path, '..', 'lib')
22
+
23
+ describe 'Module PrcLib: ' do
24
+ after(:all) do
25
+ Object.send(:remove_const, :PrcLib)
26
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load prc
27
+ load File.join(app_path, '..', 'lib', 'logging.rb') # Load logging
28
+ end
29
+
30
+ it 'load Lorj and PrcLib Modules' do
31
+ require 'lorj' # Load lorj framework
32
+ expect(Lorj).to be
33
+ expect(PrcLib).to be
34
+ end
35
+
36
+ it 'lib_path is set' do
37
+ file = File.expand_path(File.join(app_path, '..', 'lib'))
38
+ expect(PrcLib.lib_path).to eq(file)
39
+ end
40
+
41
+ it 'default app is lorj and cannot be updated.' do
42
+ expect(PrcLib.app_name).to eq('lorj')
43
+ PrcLib.app_name = 'lorj-spec'
44
+ expect(PrcLib.app_name).to eq('lorj')
45
+ end
46
+
47
+ it 'after load cleanup, set default app to lorj-spec is ok' do
48
+ Object.send(:remove_const, :PrcLib)
49
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load lorj framework
50
+ PrcLib.app_name = 'lorj-spec'
51
+ expect(PrcLib.app_name).to eq('lorj-spec')
52
+ end
53
+
54
+ it 'default pdata_path to ~/.config/lorj, and not updatable' do
55
+ Object.send(:remove_const, :PrcLib)
56
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load lorj framework
57
+ file = File.expand_path(File.join('~', '.config', PrcLib.app_name))
58
+ expect(PrcLib.pdata_path).to eq(file)
59
+ PrcLib.pdata_path = File.join('~', '.test')
60
+ expect(PrcLib.pdata_path).to eq(file)
61
+ end
62
+
63
+ it 'after load cleanup, set default pdata_path to ~/.test is ok.' do
64
+ Object.send(:remove_const, :PrcLib)
65
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load lorj framework
66
+ file = File.expand_path(File.join('~', '.test'))
67
+ PrcLib.pdata_path = file
68
+ expect(PrcLib.pdata_path).to eq(file)
69
+ end
70
+
71
+ it 'default data_path to ~/.config/lorj, and not updatable' do
72
+ Object.send(:remove_const, :PrcLib)
73
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load lorj framework
74
+ file = File.expand_path(File.join('~', '.lorj'))
75
+ expect(PrcLib.data_path).to eq(file)
76
+ PrcLib.data_path = File.join('~', '.test')
77
+ expect(PrcLib.data_path).to eq(file)
78
+ end
79
+
80
+ it 'after load cleanup, set default data_path to ~/.test is ok.' do
81
+ Object.send(:remove_const, :PrcLib)
82
+ load File.join(app_path, '..', 'lib', 'prc.rb') # Load lorj framework
83
+ file = File.expand_path(File.join('~', '.test'))
84
+ PrcLib.data_path = file
85
+ expect(PrcLib.data_path).to eq(file)
86
+ end
87
+
88
+ it 'model is initialized automatically.' do
89
+ expect(PrcLib.model).to be
90
+ expect(PrcLib.model.class).to be(Lorj::Model)
91
+ end
92
+
93
+ it 'app_defaults is nil (no defaults)' do
94
+ expect(PrcLib.app_defaults).to equal(nil)
95
+ end
96
+
97
+ it 'app_defaults is set and not updatable' do
98
+ file = File.expand_path(File.join('~', 'src', 'lorj'))
99
+ PrcLib.app_defaults = file
100
+ expect(PrcLib.app_defaults).to eq(file)
101
+ PrcLib.app_defaults = File.expand_path(File.join('~', '.test'))
102
+ expect(PrcLib.app_defaults).to eq(file)
103
+ end
104
+ end
@@ -21,7 +21,7 @@
21
21
 
22
22
  app_path = File.dirname(File.dirname(__FILE__))
23
23
 
24
- $LOAD_PATH << './lib'
24
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
25
25
 
26
26
  # This spec HAVE to the the first one executed!
27
27
  # Do never create a file or rename this file, which will
@@ -32,6 +32,16 @@ $LOAD_PATH << './lib'
32
32
 
33
33
  describe 'Module: Lorj,' do
34
34
  context 'Initializing' do
35
+ before(:all) do
36
+ rel_name = format('lorj-%d', Process.pid)
37
+ @rel_path = File.join('/tmp', rel_name) if File.exist?('/tmp')
38
+ @rel_path = File.expand_path(File.join('~', rel_name)) if @rel_path.nil?
39
+ end
40
+
41
+ after(:all) do
42
+ FileUtils.rm_rf(@rel_path)
43
+ end
44
+
35
45
  it 'PrcLib module exist' do
36
46
  require 'lorj' # Load lorj framework
37
47
  expect(PrcLib.class).to equal(Module)
@@ -39,8 +49,19 @@ describe 'Module: Lorj,' do
39
49
  expect(PrcLib.log).to be_nil
40
50
  end
41
51
 
52
+ it 'log_file = [...]/lorj-rspec.log creates the path' do
53
+ log = File.join(@rel_path, 'lorj-rspec.log')
54
+ PrcLib.log_file = log
55
+ expect(File.exist?(@rel_path))
56
+ end
57
+
58
+ it 'log_file should get absolute path to the file' do
59
+ log = File.join(@rel_path, 'lorj-rspec.log')
60
+ log = File.expand_path(log)
61
+ expect(PrcLib.log_file).to eq(log)
62
+ end
63
+
42
64
  it 'create PrcLib.log object at first message' do
43
- PrcLib.log_file = 'lorj-rspec.log'
44
65
  PrcLib.level = Logger::FATAL
45
66
  PrcLib.app_name = 'lorj-spec'
46
67
  PrcLib.app_defaults = File.join(app_path, 'lorj-spec')
@@ -15,16 +15,22 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
+ # require 'byebug'
19
+
18
20
  app_path = File.dirname(__FILE__)
19
21
 
20
- $LOAD_PATH << File.join('..', 'lib')
22
+ $LOAD_PATH << File.join(app_path, '..', 'lib')
21
23
 
22
24
  require 'lorj' # Load lorj framework
23
25
 
24
26
  describe 'class: Lorj::Config,' do
25
27
  context 'new instance, with no default local config files, ' do
26
28
  before(:all) do
27
- PrcLib.log_file = 'lorj-rspec.log'
29
+ log_file = File.expand_path(File.join('~', 'lorj-rspec.log'))
30
+ File.delete(log_file) if File.exist?(log_file)
31
+
32
+ PrcLib.log = nil
33
+ PrcLib.log_file = log_file
28
34
  PrcLib.level = Logger::FATAL
29
35
  PrcLib.app_name = 'lorj-spec'
30
36
  PrcLib.app_defaults = File.expand_path(File.join(app_path, '..',
@@ -67,7 +73,7 @@ describe 'class: Lorj::Config,' do
67
73
  end
68
74
 
69
75
  it 'config.layers returns all config names.' do
70
- expect(@config.layers).to eq(%w(runtime local default))
76
+ expect(@config.layers).to eq(%w(runtime local controller default))
71
77
  end
72
78
 
73
79
  it 'config.where?(:test1) return false' do
@@ -235,29 +241,5 @@ describe 'class: Lorj::Config,' do
235
241
  expect(@config.runtime_exist?(:test1)).to equal(true)
236
242
  end
237
243
  end
238
- context 'app default functions' do
239
- before(:all) do
240
- default_file = @config.config_filename('default')
241
- @default = YAML.load_file(default_file)
242
- end
243
- it 'config.app_default(:default) returns :default of defaults.yaml' do
244
- expect(@config.app_default(:default)).to eq(@default[:default])
245
- end
246
-
247
- it 'config.app_default(:sections) returns :section of defaults.yaml' do
248
- expect(@config.app_default(:sections)).to eq(@default[:sections])
249
- end
250
- it 'config.meta_each provides the wanted list of section/key/values' do
251
- # The defaults.yaml MUST have data exclusive set to true
252
- expect(@default.rh_get(:sections, :credentials, :data,
253
- :account_exclusive)).to equal(true)
254
- @config.meta_each do |section, key, value|
255
- expect(@default.rh_exist?(:sections, section, key)).to equal(true)
256
- expect(@default.rh_get(:sections, section, key)).to equal(value)
257
- expect([section, key,
258
- value]).not_to eq([:sections, :credentials, :data])
259
- end
260
- end
261
- end
262
244
  end
263
245
  end
@@ -15,13 +15,11 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- # require 'rubygems'
19
- # require 'byebug'
20
- # require 'bundler/setup'
18
+ # require 'byebug'
21
19
 
22
- app_path = File.dirname(File.dirname(__FILE__))
20
+ app_path = File.dirname(__FILE__)
23
21
 
24
- $LOAD_PATH << '../lib'
22
+ $LOAD_PATH << File.join(app_path, '..', 'lib')
25
23
 
26
24
  require 'lorj' # Load lorj framework
27
25
 
@@ -31,7 +29,7 @@ describe 'class: Lorj::Account,' do
31
29
  PrcLib.log_file = 'lorj-rspec.log'
32
30
  PrcLib.level = Logger::FATAL
33
31
  PrcLib.app_name = 'lorj-spec'
34
- PrcLib.app_defaults = File.join(app_path, 'lorj-spec')
32
+ PrcLib.app_defaults = File.join(app_path, '..', 'lorj-spec')
35
33
 
36
34
  account = Lorj::Account.new
37
35
  expect(account).to be
@@ -39,7 +37,7 @@ describe 'class: Lorj::Account,' do
39
37
 
40
38
  it 'account.layers is compliant' do
41
39
  account = Lorj::Account.new
42
- expect(account.layers).to eq(%w(runtime account local default))
40
+ expect(account.layers).to eq(%w(runtime account local controller default))
43
41
  end
44
42
  end
45
43
 
@@ -55,7 +53,8 @@ describe 'class: Lorj::Account,' do
55
53
  File.open(File.join(PrcLib.data_path, 'accounts', 'test1'),
56
54
  'w+') do |file|
57
55
  file.write(":credentials:\n :keypair_name: nova_test1\n "\
58
- ":tenant_name: test\n :data: ac_data")
56
+ ":tenant_name: test\n :data: ac_data\n:account:\n "\
57
+ ":name: test1\n :provider: myprovider\n")
59
58
  end
60
59
 
61
60
  @account = Lorj::Account.new
@@ -178,23 +177,12 @@ describe 'class: Lorj::Account,' do
178
177
  :name => 'account')).to eq('nova_test2')
179
178
  end
180
179
 
181
- it 'account.ac_save return false - '\
182
- 'file has no valid provider name' do
183
- expect(@account.ac_save).to equal(false)
184
- end
185
-
186
- it 'set provider name' do
187
- expect(@account.set(:provider, 'myprovider',
188
- :name => 'account',
189
- :section => :account)).to eq('myprovider')
190
- end
191
-
192
180
  it 'account.ac_save return true' do
193
181
  expect(@account.ac_save).to equal(true)
194
182
  end
195
183
 
196
184
  it 'account.ac_new return true, and :data disappeared.' do
197
- expect(@account.ac_new 'test1').to equal(true)
185
+ expect(@account.ac_new 'test1', 'provider').to equal(true)
198
186
  expect(@account.where?(:data)).to eq(%w(runtime))
199
187
  end
200
188
 
@@ -209,4 +197,32 @@ describe 'class: Lorj::Account,' do
209
197
  :name => 'account')).to eq('nova_test2')
210
198
  end
211
199
  end
200
+
201
+ context "Key | runtime | accounts | local | default)\n"\
202
+ " :keypair | nil | nil | nova_local| default_key\n"\
203
+ " :data | nil | nil | no effect | None\n"\
204
+ " :data is account exclusive\n => accounts/test1 not set:" do
205
+ before(:all) do
206
+ File.open(File.join(PrcLib.data_path, 'config.yaml'),
207
+ 'w+') do |file|
208
+ file.write(":default:\n :keypair_name: nova_local\n :data: no effect")
209
+ end
210
+ File.open(File.join(PrcLib.data_path, 'accounts', 'test1'),
211
+ 'w+') do |file|
212
+ file.write(":credentials:\n :keypair_name: nova_test1\n "\
213
+ ":tenant_name: test\n :data: ac_data\n")
214
+ end
215
+
216
+ @account = Lorj::Account.new
217
+ end
218
+
219
+ it 'account.load return true' do
220
+ expect(@account.ac_load 'test1').to equal(true)
221
+ expect(@account.where?(:data)).to eq(%w(account))
222
+ end
223
+
224
+ it 'account.ac_save return false - provider not set.' do
225
+ expect(@account.ac_save).to equal(false)
226
+ end
227
+ end
212
228
  end
@@ -0,0 +1,271 @@
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__)
23
+
24
+ $LOAD_PATH << File.join(app_path, '..', 'lib')
25
+
26
+ require 'lorj' # Load lorj framework
27
+
28
+ describe 'Lorj::MetaAppConfig,' do
29
+ context 'core with sample initialized,' do
30
+ before(:all) do
31
+ data = <<YAMLDOC
32
+ ---
33
+ :setup:
34
+ :ask_step:
35
+ - :desc: 'Small description'
36
+ :explanation: |-
37
+ My complete explanation is in
38
+ multiple lines <%= config['text'] %>
39
+ :add:
40
+ - :key_pair_files
41
+ - :ssh_user
42
+ :sections:
43
+ :section1:
44
+ :data1:
45
+ :option1: value1
46
+ :data2:
47
+ :option1: value2
48
+ :section2:
49
+ :data2:
50
+ :option2: value3
51
+ :section3:
52
+ :data3:
53
+ :option3: value4
54
+ YAMLDOC
55
+ # MetaAppConfig spec class.
56
+ class MetaAppConfigSpec < Lorj::MetaAppConfig
57
+ def get(options)
58
+ p_get(options)
59
+ end
60
+ end
61
+
62
+ @metadata = MetaAppConfigSpec.new YAML.load(data)
63
+ end
64
+
65
+ it 'sections returns [:section1, :section2].' do
66
+ expect(@metadata.sections).to eq([:section1, :section2, :section3])
67
+ end
68
+
69
+ it 'sections(:data1) returns [:section1].' do
70
+ expect(@metadata.sections(:data1)).to eq([:section1])
71
+ end
72
+
73
+ it 'sections(:data2) returns [:section1, :section2].' do
74
+ expect(@metadata.sections(:data2)).to eq([:section1, :section2])
75
+ end
76
+
77
+ it 'datas returns [:data1, :data2].' do
78
+ expect(@metadata.datas).to eq([:data1, :data2, :data3])
79
+ end
80
+
81
+ it 'first_section(:data2) returns :section1' do
82
+ expect(@metadata.first_section(:data2)).to equal(:section1)
83
+ end
84
+
85
+ it 'first_section(:data1) returns :section1' do
86
+ expect(@metadata.first_section(:data1)).to equal(:section1)
87
+ end
88
+
89
+ it 'first_section(:data3) returns :section3' do
90
+ expect(@metadata.first_section(:data3)).to equal(:section3)
91
+ end
92
+
93
+ it 'meta_exist?(:section1, :data1) returns true' do
94
+ expect(@metadata.meta_exist?(:section1, :data1)).to equal(true)
95
+ end
96
+
97
+ it 'meta_exist?(:section2, :data1) returns false' do
98
+ expect(@metadata.meta_exist?(:section2, :data1)).to equal(false)
99
+ end
100
+
101
+ it 'meta_exist?(:section2, :data2) returns true' do
102
+ expect(@metadata.meta_exist?(:section2, :data2)).to equal(true)
103
+ end
104
+
105
+ it 'auto_meta_exist?(:data2) returns true' do
106
+ expect(@metadata.auto_meta_exist?(:data2)).to equal(true)
107
+ end
108
+
109
+ it 'auto_meta_exist?(:data3) returns true' do
110
+ expect(@metadata.auto_meta_exist?(:data3)).to equal(true)
111
+ end
112
+
113
+ it 'auto_meta_exist?(:data4) returns false' do
114
+ expect(@metadata.auto_meta_exist?(:data4)).to equal(false)
115
+ end
116
+
117
+ it 'meta_each provides list of section/key/values' do
118
+ @metadata.meta_each do |section, key, _values|
119
+ expect(@metadata.sections.include?(section))
120
+ expect(@metadata.datas.include?(key))
121
+ end
122
+ end
123
+ it 'parent data[:sections, :section5, :data5] returns nil' do
124
+ expect(@metadata[:sections, :section5, :data5]).to equal(nil)
125
+ end
126
+
127
+ it 'data[:sections, :section5, :data5] = {:option5 => value5}' do
128
+ @metadata[:sections, :section5, :data5] = { :option5 => :value5 }
129
+ expect(@metadata[:sections, :section5, :data5]).to eq(:option5 => :value5)
130
+ option = {}
131
+ option[:keys] = [:sections, :section5, :data5, :option5]
132
+ option[:name] = 'app'
133
+ expect(@metadata.get(option)).to equal(nil)
134
+ option[:name] = 'map'
135
+ expect(@metadata.get(option)).to equal(nil)
136
+
137
+ # section mapping should be updated.
138
+ expect(@metadata.sections(:data5)).to eq([:section5])
139
+ end
140
+
141
+ # To simplify spec code, app layer contains String values for each options
142
+ # while controller options values are Symbol.
143
+ # This helps to identify if the merge feature result.
144
+ it 'define_controller_data(:section2, :data2, :option2 => :value4) works' do
145
+ data = { :option2 => :value4 }
146
+ expect(@metadata[:sections, :section2, :data2, :option2]).to eq('value3')
147
+ expect(@metadata.define_controller_data(:section2,
148
+ :data2, data)).to eq(data)
149
+ expect(@metadata.sections(:data2)).to eq([:section1, :section2])
150
+ expect(@metadata[:sections, :section2, :data2, :option2]).to eq(:value4)
151
+ end
152
+
153
+ it 'update_controller_data(:section2, :data2, :option3 => value1) works' do
154
+ data = { :option3 => :value1 }
155
+ result = data.clone
156
+ result[:option2] = :value4
157
+ expect(@metadata.update_controller_data(:section2,
158
+ :data2, data)).to eq(result)
159
+ expect(@metadata[:sections, :section2, :data2, :option2]).to eq(:value4)
160
+ expect(@metadata[:sections, :section2, :data2, :option3]).to eq(:value1)
161
+ end
162
+
163
+ it 'section_data(:section1, :data1) returns {:option1 => "value1"}' do
164
+ expect(@metadata.section_data(:section1, :data1
165
+ )).to eq(:option1 => 'value1')
166
+ end
167
+
168
+ it 'section_data(:section1, :data1, :option1) returns "value1"' do
169
+ expect(@metadata.section_data(:section1, :data1,
170
+ :option1)).to eq('value1')
171
+ end
172
+
173
+ it 'section_data(:section2, :data2) returns Merged hash' do
174
+ expect(@metadata.section_data(:section2, :data2
175
+ )).to eq(:option2 => :value4,
176
+ :option3 => :value1)
177
+ # Expect no change (internal reverse is not impacting)
178
+ expect(@metadata.section_data(:section2, :data2
179
+ )).to eq(:option2 => :value4,
180
+ :option3 => :value1)
181
+ # 'App' option value already exists and has not been updated.
182
+ option = {}
183
+ option[:keys] = [:sections, :section2, :data2, :option2]
184
+ option[:name] = 'app'
185
+ expect(@metadata.get(option)).to eq('value3')
186
+ end
187
+
188
+ it 'With :section3 => :data3 => :option1 => :value1,'\
189
+ ' section_data(:section3, :data3) returns {:option1=>:value1,'\
190
+ ':option3=> "value4"}' do
191
+ @metadata.define_controller_data(:section3,
192
+ :data3, :option1 => :value1)
193
+ expect(@metadata.section_data(:section3, :data3
194
+ )).to eq(:option1 => :value1,
195
+ :option3 => 'value4')
196
+ end
197
+
198
+ it 'auto_section_data(:data3) returns {:option1=>:value1,'\
199
+ ':option3=> "value4"}' do
200
+ expect(@metadata.auto_section_data(:data3)).to eq(:option1 => :value1,
201
+ :option3 => 'value4')
202
+ end
203
+
204
+ it 'set(:sections, :section6, :data6, {:option6 => :value6}) returns '\
205
+ ':option6 => :value6' do
206
+ expect(@metadata.set(:sections, :section6, :data6,
207
+ :option6 => :value6)).to eq(:option6 => :value6)
208
+
209
+ option = {}
210
+ option[:keys] = [:sections, :section6, :data6, :option6]
211
+ option[:name] = 'app'
212
+ expect(@metadata.get(option)).to equal(nil)
213
+ option[:name] = 'map'
214
+ expect(@metadata.get(option)).to equal(nil)
215
+ option[:name] = 'controller'
216
+ expect(@metadata.get(option)).to eq(:value6)
217
+ expect(@metadata.sections(:data6)).to eq([:section6])
218
+ end
219
+
220
+ it 'set(:sections, :section6, :data6, {:option6 => :value7}, "app") '\
221
+ 'returns :option6 => :value7. but controller is only updated.' do
222
+ expect(@metadata.set(:sections, :section6, :data6,
223
+ { :option6 => :value7 },
224
+ 'app')).to eq(:option6 => :value7)
225
+
226
+ option = {}
227
+ option[:keys] = [:sections, :section6, :data6, :option6]
228
+ option[:name] = 'app'
229
+ expect(@metadata.get(option)).to equal(nil)
230
+ option[:name] = 'map'
231
+ expect(@metadata.get(option)).to equal(nil)
232
+ option[:name] = 'controller'
233
+ expect(@metadata.get(option)).to eq(:value7)
234
+ end
235
+
236
+ it 'set(:any, :kind_of, :data1, {:option1 => :value1}) '\
237
+ 'returns :option1 => :value1' do
238
+ expect(@metadata.where?(:any, :kind_of, :data1, :option1)).to equal(false)
239
+ expect(@metadata.set(:any, :kind_of, :data1, :option1 => :value1
240
+ )).to eq(:option1 => :value1)
241
+ expect(@metadata.where?(:any, :kind_of, :data1,
242
+ :option1)).to eq(['controller'])
243
+ end
244
+
245
+ it 'del(:any, :kind_of, :data1) returns :option1 => :value1 and '\
246
+ 'is deleted' do
247
+ expect(@metadata.del(:any, :kind_of, :data1)).to eq(:option1 => :value1)
248
+
249
+ expect(@metadata.where?(:any, :kind_of, :data1, :option1)).to equal(false)
250
+ end
251
+
252
+ it 'setup_options(:ask_step) returns a merged data' do
253
+ expect(@metadata.setup_options(:ask_step).class).to equal(Array)
254
+ expect(@metadata.setup_options(:ask_step).length).to equal(1)
255
+ end
256
+
257
+ it 'setup_data(:ask_step) returns a merged data' do
258
+ data = @metadata.setup_data(:ask_step)
259
+ expect(data.class).to equal(Array)
260
+ expect(data.length).to equal(1)
261
+ end
262
+ end
263
+
264
+ context 'from Lorj.data,' do
265
+ it 'gets loaded.' do
266
+ PrcLib.level = Logger::FATAL
267
+ expect(Lorj.data).to be
268
+ expect(Lorj.data.class).to equal(Lorj::MetaAppConfig)
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,85 @@
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__)
23
+
24
+ $LOAD_PATH << File.join(app_path, '..', 'lib')
25
+
26
+ require 'lorj' # Load lorj framework
27
+
28
+ describe 'class: Lorj::Default loaded lorj_spec/defaults.yaml, '\
29
+ 'no controller data,' do
30
+ context 'from PrcLib module,' do
31
+ before(:all) do
32
+ log_file = File.expand_path(File.join('~', 'lorj-rspec.log'))
33
+ File.delete(log_file) if File.exist?(log_file)
34
+
35
+ PrcLib.log_file = log_file
36
+ PrcLib.level = Logger::FATAL
37
+ PrcLib.app_name = 'lorj-spec'
38
+ PrcLib.app_defaults = File.expand_path(File.join(app_path, '..',
39
+ 'lorj-spec'))
40
+ end
41
+
42
+ it 'PrcLib.defaults returns a Lorj::Defaults instance.' do
43
+ expect(Lorj.defaults).to be
44
+ expect(Lorj.defaults.class).to equal(Lorj::Defaults)
45
+ end
46
+ end
47
+
48
+ context 'Default instance' do
49
+ before(:all) do
50
+ @defaults = Lorj.defaults
51
+ end
52
+
53
+ context 'Features to be removed at version 2.0,' do
54
+ # TODO: Feature to be removed at version 2.0.
55
+ it 'meta_each provides list of section/key/values' do
56
+ @defaults.meta_each do |section, key, values|
57
+ expect([:credentials, :maestro].include?(section))
58
+ expect([:keypair_name, :data, :maestro_url].include?(key))
59
+ expect([nil, { :account_exclusive => true }].include?(values))
60
+ end
61
+ end
62
+
63
+ it 'meta_exist?(:data) return true' do
64
+ expect(@defaults.meta_exist?(:data)).to equal(true)
65
+ end
66
+
67
+ it 'meta_exist?(:test1) return false' do
68
+ expect(@defaults.meta_exist?(:test1)).to equal(false)
69
+ end
70
+
71
+ it 'get_meta_auto(:data) return {:account_exclusive => true}' do
72
+ expect(@defaults.get_meta_auto(:data)).to eq(:account_exclusive => true)
73
+ end
74
+
75
+ it 'get_meta(:credentials, :data) return {:account_exclusive => true}' do
76
+ expect(@defaults.get_meta(:credentials,
77
+ :data)).to eq(:account_exclusive => true)
78
+ end
79
+
80
+ it 'get_meta_section(:data) return :credentials' do
81
+ expect(@defaults.get_meta_section(:data)).to eq(:credentials)
82
+ end
83
+ end
84
+ end
85
+ end