lorj 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/providers/mock/Mock.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
# This class describes how to process some actions, and will do everything prior
|
19
|
-
# this task to make it to work.
|
20
|
-
|
21
|
-
# This Mock controller keep the data in memory in hash/Array data.
|
22
|
-
|
23
|
-
class Mock
|
24
|
-
# mock do not need to use any mapping. It adapts itself to what the process has defined.
|
25
|
-
end
|
26
|
-
|
27
|
-
class MockController
|
28
|
-
|
29
|
-
@@data = {}
|
30
|
-
|
31
|
-
def create(sObjectType, hParams)
|
32
|
-
PrcLib::debug("Mock: create object '%s' with parameters (hdata) '%s'" % [sObjectType, hParams[:hdata]])
|
33
|
-
|
34
|
-
result = {}
|
35
|
-
hParams[].keys.each { |key|
|
36
|
-
next if key == :hdata
|
37
|
-
result[key] = hParams[key]
|
38
|
-
}
|
39
|
-
result.merge!(hParams[:hdata])
|
40
|
-
|
41
|
-
unless @@data.key?(sObjectType)
|
42
|
-
@@data[sObjectType] = []
|
43
|
-
end
|
44
|
-
aArr = @@data[sObjectType]
|
45
|
-
|
46
|
-
aArr.each { | value |
|
47
|
-
raise if value.key?(result[:name])
|
48
|
-
}
|
49
|
-
aArr << result
|
50
|
-
|
51
|
-
result[:id] = aArr.length()-1
|
52
|
-
|
53
|
-
# Typical code:
|
54
|
-
#~ case sObjectType
|
55
|
-
#~ when :public_ip
|
56
|
-
# Following function can be executed to ensure the object :connection exists.
|
57
|
-
#~ required?(hParams, :connection)
|
58
|
-
#~ required?(hParams, :server)
|
59
|
-
#~ ... CODE to create
|
60
|
-
#~ else
|
61
|
-
#~ Error "'%s' is not a valid object for 'create'" % sObjectType
|
62
|
-
#~ end
|
63
|
-
# The code should return some data
|
64
|
-
# This data will be encapsulated in Lorj::Data object.
|
65
|
-
# data will be extracted by the framework with the controller get_attr function and mapped.
|
66
|
-
PrcLib::debug("Mock: object '%s' = '%s' is created." % [sObjectType, result])
|
67
|
-
result
|
68
|
-
end
|
69
|
-
|
70
|
-
# This function return a collection which have to provide:
|
71
|
-
# functions: [], length, each
|
72
|
-
# Used by network process.
|
73
|
-
def query(sObjectType, sQuery, hParams)
|
74
|
-
PrcLib::debug("Mock: query object '%s' with hdata '%s' using query '%s'" % [sObjectType, hParams[:hdata], sQuery])
|
75
|
-
|
76
|
-
return [] unless @@data.key?(sObjectType)
|
77
|
-
|
78
|
-
result = []
|
79
|
-
|
80
|
-
@@data[sObjectType].each { | value |
|
81
|
-
hElem = value
|
82
|
-
sQuery.each { | query_key, query_value |
|
83
|
-
hElem = nil if not value.key?(query_key) or value[query_key] != query_value
|
84
|
-
}
|
85
|
-
result << hElem if hElem
|
86
|
-
}
|
87
|
-
result
|
88
|
-
end
|
89
|
-
|
90
|
-
def delete(sObjectType, hParams)
|
91
|
-
PrcLib::debug("Mock: delete object '%s' with hdata '%s'" % [sObjectType, hParams[:hdata]])
|
92
|
-
return nil unless @@data.key?(sObjectType)
|
93
|
-
|
94
|
-
return false if not hParams.exist?(sObjectType) or hParams[sObjectType].nil?
|
95
|
-
@@data[sObjectType].delete(hParams[sObjectType])
|
96
|
-
PrcLib::debug("Mock: object '%s' = '%s' is deleted." % [sObjectType, hParams[sObjectType]])
|
97
|
-
true
|
98
|
-
end
|
99
|
-
|
100
|
-
def get(sObjectType, sUniqId, hParams)
|
101
|
-
PrcLib::debug("Mock: Get object '%s' = '%s' with hdata '%s'" % [sObjectType, sUniqId, hParams[:hdata]])
|
102
|
-
return nil unless @@data.key?(sObjectType)
|
103
|
-
@@data[sObjectType][sUniqId]
|
104
|
-
end
|
105
|
-
|
106
|
-
def get_attr(oControlerObject, key)
|
107
|
-
# This controller function read the data and
|
108
|
-
# extract the information requested by the framework.
|
109
|
-
# Those data will be mapped to the process data model.
|
110
|
-
# The key is an array, to get data from a level tree.
|
111
|
-
# [data_l1, data_l2, data_l3] => should retrieve data from structure like data[ data_l2[ data_l3 ] ]
|
112
|
-
begin
|
113
|
-
attributes = oControlerObject
|
114
|
-
# raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.keys ] unless oControlerObject.include?(key[0])
|
115
|
-
Lorj::rhGet(attributes, key)
|
116
|
-
rescue => e
|
117
|
-
Error "Unable to map '%s'. %s" % [key, e.message]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def set_attr(oControlerObject, key, value)
|
122
|
-
begin
|
123
|
-
attributes = oControlerObject
|
124
|
-
# raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.keys ] unless oControlerObject.include?(key[0])
|
125
|
-
Lorj::rhSet(attributes, value, key)
|
126
|
-
rescue => e
|
127
|
-
Error "Unable to map '%s' on '%s'" % [key, sObjectType]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
def update(sObjectType, oObject, hParams)
|
133
|
-
PrcLib::debug("Mock: Update object '%s' = '%s' with hdata '%s'" % [sObjectType, sUniqId, hParams[:hdata]])
|
134
|
-
return false unless @@data.key?(sObjectType)
|
135
|
-
|
136
|
-
return false unless @@data[sObjectType][oObject[:id]].nil?
|
137
|
-
# Considered hash object is already updated.
|
138
|
-
# This action emule the object save which doesn't make sense in this empty Mock controller.
|
139
|
-
true
|
140
|
-
end
|
141
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
# This class describes how to process some actions, and will do everything prior
|
19
|
-
# this task to make it to work.
|
20
|
-
|
21
|
-
|
22
|
-
class Openstack < BaseDefinition
|
23
|
-
def initialize()
|
24
|
-
superclass.provides([:compute, :network])
|
25
|
-
end
|
26
|
-
|
27
|
-
def compute()
|
28
|
-
Fog::Compute.new({
|
29
|
-
:provider => :openstack,
|
30
|
-
:openstack_api_key => superclass.oForjAccount.get(:account_id),
|
31
|
-
:openstack_username => superclass.oForjAccount.get(:account_key),
|
32
|
-
:openstack_auth_url => superclass.oForjAccount.get(:auth_uri),
|
33
|
-
:openstack_tenant => superclass.oForjAccount.get(:tenant_id),
|
34
|
-
:openstack_region => superclass.oForjAccount.get(:compute)
|
35
|
-
})
|
36
|
-
end
|
37
|
-
def network()
|
38
|
-
Fog::Network.new({
|
39
|
-
:provider => :openstack,
|
40
|
-
:openstack_api_key => superclass.oForjAccount.get(:account_id),
|
41
|
-
:openstack_username => superclass.oForjAccount.get(:account_key),
|
42
|
-
:openstack_auth_url => superclass.oForjAccount.get(:auth_uri),
|
43
|
-
:openstack_tenant => superclass.oForjAccount.get(:tenant_id),
|
44
|
-
:openstack_region => superclass.oForjAccount.get(:network)
|
45
|
-
})
|
46
|
-
end
|
47
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
# This file is given as an example.
|
19
|
-
|
20
|
-
require File.join($PROVIDER_PATH, "compute.rb")
|
21
|
-
require File.join($PROVIDER_PATH, "network.rb")
|
22
|
-
|
23
|
-
# Defines Meta MyCloud object
|
24
|
-
class Mycloud
|
25
|
-
|
26
|
-
# Defines Object structure and function stored on the Hpcloud class object.
|
27
|
-
|
28
|
-
# ForjCloud has a list of predefined object, like compute_connection, network, ...
|
29
|
-
# See lib/providers/core/cloud_data_pref.rb
|
30
|
-
|
31
|
-
# Compute Object
|
32
|
-
define_obj :compute_connection
|
33
|
-
# Defines Data used by compute.
|
34
|
-
obj_needs(:data, :account_id, { :mapping => :user})
|
35
|
-
obj_needs(:data, :account_key, { :mapping => :pwd})
|
36
|
-
obj_needs(:data, :auth_uri, { :mapping => :auth_uri})
|
37
|
-
obj_needs(:data, :tenant, { :mapping => :project})
|
38
|
-
obj_needs(:data, :compute, { :mapping => :compute_service})
|
39
|
-
|
40
|
-
define_obj :network_connection
|
41
|
-
obj_needs(:data, :account_id, { :mapping => :user})
|
42
|
-
obj_needs(:data, :account_key, { :mapping => :pwd})
|
43
|
-
obj_needs(:data, :auth_uri, { :mapping => :auth_uri})
|
44
|
-
obj_needs(:data, :tenant, { :mapping => :project})
|
45
|
-
obj_needs(:data, :network, { :mapping => :network_service})
|
46
|
-
|
47
|
-
define_obj :network
|
48
|
-
obj_needs(:CloudObject, :network_connection)
|
49
|
-
obj_needs(:data, :network_name)
|
50
|
-
|
51
|
-
# defines setup Cloud data
|
52
|
-
# This definition is required only if you need to change the predefined data.
|
53
|
-
# To get details on what kind of parameters can be applied to a CloudData, see lib/defaults.yaml
|
54
|
-
define_data(:account_id, {:provisioned_by => :setup, :desc => 'MyCloud username'})
|
55
|
-
define_data(:account_key, {:provisioned_by => :setup, :desc => 'HPCloud secret Key'})
|
56
|
-
define_data(:auth_uri, {:provisioned_by => :setup, :desc => 'HPCloud Authentication service URL'})
|
57
|
-
define_data(:tenant, {:provisioned_by => :setup, :desc => 'HPCloud Tenant ID'})
|
58
|
-
define_data(:compute, {:provisioned_by => :setup, :desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)'})
|
59
|
-
define_data(:network, {:provisioned_by => :setup, :desc => 'HPCloud Network service zone (Ex: region-a.geo-1)'})
|
60
|
-
|
61
|
-
end
|
data/spec/forj-account_spec.rb
DELETED
@@ -1,75 +0,0 @@
|
|
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 'bundler/setup'
|
20
|
-
|
21
|
-
$APP_PATH = File.dirname(__FILE__)
|
22
|
-
$LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
|
23
|
-
|
24
|
-
$LOAD_PATH << $LIB_PATH
|
25
|
-
|
26
|
-
require 'lorj' # Load lorj framework
|
27
|
-
|
28
|
-
PrcLib.log_file = 'lorj-rspec.log'
|
29
|
-
PrcLib.level = Logger::FATAL
|
30
|
-
PrcLib.app_name = 'lorj-spec'
|
31
|
-
PrcLib.app_defaults = 'lorj-spec'
|
32
|
-
|
33
|
-
describe "class: Lorj::Account," do
|
34
|
-
context "when creating a new instance," do
|
35
|
-
|
36
|
-
it 'should be loaded' do
|
37
|
-
oForjAccount = Lorj::Account.new()
|
38
|
-
expect(oForjAccount).to be
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should store log data in lorj-rspec.log' do
|
42
|
-
expect(PrcLib.log_file).to eq(File.expand_path('lorj-rspec.log'))
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when starting," do
|
48
|
-
before(:all) do
|
49
|
-
File.open(File.join(PrcLib.data_path, 'config.yaml'), 'w+') { |file| file.write("default:\n keypair_name: nova_local\n") }
|
50
|
-
File.open(File.join(PrcLib.data_path, 'accounts', 'test1'), 'w+') { |file| file.write("credentials:\n keypair_name: nova_test1\n :tenant_name: test\n") }
|
51
|
-
|
52
|
-
config = Lorj::Config.new()
|
53
|
-
config[:account_name] = 'test1'
|
54
|
-
@ForjAccount = Lorj::Account.new(config)
|
55
|
-
@ForjAccount.ac_load()
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should be able to read account data' do
|
59
|
-
expect(@ForjAccount[:keypair_name]).to eq('nova_test1')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should be able to create a key/value in the account config' do
|
63
|
-
@ForjAccount.set(:test1, 'value')
|
64
|
-
expect(@ForjAccount.get(:test1)).to eq('value')
|
65
|
-
@ForjAccount.set(:keypair_name, 'value')
|
66
|
-
expect(@ForjAccount.get(:keypair_name)).to eq('value')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should be able to delete a key/value in the account config and get default back.' do
|
70
|
-
@ForjAccount.del(:keypair_name)
|
71
|
-
expect(@ForjAccount.get(:keypair_name)).to eq('nova_local')
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
data/spec/forj-config_spec.rb
DELETED
@@ -1,196 +0,0 @@
|
|
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
|
-
|
19
|
-
$APP_PATH = File.dirname(__FILE__)
|
20
|
-
$LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
|
21
|
-
|
22
|
-
$LOAD_PATH << './lib'
|
23
|
-
|
24
|
-
require 'lorj' # Load lorj framework
|
25
|
-
|
26
|
-
PrcLib.log_file = 'lorj-rspec.log'
|
27
|
-
PrcLib.level = Logger::FATAL
|
28
|
-
PrcLib.app_name = 'lorj-spec'
|
29
|
-
PrcLib.app_defaults = 'lorj-spec'
|
30
|
-
|
31
|
-
|
32
|
-
describe "class: Lorj::Config," do
|
33
|
-
context "when creating a new instance" do
|
34
|
-
|
35
|
-
it 'should be loaded' do
|
36
|
-
@test_config = Lorj::Config.new()
|
37
|
-
expect(@test_config).to be
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when starting, Lorj::Config" do
|
43
|
-
before(:all) do
|
44
|
-
@config = Lorj::Config.new()
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should be able to create a key/value in local config' do
|
48
|
-
@config.localSet(:test1,'value')
|
49
|
-
expect(@config.localGet(:test1)).to eq('value')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should be able to remove the previously created key/value from local config' do
|
53
|
-
@config.localDel(:test1)
|
54
|
-
expect(@config.exist?(:test1)).to equal(false)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "while updating local config file, forj-config" do
|
59
|
-
before(:all) do
|
60
|
-
@config = Lorj::Config.new()
|
61
|
-
end
|
62
|
-
|
63
|
-
after(:all) do
|
64
|
-
@config.localDel(:test1)
|
65
|
-
@config.saveConfig()
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should save a key/value in local config' do
|
69
|
-
@config.localSet(:test1,'value')
|
70
|
-
expect(@config.saveConfig()).to equal(true)
|
71
|
-
|
72
|
-
oConfig = Lorj::Config.new()
|
73
|
-
expect(@config.localGet(:test1)).to eq('value')
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
context "With another config file - test1.yaml, forj-config" do
|
79
|
-
|
80
|
-
before(:all) do
|
81
|
-
if File.exists?(File.join(PrcLib.data_path, 'test.yaml'))
|
82
|
-
File.delete(File.join(PrcLib.data_path, 'test.yaml'))
|
83
|
-
end
|
84
|
-
File.open(File.join(PrcLib.data_path, 'test1.yaml'), 'w+') { |file| file.write(":default:\n") }
|
85
|
-
@config = Lorj::Config.new('test.yaml')
|
86
|
-
@config2 = Lorj::Config.new('test1.yaml')
|
87
|
-
end
|
88
|
-
|
89
|
-
after(:all) do
|
90
|
-
File.delete(File.join(PrcLib.data_path, 'test1.yaml'))
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'won\'t create a new file If we request to load \'test.yaml\'' do
|
94
|
-
expect(File.exists?(File.join(PrcLib.data_path, 'test.yaml'))).to equal(false)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'will load the default config file if we request to load \'test.yaml\'' do
|
98
|
-
expect(File.basename(@config.sConfigName)).to eq('config.yaml')
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'will confirm \'test1.yaml\' config to be loaded.' do
|
102
|
-
expect(File.basename(@config2.sConfigName)).to eq('test1.yaml')
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'can save \'test2=value\'' do
|
106
|
-
@config2.localSet('test2','value')
|
107
|
-
expect(@config2.saveConfig()).to equal(true)
|
108
|
-
config3 = Lorj::Config.new('test1.yaml')
|
109
|
-
expect(config3.localGet('test2')).to eq('value')
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
context "with get/set/exists?," do
|
115
|
-
before(:all) do
|
116
|
-
@config = Lorj::Config.new()
|
117
|
-
@url = @config.get('maestro_url')
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'can set and get data,' do
|
121
|
-
expect(@config.set(nil, nil)).to equal(false)
|
122
|
-
expect(@config.set(:test, nil)).to equal(true)
|
123
|
-
expect(@config.get(:test)).to equal(nil)
|
124
|
-
|
125
|
-
expect(@config.set(:test, 'data')).to equal(true)
|
126
|
-
expect(@config.get(:test)).to eq('data')
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'from defaults,' do
|
130
|
-
it 'can get application defaults' do
|
131
|
-
expect(@config.get(:maestro_url).class).to equal(String)
|
132
|
-
expect(@config.getAppDefault(:default, :maestro_url).class).to equal(String)
|
133
|
-
expect(@config.getAppDefault(:description, 'FORJ_HPC').class).to equal(String)
|
134
|
-
|
135
|
-
end
|
136
|
-
it 'can get Local defaults instead of application' do
|
137
|
-
expect(@config.localSet(:maestro_url,'local')).to equal(true)
|
138
|
-
expect(@config.localGet(:maestro_url)).to eq('local')
|
139
|
-
expect(@config.get(:maestro_url)).to eq('local')
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'can get runtime defaults instead of Local/application' do
|
143
|
-
expect(@config.set(:maestro_url, 'runtime')).to equal(true)
|
144
|
-
expect(@config.get(:maestro_url)).to eq('runtime')
|
145
|
-
expect(@config.localGet(:maestro_url)).to eq('local')
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'can get runtime defaults instead of application' do
|
149
|
-
expect(@config.localDel(:maestro_url)).to equal(true)
|
150
|
-
expect(@config.get(:maestro_url)).to eq('runtime')
|
151
|
-
expect(@config.localGet(:maestro_url)).to equal(nil)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'can get defaults if no key' do
|
155
|
-
expect(@config.set(:test1, nil)).to equal(true)
|
156
|
-
expect(@config.get(:test1, 'default')).to eq('default')
|
157
|
-
expect(@config.get(:test1, nil)).to equal(nil)
|
158
|
-
expect(@config.set(:maestro_url,nil)).to equal(true)
|
159
|
-
expect(@config.get(:maestro_url)).to eq(@url)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'Recursive Hash functions,' do
|
167
|
-
context "With recursive Hash functions" do
|
168
|
-
it 'can create a 3 levels of hash' do
|
169
|
-
yYAML = Lorj.rhSet(nil, 'level4', :level1, :level2, :level3)
|
170
|
-
expect(yYAML[:level1][:level2][:level3]).to eq('level4')
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'can add a 3 levels of hash in an existing hash' do
|
174
|
-
yYAML = Lorj.rhSet(nil, 'level4', :level1, :level2, :level3)
|
175
|
-
yYAML = Lorj.rhSet(yYAML, 'level1.1', :level1_1)
|
176
|
-
expect(yYAML[:level1][:level2][:level3]).to eq('level4')
|
177
|
-
expect(yYAML[:level1_1]).to eq('level1.1')
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'can get each levels of hash data' do
|
181
|
-
yYAML = Lorj.rhSet(nil, 'level4', :level1, :level2, :level3)
|
182
|
-
expect(Lorj.rhGet(yYAML, :level1).class).to equal(Hash)
|
183
|
-
expect(Lorj.rhGet(yYAML, :level1, :level2).class).to equal(Hash)
|
184
|
-
expect(Lorj.rhGet(yYAML, :level1, :level2, :level3).class).to equal(String)
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'can check existence of each levels of hash data' do
|
188
|
-
yYAML = Lorj.rhSet(nil, 'level4', :level1, :level2, :level3)
|
189
|
-
expect(Lorj.rhExist?(yYAML, :level1)).to eq(1)
|
190
|
-
expect(Lorj.rhExist?(yYAML, :level1, :level2)).to eq(2)
|
191
|
-
expect(Lorj.rhExist?(yYAML, :level1, :level2, :level3)).to eq(3)
|
192
|
-
expect(Lorj.rhExist?(yYAML, :level1_1, :level2, :level3)).to eq(0)
|
193
|
-
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|