occi-core 4.1.3 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +8 -0
- data/README.md +49 -17
- data/lib/occi/collection.rb +37 -21
- data/lib/occi/core/action.rb +5 -5
- data/lib/occi/core/action_instance.rb +45 -3
- data/lib/occi/core/actions.rb +2 -1
- data/lib/occi/core/attributes.rb +253 -73
- data/lib/occi/core/categories.rb +1 -0
- data/lib/occi/core/category.rb +25 -8
- data/lib/occi/core/entities.rb +1 -0
- data/lib/occi/core/entity.rb +51 -74
- data/lib/occi/core/kind.rb +15 -11
- data/lib/occi/core/kinds.rb +1 -1
- data/lib/occi/core/link.rb +14 -15
- data/lib/occi/core/links.rb +1 -1
- data/lib/occi/core/mixin.rb +5 -5
- data/lib/occi/core/mixins.rb +2 -2
- data/lib/occi/core/properties.rb +90 -12
- data/lib/occi/core/resource.rb +7 -3
- data/lib/occi/core/resources.rb +2 -2
- data/lib/occi/errors/attribute_definitions_converted_error.rb +5 -0
- data/lib/occi/errors/attribute_missing_error.rb +5 -0
- data/lib/occi/errors/attribute_name_invalid_error.rb +5 -0
- data/lib/occi/errors/attribute_not_defined_error.rb +5 -0
- data/lib/occi/errors/attribute_property_type_error.rb +5 -0
- data/lib/occi/errors/attribute_type_error.rb +5 -0
- data/lib/occi/errors/kind_not_defined_error.rb +5 -0
- data/lib/occi/errors/parser_input_error.rb +5 -0
- data/lib/occi/errors/parser_type_error.rb +5 -0
- data/lib/occi/errors.rb +1 -0
- data/lib/occi/extensions/hashie.rb +25 -0
- data/lib/occi/helpers/comparators/action_instance.rb +22 -0
- data/lib/occi/helpers/comparators/attributes.rb +22 -0
- data/lib/occi/helpers/comparators/categories.rb +22 -0
- data/lib/occi/helpers/comparators/category.rb +22 -0
- data/lib/occi/helpers/comparators/collection.rb +40 -0
- data/lib/occi/helpers/comparators/entities.rb +22 -0
- data/lib/occi/helpers/comparators/entity.rb +22 -0
- data/lib/occi/helpers/comparators/properties.rb +26 -0
- data/lib/occi/helpers/comparators.rb +1 -0
- data/lib/occi/infrastructure/compute.rb +11 -9
- data/lib/occi/infrastructure/network.rb +27 -27
- data/lib/occi/infrastructure/networkinterface.rb +22 -23
- data/lib/occi/infrastructure/os_tpl.rb +1 -1
- data/lib/occi/infrastructure/resource_tpl.rb +1 -1
- data/lib/occi/infrastructure/storage.rb +7 -6
- data/lib/occi/infrastructure/storagelink.rb +4 -4
- data/lib/occi/log.rb +13 -10
- data/lib/occi/model.rb +9 -8
- data/lib/occi/parser/json.rb +11 -9
- data/lib/occi/parser/ova.rb +12 -6
- data/lib/occi/parser/ovf.rb +173 -116
- data/lib/occi/parser/text/constants.rb +87 -0
- data/lib/occi/parser/text.rb +161 -200
- data/lib/occi/parser/xml.rb +10 -8
- data/lib/occi/parser.rb +100 -50
- data/lib/occi/settings.rb +2 -1
- data/lib/occi/version.rb +1 -1
- data/lib/occi-core.rb +6 -4
- data/occi-core.gemspec +0 -7
- data/spec/occi/collection_samples/collection1.json +1 -0
- data/spec/occi/collection_samples/directory2/collection2.json +1 -0
- data/spec/occi/collection_spec.rb +961 -31
- data/spec/occi/core/action_instance_spec.rb +317 -0
- data/spec/occi/core/action_spec.rb +71 -0
- data/spec/occi/core/attributes_spec.rb +582 -27
- data/spec/occi/core/category_spec.rb +194 -18
- data/spec/occi/core/entities_spec.rb +96 -0
- data/spec/occi/core/entity_spec.rb +317 -28
- data/spec/occi/core/kind_spec.rb +127 -16
- data/spec/occi/core/link_spec.rb +35 -0
- data/spec/occi/core/links_spec.rb +130 -0
- data/spec/occi/core/mixins_spec.rb +107 -0
- data/spec/occi/core/properties_spec.rb +167 -0
- data/spec/occi/core/resource_spec.rb +23 -9
- data/spec/occi/core_spec.rb +12 -0
- data/spec/occi/infrastructure/compute_spec.rb +218 -18
- data/spec/occi/infrastructure/network_spec.rb +96 -0
- data/spec/occi/infrastructure/networkinterface_spec.rb +96 -0
- data/spec/occi/infrastructure/storage_spec.rb +33 -0
- data/spec/occi/infrastructure/storagelink_spec.rb +45 -0
- data/spec/occi/log_spec.rb +104 -1
- data/spec/occi/model_spec.rb +251 -39
- data/spec/occi/{test.json → parser/json_samples/test.json} +0 -0
- data/spec/occi/parser/ova_samples/test.dump +0 -0
- data/spec/occi/{test.ova → parser/ova_samples/test.ova} +0 -0
- data/spec/occi/parser/ovf_samples/test.dump +0 -0
- data/spec/occi/{test.ovf → parser/ovf_samples/test.ovf} +0 -0
- data/spec/occi/parser/text_samples/occi_categories.dump +0 -0
- data/spec/occi/parser/text_samples/occi_categories.text +2 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +10 -0
- data/spec/occi/parser/text_samples/occi_link_resource_instance.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_resource_instance.text +7 -0
- data/spec/occi/parser/text_samples/occi_link_simple.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_simple.link_string.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_simple.text +1 -0
- data/spec/occi/parser/text_samples/occi_link_w_attributes.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_w_attributes.text +7 -0
- data/spec/occi/parser/text_samples/occi_link_w_category.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_w_category.text +3 -0
- data/spec/occi/parser/text_samples/occi_model_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_model_rocci_server.text +51 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.text +11 -0
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +11 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +16 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +13 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +9 -0
- data/spec/occi/parser/text_spec.rb +274 -78
- data/spec/occi/parser/xml_samples/test.xml +352 -0
- data/spec/occi/parser_spec.rb +255 -104
- data/spec/occi-core_spec.rb +31 -0
- data/spec/spec_helper.rb +6 -2
- metadata +110 -111
- checksums.yaml +0 -7
- data/spec/occi/core/attribute_spec.rb +0 -0
@@ -1,29 +1,229 @@
|
|
1
1
|
module Occi
|
2
2
|
module Infrastructure
|
3
3
|
describe Compute do
|
4
|
+
let(:compute){ Occi::Infrastructure::Compute.new }
|
5
|
+
let(:modl){
|
6
|
+
modl = Occi::Model.new
|
7
|
+
modl.register_infrastructure
|
8
|
+
modl }
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
context 'Storage Links' do
|
11
|
+
let(:target){
|
12
|
+
target = Occi::Infrastructure::Storage.new
|
13
|
+
# create a random ID as the storage resource must already exist and therefore must have an ID assigned
|
14
|
+
target.id = UUIDTools::UUID.random_create.to_s
|
15
|
+
target }
|
16
|
+
|
17
|
+
context '#storagelink' do
|
18
|
+
it "creates a single storagelink" do
|
19
|
+
compute.storagelink target
|
20
|
+
expect(compute.links).to have(1).link
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates a storagelink to a storage resource" do
|
24
|
+
compute.storagelink target
|
25
|
+
expect(compute.links.first).to be_kind_of Occi::Infrastructure::Storagelink
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has the correct link as target" do
|
29
|
+
compute.storagelink target
|
30
|
+
expect(compute.links.first.target).to be target
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has target with correct ID" do
|
34
|
+
compute.storagelink target
|
35
|
+
expect(compute.links.first.target.id).to eq target.id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context '#storagelinks' do
|
40
|
+
it 'has the correct number of members -- single' do
|
41
|
+
compute.storagelink target
|
42
|
+
compute.model=modl
|
43
|
+
expect(compute.storagelinks.count).to eq 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has the correct number of members -- double' do
|
47
|
+
target2 = Occi::Infrastructure::Storage.new
|
48
|
+
target2.id = UUIDTools::UUID.random_create.to_s
|
49
|
+
compute.storagelink target
|
50
|
+
compute.storagelink target2
|
51
|
+
compute.model=modl
|
52
|
+
expect(compute.storagelinks.count).to eq 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'shows correctly in collections' do
|
56
|
+
compute.storagelink target
|
57
|
+
compute.model=modl
|
58
|
+
expect(compute.storagelinks[0].target.id).to eq target.id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'Network Interfaces' do
|
64
|
+
let(:target){
|
65
|
+
target = Occi::Infrastructure::Network.new
|
66
|
+
# create a random ID as the network resource must already exist and therefore must have an ID assigned
|
67
|
+
target.id = UUIDTools::UUID.random_create.to_s
|
68
|
+
target }
|
69
|
+
|
70
|
+
context '#networkinterface' do
|
71
|
+
it "creates a single networkinterface" do
|
72
|
+
compute.networkinterface target
|
73
|
+
expect(compute.links).to have(1).link
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a networkinterface to a storage resource" do
|
77
|
+
compute.networkinterface target
|
78
|
+
expect(compute.links.first).to be_kind_of Occi::Infrastructure::Networkinterface
|
79
|
+
end
|
80
|
+
|
81
|
+
it "has the correct interface as target" do
|
82
|
+
compute.networkinterface target
|
83
|
+
expect(compute.links.first.target).to be target
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context '#networkinterfaces' do
|
88
|
+
it 'has the correct number of members -- single' do
|
89
|
+
compute.networkinterface target
|
90
|
+
compute.model=modl
|
91
|
+
expect(compute.networkinterfaces.count).to eq 1
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'has the correct number of members -- double' do
|
95
|
+
target2 = Occi::Infrastructure::Network.new
|
96
|
+
target2.id = UUIDTools::UUID.random_create.to_s
|
97
|
+
compute.networkinterface target
|
98
|
+
compute.networkinterface target2
|
99
|
+
compute.model=modl
|
100
|
+
expect(compute.networkinterfaces.count).to eq 2
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'shows correctly in collections' do
|
104
|
+
compute.networkinterface target
|
105
|
+
compute.model=modl
|
106
|
+
expect(compute.networkinterfaces[0].target.id).to eq target.id
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context '#architecture' do
|
112
|
+
it 'can be set and read' do
|
113
|
+
compute.architecture = 'x64'
|
114
|
+
expect(compute.architecture).to eq 'x64'
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'Pattern matching' do
|
118
|
+
before(:each) { Occi::Settings['compatibility']=false }
|
119
|
+
after(:each) { Occi::Settings.reload! }
|
120
|
+
|
121
|
+
it 'preserves non-matching values with verification settings off' do
|
122
|
+
Occi::Settings['verify_attribute_pattern']=false
|
123
|
+
compute.model=modl
|
124
|
+
expect{compute.architecture = 'z80'}.to_not raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'rejects non-matching values with verification settings on' do
|
128
|
+
Occi::Settings['verify_attribute_pattern']=true
|
129
|
+
compute.model=modl
|
130
|
+
expect{compute.architecture = 'z80'}.to raise_error Occi::Errors::AttributeTypeError
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context '#cores' do
|
136
|
+
it 'can be set and read' do
|
137
|
+
compute.cores = 32
|
138
|
+
expect(compute.cores).to eq 32
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'rejects non-numeric values' do
|
142
|
+
expect{compute.memory = 'a few'}.to raise_error
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context '#hostname' do
|
147
|
+
it 'can be set and read' do
|
148
|
+
compute.hostname = 'testhostname'
|
149
|
+
expect(compute.hostname).to eq 'testhostname'
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'Pattern matching' do
|
153
|
+
before(:each) { Occi::Settings['compatibility']=false }
|
154
|
+
after(:each) { Occi::Settings.reload! }
|
155
|
+
|
156
|
+
it 'preserves non-matching values with verification settings off' do
|
157
|
+
Occi::Settings['verify_attribute_pattern']=false
|
158
|
+
compute.model=modl
|
159
|
+
expect{compute.hostname = 'notaproperhostname'}.to_not raise_error
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'rejects non-matching values with verification settings on' do
|
163
|
+
Occi::Settings['verify_attribute_pattern']=true
|
164
|
+
compute.model=modl
|
165
|
+
expect{compute.hostname = 'notaproperhostname'}.to raise_error Occi::Errors::AttributeTypeError
|
166
|
+
end
|
167
|
+
end
|
14
168
|
end
|
15
169
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
170
|
+
context '#speed' do
|
171
|
+
it 'can be set and read' do
|
172
|
+
compute.speed = 3000.0
|
173
|
+
expect(compute.speed).to eq 3000.0
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'rejects non-numeric values' do
|
177
|
+
expect{compute.memory = 'fast'}.to raise_error
|
178
|
+
end
|
25
179
|
end
|
26
180
|
|
181
|
+
context '#memory' do
|
182
|
+
it 'can be set and read' do
|
183
|
+
compute.memory = 4096
|
184
|
+
expect(compute.memory).to eq 4096
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'rejects non-numeric values' do
|
188
|
+
expect{compute.memory = 'a lot'}.to raise_error
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context '#state' do
|
193
|
+
it 'has correct default value with set_defaults == true' do
|
194
|
+
compute.model=modl
|
195
|
+
compute.check(true)
|
196
|
+
expect(compute.state).to eq 'inactive'
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'does not take the default value with set_defaults set to default' do
|
200
|
+
compute.model=modl
|
201
|
+
compute.check
|
202
|
+
expect(compute.state).to_not eq 'inactive'
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'can be set and read' do
|
206
|
+
compute.state = 'active'
|
207
|
+
expect(compute.state).to eq 'active'
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'Pattern matching' do
|
211
|
+
before(:each) { Occi::Settings['compatibility']=false }
|
212
|
+
after(:each) { Occi::Settings.reload! }
|
213
|
+
|
214
|
+
it 'preserves non-matching values with verification settings off' do
|
215
|
+
Occi::Settings['verify_attribute_pattern']=false
|
216
|
+
compute.model=modl
|
217
|
+
expect{compute.state = 'broken'}.to_not raise_error
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'rejects non-matching values with verification settings on' do
|
221
|
+
Occi::Settings['verify_attribute_pattern']=true
|
222
|
+
compute.model=modl
|
223
|
+
expect{compute.state = 'broken'}.to raise_error Occi::Errors::AttributeTypeError
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
27
227
|
end
|
28
228
|
end
|
29
229
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Occi
|
2
|
+
module Infrastructure
|
3
|
+
describe Network do
|
4
|
+
|
5
|
+
context 'setters/getters' do
|
6
|
+
let(:network){ Occi::Infrastructure::Network.new }
|
7
|
+
context '#vlan' do
|
8
|
+
it 'Can be set and read as attribute' do
|
9
|
+
network.vlan = 4
|
10
|
+
expect(network.attributes.occi.network.vlan).to eql 4
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'Can be set and read through getter' do
|
14
|
+
network.vlan = 4
|
15
|
+
expect(network.vlan).to eql 4
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#label' do
|
20
|
+
it 'Can be set and read as attribute' do
|
21
|
+
network.label = "Network Label"
|
22
|
+
expect(network.attributes.occi.network.label).to eql "Network Label"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Can be set and read through getter' do
|
26
|
+
network.label = "Network Label"
|
27
|
+
expect(network.label).to eql "Network Label"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#state' do
|
32
|
+
it 'Can be set and read as attribute' do
|
33
|
+
network.state = "inactive"
|
34
|
+
expect(network.attributes.occi.network.state).to eql "inactive"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Can be set and read through getter' do
|
38
|
+
network.state = "inactive"
|
39
|
+
expect(network.state).to eql "inactive"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#address' do
|
44
|
+
it 'Can be set and read as attribute' do
|
45
|
+
network.address = "127.0.0.1"
|
46
|
+
expect(network.attributes.occi.network.address).to eql "127.0.0.1"
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Can be set and read through getter' do
|
50
|
+
network.address = "127.0.0.1"
|
51
|
+
expect(network.address).to eql "127.0.0.1"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#gateway' do
|
56
|
+
it 'Can be set and read as attribute' do
|
57
|
+
network.gateway = "127.0.0.255"
|
58
|
+
expect(network.attributes.occi.network.gateway).to eql "127.0.0.255"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'Can be set and read through getter' do
|
62
|
+
network.gateway = "127.0.0.255"
|
63
|
+
expect(network.gateway).to eql "127.0.0.255"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#allocation' do
|
68
|
+
it 'Can be set and read as attribute' do
|
69
|
+
network.allocation = "static"
|
70
|
+
expect(network.attributes.occi.network.allocation).to eql "static"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'Can be set and read through getter' do
|
74
|
+
network.allocation = "static"
|
75
|
+
expect(network.allocation).to eql "static"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context '#ipnetwork' do
|
81
|
+
let(:network){ Occi::Infrastructure::Network.new }
|
82
|
+
|
83
|
+
it 'adds the Ipnetwork mixin' do
|
84
|
+
network.ipnetwork(true)
|
85
|
+
expect(network.mixins.first.to_s).to eql "http://schemas.ogf.org/occi/infrastructure/network#ipnetwork"
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'removes the Ipnetwork mixin' do
|
89
|
+
network.ipnetwork(true)
|
90
|
+
network.ipnetwork(false)
|
91
|
+
expect(network.mixins.count).to eql 0
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Occi
|
2
|
+
module Infrastructure
|
3
|
+
describe Networkinterface do
|
4
|
+
|
5
|
+
context 'setters/getters' do
|
6
|
+
let(:networkinterface){ Occi::Infrastructure::Networkinterface.new }
|
7
|
+
context '#interface' do
|
8
|
+
it 'Can be set and read as attribute' do
|
9
|
+
networkinterface.interface = "eth0"
|
10
|
+
expect(networkinterface.attributes.occi.networkinterface.interface).to eql "eth0"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'Can be set and read through getter' do
|
14
|
+
networkinterface.interface = "eth0"
|
15
|
+
expect(networkinterface.interface).to eql "eth0"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#mac' do
|
20
|
+
it 'Can be set and read as attribute' do
|
21
|
+
networkinterface.mac = "FF-FF-FF-FF-FF-FF"
|
22
|
+
expect(networkinterface.attributes.occi.networkinterface.mac).to eql "FF-FF-FF-FF-FF-FF"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Can be set and read through getter' do
|
26
|
+
networkinterface.mac = "FF-FF-FF-FF-FF-FF"
|
27
|
+
expect(networkinterface.mac).to eql "FF-FF-FF-FF-FF-FF"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#state' do
|
32
|
+
it 'Can be set and read as attribute' do
|
33
|
+
networkinterface.state = "error"
|
34
|
+
expect(networkinterface.attributes.occi.networkinterface.state).to eql "error"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Can be set and read through getter' do
|
38
|
+
networkinterface.state = "error"
|
39
|
+
expect(networkinterface.state).to eql "error"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#address' do
|
44
|
+
it 'Can be set and read as attribute' do
|
45
|
+
networkinterface.address = "127.0.0.1"
|
46
|
+
expect(networkinterface.attributes.occi.networkinterface.address).to eql "127.0.0.1"
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Can be set and read through getter' do
|
50
|
+
networkinterface.address = "127.0.0.1"
|
51
|
+
expect(networkinterface.address).to eql "127.0.0.1"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#gateway' do
|
56
|
+
it 'Can be set and read as attribute' do
|
57
|
+
networkinterface.gateway = "127.0.0.255"
|
58
|
+
expect(networkinterface.attributes.occi.networkinterface.gateway).to eql "127.0.0.255"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'Can be set and read through getter' do
|
62
|
+
networkinterface.gateway = "127.0.0.255"
|
63
|
+
expect(networkinterface.gateway).to eql "127.0.0.255"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context '#allocation' do
|
68
|
+
it 'Can be set and read as attribute' do
|
69
|
+
networkinterface.allocation = "static"
|
70
|
+
expect(networkinterface.attributes.occi.networkinterface.allocation).to eql "static"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'Can be set and read through getter' do
|
74
|
+
networkinterface.allocation = "static"
|
75
|
+
expect(networkinterface.allocation).to eql "static"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context '#ipnetworkinterface' do
|
81
|
+
let(:networkinterface){ Occi::Infrastructure::Networkinterface.new }
|
82
|
+
|
83
|
+
it 'adds the Ipnetwork mixin' do
|
84
|
+
networkinterface.ipnetworkinterface(true)
|
85
|
+
expect(networkinterface.mixins.first.to_s).to eql "http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface"
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'removes the Ipnetwork mixin' do
|
89
|
+
networkinterface.ipnetworkinterface(true)
|
90
|
+
networkinterface.ipnetworkinterface(false)
|
91
|
+
expect(networkinterface.mixins.count).to eql 0
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Occi
|
2
|
+
module Infrastructure
|
3
|
+
describe Storage do
|
4
|
+
|
5
|
+
context 'setters/getters' do
|
6
|
+
let(:storage){ Occi::Infrastructure::Storage.new }
|
7
|
+
context '#size' do
|
8
|
+
it 'Can be set and read as attribute' do
|
9
|
+
storage.size = 16777216
|
10
|
+
expect(storage.attributes.occi.storage['size']).to eql 16777216
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'Can be set and read through getter' do
|
14
|
+
storage.size = 16777216
|
15
|
+
expect(storage.size).to eql 16777216
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#state' do
|
20
|
+
it 'Can be set and read as attribute' do
|
21
|
+
storage.state = "online"
|
22
|
+
expect(storage.attributes.occi.storage.state).to eql "online"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Can be set and read through getter' do
|
26
|
+
storage.state = "online"
|
27
|
+
expect(storage.state).to eql "online"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Occi
|
2
|
+
module Infrastructure
|
3
|
+
describe Storagelink do
|
4
|
+
|
5
|
+
context 'setters/getters' do
|
6
|
+
let(:storagelink){ Occi::Infrastructure::Storagelink.new }
|
7
|
+
context '#deviceid' do
|
8
|
+
it 'Can be set and read as attribute' do
|
9
|
+
storagelink.deviceid = "sda"
|
10
|
+
expect(storagelink.attributes.occi.storagelink.deviceid).to eql "sda"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'Can be set and read through getter' do
|
14
|
+
storagelink.deviceid = "sda"
|
15
|
+
expect(storagelink.deviceid).to eql "sda"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#mountpoint' do
|
20
|
+
it 'Can be set and read as attribute' do
|
21
|
+
storagelink.mountpoint = "/mnt/sda"
|
22
|
+
expect(storagelink.attributes.occi.storagelink.mountpoint).to eql "/mnt/sda"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Can be set and read through getter' do
|
26
|
+
storagelink.mountpoint = "/mnt/sda"
|
27
|
+
expect(storagelink.mountpoint).to eql "/mnt/sda"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#state' do
|
32
|
+
it 'Can be set and read as attribute' do
|
33
|
+
storagelink.state = "active"
|
34
|
+
expect(storagelink.attributes.occi.storagelink.state).to eql "active"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Can be set and read through getter' do
|
38
|
+
storagelink.state = "active"
|
39
|
+
expect(storagelink.state).to eql "active"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/occi/log_spec.rb
CHANGED
@@ -1,7 +1,101 @@
|
|
1
1
|
module Occi
|
2
2
|
describe Log do
|
3
3
|
|
4
|
-
|
4
|
+
context 'logging to files' do
|
5
|
+
let!(:testIO){ StringIO.new}
|
6
|
+
let!(:logger){ Occi::Log.new(testIO) }
|
7
|
+
after(:each) do
|
8
|
+
logger.close
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'logs correctly with prioritiy DEBUG' do
|
12
|
+
Occi::Log.debug("Test Debug Text")
|
13
|
+
expect(testIO.string).to match (/D.*DEBUG.*Test Debug Text/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'logs correctly with prioritiy INFO' do
|
17
|
+
Occi::Log.info("Test Info Text")
|
18
|
+
expect(testIO.string).to match (/I.*INFO.*Test Info Text/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'logs correctly with prioritiy WARN' do
|
22
|
+
Occi::Log.warn("Test Warning Text")
|
23
|
+
expect(testIO.string).to match (/W.*WARN.*Test Warning Text/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'logs correctly with prioritiy ERROR' do
|
27
|
+
Occi::Log.error("Test Error Text")
|
28
|
+
expect(testIO.string).to match (/E.*ERROR.*Test Error Text/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'logs correctly with prioritiy FATAL' do
|
32
|
+
Occi::Log.fatal("Test Fatal Text")
|
33
|
+
expect(testIO.string).to match (/F.*FATAL.*Test Fatal Text/)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with log level set to filter out some messages" do
|
37
|
+
before(:each) do
|
38
|
+
logger.level=Occi::Log::ERROR
|
39
|
+
end
|
40
|
+
it 'does not log prioritiy DEBUG with log level set to ERROR' do
|
41
|
+
Occi::Log.debug("Second Debug Text")
|
42
|
+
expect(testIO.string).to_not match (/D.*DEBUG.*Second Debug Text/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not log prioritiy WARN with log level set to ERROR' do
|
46
|
+
Occi::Log.info("Second Info Text")
|
47
|
+
expect(testIO.string).to_not match (/I.*INFO.*Second Info Text/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'does not log prioritiy WARN with log level set to ERROR' do
|
51
|
+
Occi::Log.warn("Second Warning Text")
|
52
|
+
expect(testIO.string).to_not match (/W.*WARN.*Second Warning Text/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'still logs with prioritiy ERROR' do
|
56
|
+
Occi::Log.error("Second Error Text")
|
57
|
+
expect(testIO.string).to match (/E.*ERROR.*Second Error Text/)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'still logs with prioritiy FATAL' do
|
61
|
+
Occi::Log.fatal("Second Fatal Text")
|
62
|
+
expect(testIO.string).to match (/F.*FATAL.*Second Fatal Text/)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'tells log lines apart correctly' do #This tests the correctness of the testing procedure rather than the code itself
|
67
|
+
Occi::Log.error("Second Error Text")
|
68
|
+
Occi::Log.fatal("Second Fatal Text")
|
69
|
+
expect(testIO.string).to_not match (/E.*ERROR.*Test Fatal Text/)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'copes with read-only log file' do
|
75
|
+
(contents = "locked file contents").freeze
|
76
|
+
testIO = StringIO.open(contents)
|
77
|
+
logger = Occi::Log.new(testIO)
|
78
|
+
expect(Occi::Log.fatal("New content")).to eq nil
|
79
|
+
logger.close
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'reporting current log levels correctly' do
|
83
|
+
testIO = StringIO.new
|
84
|
+
logger = Occi::Log.new(testIO)
|
85
|
+
|
86
|
+
it 'has initial log level set to 0' do
|
87
|
+
expect(logger.level).to eq 0
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'reports ERROR log level correctly' do
|
91
|
+
logger.level=Occi::Log::ERROR
|
92
|
+
expect(logger.level).to eq 3
|
93
|
+
end
|
94
|
+
|
95
|
+
logger.close
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'logs through a pipe' do
|
5
99
|
r, w = IO.pipe
|
6
100
|
logger = Occi::Log.new(w)
|
7
101
|
logger.level = Occi::Log::INFO
|
@@ -10,5 +104,14 @@ module Occi
|
|
10
104
|
logger.close
|
11
105
|
end
|
12
106
|
|
107
|
+
it 'logs through a pre-initiated Logger' do
|
108
|
+
r, w = IO.pipe
|
109
|
+
logger = Occi::Log.new(Logger.new(w))
|
110
|
+
logger.level = Occi::Log::INFO
|
111
|
+
Occi::Log.info("Test")
|
112
|
+
r.readline.include?("Test")
|
113
|
+
logger.close
|
114
|
+
end
|
115
|
+
|
13
116
|
end
|
14
117
|
end
|