oneacct-export 0.3.0 → 0.4.2
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/README.md +9 -1
- data/bin/oneacct-export +15 -3
- data/config/conf.yml +1 -0
- data/examples/usr/bin/oneacct-export-cron +31 -7
- data/lib/data_validators/apel_data_validator.rb +17 -5
- data/lib/data_validators/data_validator_helper.rb +1 -0
- data/lib/input_validator.rb +5 -0
- data/lib/one_data_accessor.rb +62 -10
- data/lib/one_worker.rb +89 -10
- data/lib/one_writer.rb +3 -1
- data/lib/oneacct_exporter.rb +3 -5
- data/lib/oneacct_exporter/version.rb +1 -1
- data/lib/oneacct_opts.rb +13 -3
- data/lib/output_types.rb +3 -3
- data/lib/templates/apel-0.2.erb +1 -1
- data/lib/templates/apel-0.4.erb +34 -0
- data/mock/one_data_accessor_cluster_01.xml +27 -0
- data/mock/one_data_accessor_cluster_02.xml +23 -0
- data/mock/one_data_accessor_host_01.xml +65 -0
- data/mock/one_data_accessor_host_02.xml +66 -0
- data/mock/one_data_accessor_host_03.xml +63 -0
- data/mock/one_data_accessor_host_04.xml +63 -0
- data/mock/one_data_accessor_host_05.xml +63 -0
- data/mock/one_worker_vm_number_of_public_ips_01.xml +275 -0
- data/mock/one_worker_vm_number_of_public_ips_02.xml +164 -0
- data/mock/one_worker_vm_number_of_public_ips_03.xml +189 -0
- data/mock/one_worker_vm_search_benchmark_01.xml +175 -0
- data/mock/one_worker_vm_search_benchmark_02.xml +175 -0
- data/oneacct-export.gemspec +6 -5
- data/spec/data_validators/apel_data_validator_spec.rb +72 -0
- data/spec/one_data_accessor_spec.rb +114 -43
- data/spec/one_worker_spec.rb +148 -18
- data/spec/oneacct_exporter_spec.rb +3 -13
- data/spec/oneacct_opts_spec.rb +22 -0
- data/spec/spec_helper.rb +2 -1
- metadata +40 -13
data/oneacct-export.gemspec
CHANGED
@@ -20,14 +20,15 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.required_ruby_version = '>= 2.0.0'
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.
|
24
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
25
25
|
spec.add_development_dependency 'fuubar', '~> 2.0.0'
|
26
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
27
27
|
spec.add_development_dependency 'rubygems-tasks', '~> 0.2.4'
|
28
28
|
|
29
29
|
spec.add_runtime_dependency 'opennebula', '~> 4.6.0'
|
30
|
-
spec.add_runtime_dependency 'syslogger', '~> 1.6
|
31
|
-
spec.add_runtime_dependency 'sidekiq', '~> 3.
|
30
|
+
spec.add_runtime_dependency 'syslogger', '~> 1.6'
|
31
|
+
spec.add_runtime_dependency 'sidekiq', '~> 3.4'
|
32
32
|
spec.add_runtime_dependency 'settingslogic', '~> 2.0.9'
|
33
|
+
spec.add_runtime_dependency 'chronic_duration', '~> 0.10'
|
33
34
|
end
|
@@ -50,6 +50,11 @@ module DataValidators
|
|
50
50
|
data['user_dn'] = '/MY=STuPID/CN=DN/CN=HERE'
|
51
51
|
data['image_name'] = 'https://appdb.egi.eu/store/vo/image/blablablabla/'
|
52
52
|
|
53
|
+
data['cloud_compute_service'] = 'CloudComputeServiceValue'
|
54
|
+
|
55
|
+
data['benchmark_type'] = 'b_type_999'
|
56
|
+
data['benchmark_value'] = '132.68'
|
57
|
+
|
53
58
|
data
|
54
59
|
end
|
55
60
|
|
@@ -74,6 +79,7 @@ module DataValidators
|
|
74
79
|
valid_data['network_inbound'] = 3
|
75
80
|
valid_data['network_outbound'] = 5
|
76
81
|
valid_data['memory'] = '1736960'
|
82
|
+
valid_data['number_of_public_ips'] = 0
|
77
83
|
history = []
|
78
84
|
rec = {}
|
79
85
|
rec['start_time'] = '1383741169'
|
@@ -101,6 +107,11 @@ module DataValidators
|
|
101
107
|
valid_data['suspend'] = 425
|
102
108
|
valid_data['disk_size'] = 52608
|
103
109
|
|
110
|
+
valid_data['cloud_compute_service'] = 'CloudComputeServiceValue'
|
111
|
+
|
112
|
+
valid_data['benchmark_type'] = 'b_type_999'
|
113
|
+
valid_data['benchmark_value'] = '132.68'
|
114
|
+
|
104
115
|
valid_data
|
105
116
|
end
|
106
117
|
|
@@ -492,6 +503,67 @@ module DataValidators
|
|
492
503
|
expect(subject.validate_data(data)).to eq(valid_data)
|
493
504
|
end
|
494
505
|
end
|
506
|
+
|
507
|
+
context 'without cloud compute service' do
|
508
|
+
before :example do
|
509
|
+
data['cloud_compute_service'] = nil
|
510
|
+
valid_data['cloud_compute_service'] = 'NULL'
|
511
|
+
end
|
512
|
+
|
513
|
+
it 'replaces cloud compute service with "NULL"' do
|
514
|
+
expect(subject.validate_data(data)).to eq(valid_data)
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
context 'without benchmark_type' do
|
519
|
+
before :example do
|
520
|
+
data['benchmark_type'] = nil
|
521
|
+
valid_data['benchmark_type'] = 'NULL'
|
522
|
+
valid_data['benchmark_value'] = 'NULL'
|
523
|
+
end
|
524
|
+
|
525
|
+
it 'replaced benchmark type and benchmark value with "NULL"' do
|
526
|
+
expect(subject.validate_data(data)).to eq(valid_data)
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
context 'without benchmark_value' do
|
531
|
+
before :example do
|
532
|
+
data['benchmark_value'] = nil
|
533
|
+
valid_data['benchmark_type'] = 'NULL'
|
534
|
+
valid_data['benchmark_value'] = 'NULL'
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'replaced benchmark type and benchmark value with "NULL"' do
|
538
|
+
expect(subject.validate_data(data)).to eq(valid_data)
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
context 'without benchmark_type and benchmark_value' do
|
543
|
+
before :example do
|
544
|
+
data['benchmark_type'] = nil
|
545
|
+
data['benchmark_value'] = nil
|
546
|
+
valid_data['benchmark_type'] = 'NULL'
|
547
|
+
valid_data['benchmark_value'] = 'NULL'
|
548
|
+
end
|
549
|
+
|
550
|
+
it 'replaced benchmark type and benchmark value with "NULL"' do
|
551
|
+
expect(subject.validate_data(data)).to eq(valid_data)
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
context 'with benchmark_value that is not a number' do
|
556
|
+
before :example do
|
557
|
+
data['benchmark_value'] = 'string'
|
558
|
+
valid_data['benchmark_type'] = 'NULL'
|
559
|
+
valid_data['benchmark_value'] = 'NULL'
|
560
|
+
end
|
561
|
+
|
562
|
+
it 'replaced benchmark type and benchmark value with "NULL"' do
|
563
|
+
expect(subject.validate_data(data)).to eq(valid_data)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
495
567
|
end
|
496
568
|
end
|
497
569
|
end
|
@@ -155,42 +155,44 @@ describe OneDataAccessor do
|
|
155
155
|
before :example do
|
156
156
|
allow(vm_pool).to receive(:info) { 'valid_rc' }
|
157
157
|
allow(vm_pool).to receive(:to) { vm_pool }
|
158
|
+
allow(vm_pool).to receive(:count) { 100 }
|
159
|
+
allow(vm_pool).to receive(:entries) { [last] }
|
158
160
|
allow(OpenNebula::VirtualMachinePool).to receive(:new) { vm_pool }
|
159
161
|
end
|
160
162
|
|
161
163
|
let(:vm_pool) { double('vm_pool') }
|
164
|
+
let(:last) { double('last') }
|
162
165
|
|
163
166
|
context 'without compatibility mode' do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
167
|
+
it 'requests vms with correct range' do
|
168
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 0, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
169
|
+
allow(last).to receive(:id) {99}
|
170
|
+
subject.load_vm_pool
|
168
171
|
|
169
|
-
|
170
|
-
|
172
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 100, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
173
|
+
allow(last).to receive(:id) {199}
|
174
|
+
subject.load_vm_pool
|
171
175
|
|
172
|
-
|
173
|
-
|
176
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 200, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
177
|
+
allow(last).to receive(:id) {299}
|
178
|
+
subject.load_vm_pool
|
174
179
|
|
175
|
-
|
176
|
-
|
180
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 300, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
181
|
+
allow(last).to receive(:id) {399}
|
182
|
+
subject.load_vm_pool
|
177
183
|
|
178
|
-
|
179
|
-
|
184
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 400, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
185
|
+
allow(last).to receive(:id) {499}
|
186
|
+
subject.load_vm_pool
|
180
187
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
it 'returns obtained vm pool' do
|
186
|
-
expect(subject.load_vm_pool(0)).to eq(vm_pool)
|
187
|
-
end
|
188
|
+
expect(vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, 500, -100, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
189
|
+
allow(last).to receive(:id) {599}
|
190
|
+
subject.load_vm_pool
|
188
191
|
end
|
189
192
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
193
|
+
it 'returns obtained vm pool' do
|
194
|
+
allow(last).to receive(:id) {99}
|
195
|
+
expect(subject.load_vm_pool).to eq(vm_pool)
|
194
196
|
end
|
195
197
|
end
|
196
198
|
|
@@ -199,17 +201,19 @@ describe OneDataAccessor do
|
|
199
201
|
Settings.output['num_of_vms_per_file'] = 3
|
200
202
|
allow(OpenNebula::VirtualMachinePool).to receive(:new) { compatibility_vm_pool }
|
201
203
|
allow(compatibility_vm_pool).to receive(:info) { 'valid_rc' }
|
204
|
+
allow(last).to receive(:id).and_return(2, 5, 8, 10)
|
202
205
|
end
|
203
206
|
|
204
207
|
let(:one_data_accessor) { OneDataAccessor.new(true, Logger.new('/dev/null')) }
|
205
|
-
let(:compatibility_vm_pool) { [0, 1,
|
208
|
+
let(:compatibility_vm_pool) { [0, 1, last, 3, 4, last, 6, 7, last, 9, last] }
|
209
|
+
let(:last) { double('last') }
|
206
210
|
|
207
211
|
it 'returns correct parts of vm pool' do
|
208
212
|
expect(compatibility_vm_pool).to receive(:info).with(OpenNebula::Pool::INFO_ALL, -1, -1, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
209
|
-
expect(subject.load_vm_pool
|
210
|
-
expect(subject.load_vm_pool
|
211
|
-
expect(subject.load_vm_pool
|
212
|
-
expect(subject.load_vm_pool
|
213
|
+
expect(subject.load_vm_pool).to eq([0, 1, last])
|
214
|
+
expect(subject.load_vm_pool).to eq([3, 4, last])
|
215
|
+
expect(subject.load_vm_pool).to eq([6, 7, last])
|
216
|
+
expect(subject.load_vm_pool).to eq([9, last])
|
213
217
|
end
|
214
218
|
end
|
215
219
|
end
|
@@ -333,23 +337,12 @@ describe OneDataAccessor do
|
|
333
337
|
let(:vm2) { { 'ID' => '2' } }
|
334
338
|
let(:vm3) { { 'ID' => '3' } }
|
335
339
|
let(:vm_pool) { [vm1, vm2, vm3] }
|
336
|
-
let(:batch_number) { 5 }
|
337
|
-
|
338
|
-
context 'is called with some batch number' do
|
339
|
-
before :example do
|
340
|
-
expect(subject).to receive(:load_vm_pool).with(5) { vm_pool }
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'calls load_vm_pool with that batch number' do
|
344
|
-
subject.vms(batch_number, nil, nil)
|
345
|
-
end
|
346
|
-
end
|
347
340
|
|
348
341
|
context 'when vm pool is empty' do
|
349
342
|
let(:vm_pool) { [] }
|
350
343
|
|
351
344
|
it 'returns nil' do
|
352
|
-
expect(subject.vms(
|
345
|
+
expect(subject.vms(nil, nil)).to be_nil
|
353
346
|
end
|
354
347
|
end
|
355
348
|
|
@@ -360,14 +353,14 @@ describe OneDataAccessor do
|
|
360
353
|
expect(subject).to receive(:want?).with(vm3, nil, nil).once
|
361
354
|
end
|
362
355
|
it 'calls want?' do
|
363
|
-
subject.vms(
|
356
|
+
subject.vms(nil, nil)
|
364
357
|
end
|
365
358
|
end
|
366
359
|
|
367
360
|
context 'for every vm obtained from vm pool' do
|
368
361
|
context 'with ID attribute' do
|
369
362
|
it 'returns ID of those vms' do
|
370
|
-
expect(subject.vms(
|
363
|
+
expect(subject.vms(nil, nil)).to eq([1, 2, 3])
|
371
364
|
end
|
372
365
|
end
|
373
366
|
|
@@ -376,7 +369,7 @@ describe OneDataAccessor do
|
|
376
369
|
let(:vm3) { {} }
|
377
370
|
|
378
371
|
it 'skips vms without ID attribute and returns only thouse with it' do
|
379
|
-
expect(subject.vms(
|
372
|
+
expect(subject.vms(nil, nil)).to eq([2])
|
380
373
|
end
|
381
374
|
end
|
382
375
|
end
|
@@ -438,4 +431,82 @@ describe OneDataAccessor do
|
|
438
431
|
end
|
439
432
|
end
|
440
433
|
end
|
434
|
+
|
435
|
+
describe '.benchmark_map' do
|
436
|
+
before :example do
|
437
|
+
allow(OpenNebula::HostPool).to receive(:new) { host_pool }
|
438
|
+
allow(OpenNebula::Cluster).to receive(:new) { searched_cluster }
|
439
|
+
expect(host_pool).to receive(:info)
|
440
|
+
end
|
441
|
+
|
442
|
+
let(:host_pool) {
|
443
|
+
file = File.read("#{GEM_DIR}/mock/#{host_filename}")
|
444
|
+
xml = OpenNebula::XMLElement.new(OpenNebula::XMLElement.build_xml(file, 'HOST'))
|
445
|
+
[ xml ]
|
446
|
+
}
|
447
|
+
|
448
|
+
let(:searched_cluster) {
|
449
|
+
file = File.read("#{GEM_DIR}/mock/#{cluster_filename}")
|
450
|
+
OpenNebula::XMLElement.new(OpenNebula::XMLElement.build_xml(file, 'CLUSTER'))
|
451
|
+
}
|
452
|
+
|
453
|
+
context 'with correct data on a host with one benchmark value' do
|
454
|
+
let(:host_filename) { 'one_data_accessor_host_01.xml' }
|
455
|
+
let(:expected) { { '1' => { :benchmark_type => 'bench_type_1',
|
456
|
+
:mixins => { 'mixin1' => '36.9' } } } }
|
457
|
+
|
458
|
+
it 'creates correct benchmark_map' do
|
459
|
+
expect(subject.benchmark_map).to eq(expected)
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
context 'with correct data on a host with two benchmark values' do
|
464
|
+
let(:host_filename) { 'one_data_accessor_host_02.xml' }
|
465
|
+
let(:expected) { { '2' => { :benchmark_type => 'bench_type_2',
|
466
|
+
:mixins => { 'mixin1' => '788.6', 'mixin2' => '123.123' } } } }
|
467
|
+
|
468
|
+
it 'creates correct benchmark_map' do
|
469
|
+
expect(subject.benchmark_map).to eq(expected)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
context 'with no data on a host and correct data on host\'s cluster' do
|
474
|
+
before :example do
|
475
|
+
expect(searched_cluster).to receive(:info)
|
476
|
+
end
|
477
|
+
|
478
|
+
let(:host_filename) { 'one_data_accessor_host_03.xml' }
|
479
|
+
let(:cluster_filename) { 'one_data_accessor_cluster_01.xml' }
|
480
|
+
let(:expected) { { '3' => { :benchmark_type => 'bench_type_cluster_1',
|
481
|
+
:mixins => { 'mixin1' => '21.7' } } } }
|
482
|
+
|
483
|
+
it 'creates correct benchmark_map' do
|
484
|
+
expect(subject.benchmark_map).to eq(expected)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context 'with no data on a host and with no data on host\'s cluster' do
|
489
|
+
before :example do
|
490
|
+
expect(searched_cluster).to receive(:info)
|
491
|
+
end
|
492
|
+
|
493
|
+
let(:host_filename) { 'one_data_accessor_host_04.xml' }
|
494
|
+
let(:cluster_filename) { 'one_data_accessor_cluster_02.xml' }
|
495
|
+
let(:expected) { { '4' => {} } }
|
496
|
+
|
497
|
+
it 'creates correct benchmark_map' do
|
498
|
+
expect(subject.benchmark_map).to eq(expected)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
context 'with no data on a host and without host\'s cluster' do
|
503
|
+
let(:host_filename) { 'one_data_accessor_host_05.xml' }
|
504
|
+
let(:expected) { { '5' => {} } }
|
505
|
+
let(:searched_cluster) { nil }
|
506
|
+
|
507
|
+
it 'creates correct benchmark_map' do
|
508
|
+
expect(subject.benchmark_map).to eq(expected)
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
441
512
|
end
|
data/spec/one_worker_spec.rb
CHANGED
@@ -13,9 +13,10 @@ describe OneWorker do
|
|
13
13
|
Settings.output.apel['endpoint'] = 'machine.hogwarts.co.uk'
|
14
14
|
Settings.output.apel['site_name'] = 'Hogwarts'
|
15
15
|
Settings.output.apel['cloud_type'] = 'OpenNebula'
|
16
|
+
Settings.output.apel['cloud_compute_service'] = 'CloudComputeServiceValue'
|
16
17
|
end
|
17
18
|
|
18
|
-
let(:output_type_specific_data) { {'endpoint' => 'machine.hogwarts.co.uk', 'site_name' => 'Hogwarts', 'cloud_type' => 'OpenNebula'} }
|
19
|
+
let(:output_type_specific_data) { {'endpoint' => 'machine.hogwarts.co.uk', 'site_name' => 'Hogwarts', 'cloud_type' => 'OpenNebula', 'cloud_compute_service' => 'CloudComputeServiceValue'} }
|
19
20
|
|
20
21
|
it 'returns data specific for apel output type in form of hash' do
|
21
22
|
expect(subject.output_type_specific_data).to eq(output_type_specific_data)
|
@@ -53,6 +54,13 @@ describe OneWorker do
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
describe '.create_cluster_map' do
|
58
|
+
it 'returns cluster map' do
|
59
|
+
expect(subject).to receive(:create_map).with(OpenNebula::ClusterPool, anything, anything) { 'map' }
|
60
|
+
expect(subject.create_cluster_map(oda)).to eq('map')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
56
64
|
describe '.create_map' do
|
57
65
|
let(:pool_type) { double('pool_type') }
|
58
66
|
let(:mapping) { double('mapping') }
|
@@ -136,8 +144,9 @@ describe OneWorker do
|
|
136
144
|
before :example do
|
137
145
|
Settings.output['output_type'] = 'apel-0.2'
|
138
146
|
Settings.output.apel['endpoint'] = 'machine.hogwarts.co.uk'
|
139
|
-
Settings.output.apel['site_name'] = '
|
147
|
+
Settings.output.apel['site_name'] = 'site-name-from-config'
|
140
148
|
Settings.output.apel['cloud_type'] = 'OpenNebula'
|
149
|
+
Settings.output.apel['cloud_compute_service'] = nil
|
141
150
|
|
142
151
|
allow(vm).to receive(:state_str) { 'DONE' }
|
143
152
|
end
|
@@ -151,8 +160,9 @@ describe OneWorker do
|
|
151
160
|
data = {}
|
152
161
|
|
153
162
|
data['endpoint'] = 'machine.hogwarts.co.uk'
|
154
|
-
data['site_name'] = '
|
163
|
+
data['site_name'] = 'site-name-from-cluster'
|
155
164
|
data['cloud_type'] = 'OpenNebula'
|
165
|
+
data['cloud_compute_service'] = nil
|
156
166
|
|
157
167
|
data['vm_uuid'] = '36551'
|
158
168
|
data['start_time'] = '1383741160'
|
@@ -168,6 +178,7 @@ describe OneWorker do
|
|
168
178
|
data['network_inbound'] = '43557888'
|
169
179
|
data['network_outbound'] = '376832'
|
170
180
|
data['memory'] = '1736960'
|
181
|
+
data['number_of_public_ips'] = 1
|
171
182
|
history = []
|
172
183
|
rec = {}
|
173
184
|
rec['start_time'] = '1383741169'
|
@@ -191,17 +202,24 @@ describe OneWorker do
|
|
191
202
|
data['user_dn'] = '/Dn=FrOm/CN=DN/CN=TeMpLaTe'
|
192
203
|
data['image_name'] = 'https://appdb.egi.eu/store/vo/image/image_name_from_VMCATCHER_EVENT_AD_MPURI_tag/'
|
193
204
|
|
205
|
+
data['benchmark_type'] = nil
|
206
|
+
data['benchmark_value'] = nil
|
207
|
+
|
208
|
+
data['oneacct_export_version'] = ::OneacctExporter::VERSION
|
209
|
+
|
194
210
|
data
|
195
211
|
end
|
196
212
|
|
197
213
|
let(:user_map) { {'120' => '/Dn=FrOm/CN=DN/CN=MaP'} }
|
198
214
|
let(:image_map) { {'31' => 'image_name_from_map'} }
|
215
|
+
let(:cluster_map) { {'100' => 'site-name-from-cluster'}}
|
216
|
+
let(:benchmark_map) { {'123' => nil} }
|
199
217
|
|
200
218
|
context 'with apel specific data' do
|
201
219
|
let(:filename) { 'one_worker_vm_dn01.xml' }
|
202
220
|
|
203
221
|
it 'returns correct vm data with apel specific data' do
|
204
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
222
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
205
223
|
end
|
206
224
|
end
|
207
225
|
|
@@ -219,14 +237,14 @@ describe OneWorker do
|
|
219
237
|
data['host'] = 'on_localhost'
|
220
238
|
|
221
239
|
data.delete 'endpoint'
|
222
|
-
data.delete 'site_name'
|
223
240
|
data.delete 'cloud_type'
|
241
|
+
data.delete 'cloud_compute_service'
|
224
242
|
end
|
225
243
|
|
226
244
|
let(:filename) { 'one_worker_vm_dn01.xml' }
|
227
245
|
|
228
246
|
it 'returns correct vm data with pbs specific data' do
|
229
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
247
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
230
248
|
end
|
231
249
|
end
|
232
250
|
|
@@ -234,7 +252,7 @@ describe OneWorker do
|
|
234
252
|
let(:filename) { 'one_worker_vm_dn01.xml' }
|
235
253
|
|
236
254
|
it 'returns correct vm data with user\'s dn from template' do
|
237
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
255
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
238
256
|
end
|
239
257
|
end
|
240
258
|
|
@@ -246,7 +264,7 @@ describe OneWorker do
|
|
246
264
|
end
|
247
265
|
|
248
266
|
it 'returns correct vm data with user\'s dn from map' do
|
249
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
267
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
250
268
|
end
|
251
269
|
end
|
252
270
|
|
@@ -254,7 +272,7 @@ describe OneWorker do
|
|
254
272
|
let(:filename) { 'one_worker_vm_image_name01.xml' }
|
255
273
|
|
256
274
|
it 'returns correct vm data with image name from VMCATCHER_EVENT_AD_MPURI tag' do
|
257
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
275
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
258
276
|
end
|
259
277
|
end
|
260
278
|
|
@@ -266,7 +284,7 @@ describe OneWorker do
|
|
266
284
|
end
|
267
285
|
|
268
286
|
it 'returns correct vm data with image name from map' do
|
269
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
287
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
270
288
|
end
|
271
289
|
end
|
272
290
|
|
@@ -279,7 +297,7 @@ describe OneWorker do
|
|
279
297
|
end
|
280
298
|
|
281
299
|
it 'returns correct vm data with image name from USER_TEMPLATE/OCCI_COMPUTE_MIXINS tag' do
|
282
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
300
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
283
301
|
end
|
284
302
|
end
|
285
303
|
|
@@ -292,7 +310,7 @@ describe OneWorker do
|
|
292
310
|
end
|
293
311
|
|
294
312
|
it 'returns correct vm data with image name from USER_TEMPLATE/OCCI_MIXIN tag' do
|
295
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
313
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
296
314
|
end
|
297
315
|
end
|
298
316
|
|
@@ -305,7 +323,7 @@ describe OneWorker do
|
|
305
323
|
end
|
306
324
|
|
307
325
|
it 'returns correct vm data with image name from TEMPLATE/OCCI_MIXIN tag' do
|
308
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
326
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
309
327
|
end
|
310
328
|
end
|
311
329
|
|
@@ -317,7 +335,47 @@ describe OneWorker do
|
|
317
335
|
end
|
318
336
|
|
319
337
|
it 'returns correct vm data with image name as image id' do
|
320
|
-
expect(subject.process_vm(vm, user_map, image_map)).to eq(data)
|
338
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context 'without site-name on cluster (APEL)' do
|
343
|
+
let(:filename) { 'one_worker_vm_dn01.xml' }
|
344
|
+
let(:cluster_map) { {} }
|
345
|
+
|
346
|
+
before :example do
|
347
|
+
data['site_name'] = 'site-name-from-config'
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'returns correct vm data with site-name from configuration file' do
|
351
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'without site-name on cluster (NON APEL)' do
|
356
|
+
let(:filename) { 'one_worker_vm_dn01.xml' }
|
357
|
+
let(:cluster_map) { {} }
|
358
|
+
|
359
|
+
before :example do
|
360
|
+
Settings.output['output_type'] = 'pbs-0.1'
|
361
|
+
Settings.output.pbs['realm'] = 'REALM'
|
362
|
+
Settings.output.pbs['queue'] = 'cloud'
|
363
|
+
Settings.output.pbs['scratch_type'] = 'local'
|
364
|
+
Settings.output.pbs['host_identifier'] = 'on_localhost'
|
365
|
+
|
366
|
+
data['realm'] = 'REALM'
|
367
|
+
data['pbs_queue'] = 'cloud'
|
368
|
+
data['scratch_type'] = 'local'
|
369
|
+
data['host'] = 'on_localhost'
|
370
|
+
|
371
|
+
data.delete 'endpoint'
|
372
|
+
data.delete 'cloud_type'
|
373
|
+
data.delete 'cloud_compute_service'
|
374
|
+
data.delete 'site_name'
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'returns correct vm data without any site-name' do
|
378
|
+
expect(subject.process_vm(vm, user_map, image_map, cluster_map, benchmark_map)).to eq(data)
|
321
379
|
end
|
322
380
|
end
|
323
381
|
end
|
@@ -402,19 +460,46 @@ describe OneWorker do
|
|
402
460
|
end
|
403
461
|
end
|
404
462
|
|
463
|
+
describe ".number_of_public_ips" do
|
464
|
+
let(:vm) do
|
465
|
+
xml = File.read("#{GEM_DIR}/mock/#{filename}")
|
466
|
+
OpenNebula::XMLElement.new(OpenNebula::XMLElement.build_xml(xml, 'VM'))
|
467
|
+
end
|
468
|
+
|
469
|
+
context "with multiple NICs (multiple IPs with duplicates) " do
|
470
|
+
let(:filename) { 'one_worker_vm_number_of_public_ips_01.xml' }
|
471
|
+
it "returns the correct number of public IPs" do
|
472
|
+
expect(subject.number_of_public_ips(vm)).to eq 8
|
473
|
+
end
|
474
|
+
end
|
475
|
+
context "with no NICs" do
|
476
|
+
let(:filename) { 'one_worker_vm_number_of_public_ips_02.xml' }
|
477
|
+
it "returns 0, the correct number of IPs" do
|
478
|
+
expect(subject.number_of_public_ips(vm)).to eq 0
|
479
|
+
end
|
480
|
+
end
|
481
|
+
context "with single NIC (multiple IPs with duplicates)" do
|
482
|
+
let(:filename) { 'one_worker_vm_number_of_public_ips_03.xml' }
|
483
|
+
it "returns the correct number of public IPs" do
|
484
|
+
expect(subject.number_of_public_ips(vm)).to eq 8
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
405
489
|
describe '.perform' do
|
406
490
|
before :example do
|
407
491
|
Settings.output['output_type'] = 'unknown'
|
408
492
|
allow(OneDataAccessor).to receive(:new) { oda }
|
409
493
|
allow(subject).to receive(:create_user_map) { 'user_map' }
|
410
494
|
allow(subject).to receive(:create_image_map) { 'image_map' }
|
411
|
-
allow(subject).to receive(:
|
495
|
+
allow(subject).to receive(:create_cluster_map) { 'cluster_map' }
|
496
|
+
allow(oda).to receive(:benchmark_map) { 'benchmark_map' }
|
412
497
|
allow(subject).to receive(:load_vm).with('10', oda).and_return('10')
|
413
498
|
allow(subject).to receive(:load_vm).with('20', oda).and_return('20')
|
414
499
|
allow(subject).to receive(:load_vm).with('30', oda).and_return('30')
|
415
|
-
allow(subject).to receive(:process_vm).with('10', anything, anything).and_return('data_vm1')
|
416
|
-
allow(subject).to receive(:process_vm).with('20', anything, anything).and_return('data_vm2')
|
417
|
-
allow(subject).to receive(:process_vm).with('30', anything, anything).and_return('data_vm3')
|
500
|
+
allow(subject).to receive(:process_vm).with('10', anything, anything, anything, anything).and_return('data_vm1')
|
501
|
+
allow(subject).to receive(:process_vm).with('20', anything, anything, anything, anything).and_return('data_vm2')
|
502
|
+
allow(subject).to receive(:process_vm).with('30', anything, anything, anything, anything).and_return('data_vm3')
|
418
503
|
end
|
419
504
|
|
420
505
|
let(:vms) { '10|20|30' }
|
@@ -498,4 +583,49 @@ describe OneWorker do
|
|
498
583
|
end
|
499
584
|
end
|
500
585
|
end
|
586
|
+
|
587
|
+
describe '.search_benchmark' do
|
588
|
+
let(:vm) do
|
589
|
+
xml = File.read("#{GEM_DIR}/mock/#{filename}")
|
590
|
+
OpenNebula::XMLElement.new(OpenNebula::XMLElement.build_xml(xml, 'VM'))
|
591
|
+
end
|
592
|
+
|
593
|
+
let(:benchmark_map) do
|
594
|
+
values1 = { :benchmark_type => 'bench_type_1', :mixins => { 'mixin1' => '34.12' } }
|
595
|
+
values2 = { :benchmark_type => 'bench_type_2', :mixins => { 'mixin2' => '123.2', 'mixin3' => '129.6' } }
|
596
|
+
values3 = { }
|
597
|
+
|
598
|
+
benchmark_map = { '19' => values1, '11' => values2, '23' => values3 }
|
599
|
+
benchmark_map
|
600
|
+
end
|
601
|
+
|
602
|
+
context 'with empty benchmark_map' do
|
603
|
+
let(:filename) { 'one_worker_vm_search_benchmark_01.xml' }
|
604
|
+
let(:benchmark_map) { {} }
|
605
|
+
let(:expected) { { :benchmark_type => nil, :benchmark_value => nil } }
|
606
|
+
|
607
|
+
it 'returns array with two nil items' do
|
608
|
+
expect(subject.search_benchmark(vm, benchmark_map)).to eq(expected)
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
context 'with no data for the virtual machine in benchmark_map' do
|
613
|
+
let(:filename) { 'one_worker_vm_search_benchmark_02.xml' }
|
614
|
+
let(:expected) { { :benchmark_type => nil, :benchmark_value => nil } }
|
615
|
+
|
616
|
+
it 'returns array with two nil items' do
|
617
|
+
expect(subject.search_benchmark(vm, benchmark_map)).to eq(expected)
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
context 'with correct data in vm and benchmark_map' do
|
622
|
+
let(:filename) { 'one_worker_vm_search_benchmark_01.xml' }
|
623
|
+
let(:expected) { { :benchmark_type => 'bench_type_2', :benchmark_value => '129.6' } }
|
624
|
+
|
625
|
+
it 'returns correct benchmark type and value' do
|
626
|
+
expect(subject.search_benchmark(vm, benchmark_map)).to eq(expected)
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
501
631
|
end
|