vmfloaty 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ describe Service do
16
16
  it 'prompts the user for their password and retrieves a token' do
17
17
  config = { 'user' => 'first.last', 'url' => 'http://default.url' }
18
18
  service = Service.new(MockOptions.new, config)
19
- allow(STDOUT).to receive(:puts).with('Enter your http://default.url service password:')
19
+ allow($stdout).to receive(:puts).with('Enter your http://default.url service password:')
20
20
  allow(Commander::UI).to(receive(:password)
21
21
  .with('Enter your http://default.url service password:', '*')
22
22
  .and_return('hunter2'))
@@ -29,9 +29,9 @@ describe Service do
29
29
  it 'prompts the user for their username and password if the username is unknown' do
30
30
  config = { 'url' => 'http://default.url' }
31
31
  service = Service.new(MockOptions.new({}), config)
32
- allow(STDOUT).to receive(:puts).with 'Enter your http://default.url service username:'
33
- allow(STDOUT).to receive(:puts).with "\n"
34
- allow(STDIN).to receive(:gets).and_return('first.last')
32
+ allow($stdout).to receive(:puts).with 'Enter your http://default.url service username:'
33
+ allow($stdout).to receive(:puts).with "\n"
34
+ allow($stdin).to receive(:gets).and_return('first.last')
35
35
  allow(Commander::UI).to(receive(:password)
36
36
  .with('Enter your http://default.url service password:', '*')
37
37
  .and_return('hunter2'))
@@ -59,16 +59,16 @@ describe Service do
59
59
  it 'reports the status of a token' do
60
60
  config = {
61
61
  'user' => 'first.last',
62
- 'url' => 'http://default.url',
62
+ 'url' => 'http://default.url'
63
63
  }
64
64
  options = MockOptions.new('token' => 'token-value')
65
65
  service = Service.new(options, config)
66
66
  status = {
67
- 'ok' => true,
68
- 'user' => config['user'],
69
- 'created' => '2017-09-22 02:04:18 +0000',
70
- 'last_accessed' => '2017-09-22 02:04:28 +0000',
71
- 'reserved_hosts' => [],
67
+ 'ok' => true,
68
+ 'user' => config['user'],
69
+ 'created' => '2017-09-22 02:04:18 +0000',
70
+ 'last_accessed' => '2017-09-22 02:04:28 +0000',
71
+ 'reserved_hosts' => []
72
72
  }
73
73
  allow(Auth).to(receive(:token_status)
74
74
  .with(nil, config['url'], 'token-value')
@@ -8,14 +8,14 @@ class ServiceStub
8
8
  if os_types.keys[0] == 'abs_host_string'
9
9
  return {
10
10
  os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
11
- 'ok' => true,
11
+ 'ok' => true
12
12
  }
13
13
  end
14
14
 
15
15
  {
16
16
  os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
17
- 'domain' => 'delivery.puppetlabs.net',
18
- 'ok' => true,
17
+ 'domain' => 'delivery.puppetlabs.net',
18
+ 'ok' => true
19
19
  }
20
20
  end
21
21
 
@@ -36,13 +36,14 @@ describe Utils do
36
36
 
37
37
  it 'formats a result from vmpooler into a hash of os to hostnames' do
38
38
  result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
39
- expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
40
- 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'])
39
+ expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
40
+ 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net',
41
+ 'ctnktsd0u11p9tm.delivery.mycompany.net'])
41
42
  end
42
43
 
43
44
  it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do
44
45
  result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body))
45
- expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
46
+ expect(result).to eq('solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
46
47
  'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
47
48
  end
48
49
  end
@@ -50,12 +51,12 @@ describe Utils do
50
51
  describe '#format_host_output' do
51
52
  before :each do
52
53
  @vmpooler_results = {
53
- 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
54
- 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net'],
54
+ 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
55
+ 'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.delivery.mycompany.net', 'ctnktsd0u11p9tm.delivery.mycompany.net']
55
56
  }
56
57
  @nonstandard_results = {
57
- 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
58
- 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'],
58
+ 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
59
+ 'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net']
59
60
  }
60
61
  @vmpooler_output = <<~OUT.chomp
61
62
  - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
@@ -98,23 +99,23 @@ describe Utils do
98
99
  describe '#get_service_config' do
99
100
  before :each do
100
101
  @default_config = {
101
- 'url' => 'http://default.url',
102
- 'user' => 'first.last.default',
103
- 'token' => 'default-token',
102
+ 'url' => 'http://default.url',
103
+ 'user' => 'first.last.default',
104
+ 'token' => 'default-token'
104
105
  }
105
106
  @services_config = {
106
107
  'services' => {
107
108
  'vm' => {
108
- 'url' => 'http://vmpooler.url',
109
- 'user' => 'first.last.vmpooler',
110
- 'token' => 'vmpooler-token',
109
+ 'url' => 'http://vmpooler.url',
110
+ 'user' => 'first.last.vmpooler',
111
+ 'token' => 'vmpooler-token'
111
112
  },
112
113
  'ns' => {
113
- 'url' => 'http://nspooler.url',
114
- 'user' => 'first.last.nspooler',
115
- 'token' => 'nspooler-token',
116
- },
117
- },
114
+ 'url' => 'http://nspooler.url',
115
+ 'user' => 'first.last.nspooler',
116
+ 'token' => 'nspooler-token'
117
+ }
118
+ }
118
119
  }
119
120
  end
120
121
 
@@ -126,26 +127,26 @@ describe Utils do
126
127
 
127
128
  it 'allows selection by configured service key' do
128
129
  config = @default_config.merge @services_config
129
- options = MockOptions.new(:service => 'ns')
130
+ options = MockOptions.new(service: 'ns')
130
131
  expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns']
131
132
  end
132
133
 
133
134
  it 'uses top-level service config values as defaults when configured service values are missing' do
134
135
  config = @default_config.merge @services_config
135
136
  config['services']['vm'].delete 'url'
136
- options = MockOptions.new(:service => 'vm')
137
+ options = MockOptions.new(service: 'vm')
137
138
  expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url'
138
139
  end
139
140
 
140
141
  it "raises an error if passed a service name that hasn't been configured" do
141
142
  config = @default_config.merge @services_config
142
- options = MockOptions.new(:service => 'none')
143
+ options = MockOptions.new(service: 'none')
143
144
  expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError
144
145
  end
145
146
 
146
147
  it 'prioritizes values passed as command line options over configuration options' do
147
148
  config = @default_config
148
- options = MockOptions.new(:url => 'http://alternate.url', :token => 'alternate-token')
149
+ options = MockOptions.new(url: 'http://alternate.url', token: 'alternate-token')
149
150
  expected = config.merge('url' => 'http://alternate.url', 'token' => 'alternate-token')
150
151
  expect(Utils.get_service_config(config, options)).to include expected
151
152
  end
@@ -182,15 +183,15 @@ describe Utils do
182
183
  {
183
184
  'template' => 'ubuntu-1604-x86_64',
184
185
  'lifetime' => 12,
185
- 'running' => 9.66,
186
- 'state' => 'running',
187
- 'ip' => '127.0.0.1',
188
- 'domain' => domain,
186
+ 'running' => 9.66,
187
+ 'state' => 'running',
188
+ 'ip' => '127.0.0.1',
189
+ 'domain' => domain
189
190
  }
190
191
  end
191
192
 
192
193
  it 'outputs fqdn for host' do
193
- expect(STDOUT).to receive(:puts).with(fqdn)
194
+ expect($stdout).to receive(:puts).with(fqdn)
194
195
 
195
196
  subject
196
197
  end
@@ -201,17 +202,17 @@ describe Utils do
201
202
  let(:hostname) { 'sol11-9.delivery.mycompany.net' }
202
203
  let(:host_data) do
203
204
  {
204
- 'fqdn' => hostname,
205
- 'os_triple' => 'solaris-11-sparc',
206
- 'reserved_by_user' => 'first.last',
207
- 'reserved_for_reason' => '',
208
- 'hours_left_on_reservation' => 35.89,
205
+ 'fqdn' => hostname,
206
+ 'os_triple' => 'solaris-11-sparc',
207
+ 'reserved_by_user' => 'first.last',
208
+ 'reserved_for_reason' => '',
209
+ 'hours_left_on_reservation' => 35.89
209
210
  }
210
211
  end
211
212
  let(:fqdn) { hostname } # for nspooler these are the same
212
213
 
213
214
  it 'outputs fqdn for host' do
214
- expect(STDOUT).to receive(:puts).with(fqdn)
215
+ expect($stdout).to receive(:puts).with(fqdn)
215
216
 
216
217
  subject
217
218
  end
@@ -231,19 +232,19 @@ describe Utils do
231
232
  {
232
233
  'hostname' => fqdn,
233
234
  'type' => template,
234
- 'enging' => 'vmpooler',
235
- },
235
+ 'enging' => 'vmpooler'
236
+ }
236
237
  ],
237
238
  'request' => {
238
239
  'job' => {
239
- 'id' => hostname,
240
+ 'id' => hostname
240
241
  }
241
- },
242
+ }
242
243
  }
243
244
  end
244
245
 
245
246
  it 'outputs fqdn for host' do
246
- expect(STDOUT).to receive(:puts).with(fqdn)
247
+ expect($stdout).to receive(:puts).with(fqdn)
247
248
 
248
249
  subject
249
250
  end
@@ -275,10 +276,10 @@ describe Utils do
275
276
  hostname => {
276
277
  'template' => 'ubuntu-1604-x86_64',
277
278
  'lifetime' => 12,
278
- 'running' => 9.66,
279
- 'state' => 'running',
280
- 'ip' => '127.0.0.1',
281
- 'domain' => domain,
279
+ 'running' => 9.66,
280
+ 'state' => 'running',
281
+ 'ip' => '127.0.0.1',
282
+ 'domain' => domain
282
283
  }
283
284
  }
284
285
  end
@@ -286,7 +287,7 @@ describe Utils do
286
287
  let(:default_output) { "- #{fqdn} (running, ubuntu-1604-x86_64, 9.66/12 hours)" }
287
288
 
288
289
  it 'prints output with host fqdn, template and duration info' do
289
- expect(STDOUT).to receive(:puts).with(default_output)
290
+ expect($stdout).to receive(:puts).with(default_output)
290
291
 
291
292
  subject
292
293
  end
@@ -298,14 +299,14 @@ describe Utils do
298
299
  hostname => {
299
300
  'template' => 'redhat-7-x86_64',
300
301
  'lifetime' => 48,
301
- 'running' => 7.67,
302
- 'state' => 'running',
303
- 'tags' => {
302
+ 'running' => 7.67,
303
+ 'state' => 'running',
304
+ 'tags' => {
304
305
  'user' => 'bob',
305
- 'role' => 'agent',
306
+ 'role' => 'agent'
306
307
  },
307
- 'ip' => '127.0.0.1',
308
- 'domain' => domain,
308
+ 'ip' => '127.0.0.1',
309
+ 'domain' => domain
309
310
  }
310
311
  }
311
312
  end
@@ -313,7 +314,7 @@ describe Utils do
313
314
  it 'prints output with host fqdn, template, duration info, and tags' do
314
315
  output = "- #{fqdn} (running, redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
315
316
 
316
- expect(STDOUT).to receive(:puts).with(output)
317
+ expect($stdout).to receive(:puts).with(output)
317
318
 
318
319
  subject
319
320
  end
@@ -323,7 +324,7 @@ describe Utils do
323
324
  let(:print_to_stderr) { true }
324
325
 
325
326
  it 'outputs to stderr instead of stdout' do
326
- expect(STDERR).to receive(:puts).with(default_output)
327
+ expect($stderr).to receive(:puts).with(default_output)
327
328
 
328
329
  subject
329
330
  end
@@ -337,11 +338,11 @@ describe Utils do
337
338
  let(:response_body) do
338
339
  {
339
340
  hostname => {
340
- 'fqdn' => hostname,
341
- 'os_triple' => 'solaris-11-sparc',
342
- 'reserved_by_user' => 'first.last',
343
- 'reserved_for_reason' => '',
344
- 'hours_left_on_reservation' => 35.89,
341
+ 'fqdn' => hostname,
342
+ 'os_triple' => 'solaris-11-sparc',
343
+ 'reserved_by_user' => 'first.last',
344
+ 'reserved_for_reason' => '',
345
+ 'hours_left_on_reservation' => 35.89
345
346
  }
346
347
  }
347
348
  end
@@ -349,7 +350,7 @@ describe Utils do
349
350
  let(:default_output) { "- #{hostname} (solaris-11-sparc, 35.89h remaining)" }
350
351
 
351
352
  it 'prints output with host, template, and time remaining' do
352
- expect(STDOUT).to receive(:puts).with(default_output)
353
+ expect($stdout).to receive(:puts).with(default_output)
353
354
 
354
355
  subject
355
356
  end
@@ -358,11 +359,11 @@ describe Utils do
358
359
  let(:response_body) do
359
360
  {
360
361
  hostname => {
361
- 'fqdn' => hostname,
362
- 'os_triple' => 'solaris-11-sparc',
363
- 'reserved_by_user' => 'first.last',
364
- 'reserved_for_reason' => 'testing',
365
- 'hours_left_on_reservation' => 35.89,
362
+ 'fqdn' => hostname,
363
+ 'os_triple' => 'solaris-11-sparc',
364
+ 'reserved_by_user' => 'first.last',
365
+ 'reserved_for_reason' => 'testing',
366
+ 'hours_left_on_reservation' => 35.89
366
367
  }
367
368
  }
368
369
  end
@@ -370,7 +371,7 @@ describe Utils do
370
371
  it 'prints output with host, template, time remaining, and reason' do
371
372
  output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
372
373
 
373
- expect(STDOUT).to receive(:puts).with(output)
374
+ expect($stdout).to receive(:puts).with(output)
374
375
 
375
376
  subject
376
377
  end
@@ -380,7 +381,7 @@ describe Utils do
380
381
  let(:print_to_stderr) { true }
381
382
 
382
383
  it 'outputs to stderr instead of stdout' do
383
- expect(STDERR).to receive(:puts).with(default_output)
384
+ expect($stderr).to receive(:puts).with(default_output)
384
385
 
385
386
  subject
386
387
  end
@@ -392,7 +393,7 @@ describe Utils do
392
393
 
393
394
  let(:hostname) { '1597952189390' }
394
395
  let(:fqdn) { 'example-noun.delivery.mycompany.net' }
395
- let(:fqdn_hostname) {'example-noun'}
396
+ let(:fqdn_hostname) { 'example-noun' }
396
397
  let(:template) { 'ubuntu-1604-x86_64' }
397
398
 
398
399
  # This seems to be the miminal stub response from ABS for the current output
@@ -404,14 +405,14 @@ describe Utils do
404
405
  {
405
406
  'hostname' => fqdn,
406
407
  'type' => template,
407
- 'engine' => 'vmpooler',
408
- },
408
+ 'engine' => 'vmpooler'
409
+ }
409
410
  ],
410
411
  'request' => {
411
412
  'job' => {
412
- 'id' => hostname,
413
+ 'id' => hostname
413
414
  }
414
- },
415
+ }
415
416
  }
416
417
  }
417
418
  end
@@ -420,58 +421,58 @@ describe Utils do
420
421
  let(:domain) { 'delivery.mycompany.net' }
421
422
  let(:response_body_vmpooler) do
422
423
  {
423
- fqdn_hostname => {
424
- 'template' => template,
425
- 'lifetime' => 48,
426
- 'running' => 7.67,
427
- 'state' => 'running',
428
- 'tags' => {
429
- 'user' => 'bob',
430
- 'role' => 'agent',
431
- },
432
- 'ip' => '127.0.0.1',
433
- 'domain' => domain,
434
- }
424
+ fqdn_hostname => {
425
+ 'template' => template,
426
+ 'lifetime' => 48,
427
+ 'running' => 7.67,
428
+ 'state' => 'running',
429
+ 'tags' => {
430
+ 'user' => 'bob',
431
+ 'role' => 'agent'
432
+ },
433
+ 'ip' => '127.0.0.1',
434
+ 'domain' => domain
435
+ }
435
436
  }
436
437
  end
437
438
 
438
439
  before(:each) do
439
440
  allow(Utils).to receive(:get_vmpooler_service_config).and_return({
440
- 'url' => 'http://vmpooler.example.com',
441
- 'token' => 'krypto-knight'
442
- })
441
+ 'url' => 'http://vmpooler.example.com',
442
+ 'token' => 'krypto-knight'
443
+ })
443
444
  allow(service).to receive(:query)
444
- .with(anything, fqdn_hostname)
445
- .and_return(response_body_vmpooler)
445
+ .with(anything, fqdn_hostname)
446
+ .and_return(response_body_vmpooler)
446
447
  end
447
448
 
448
449
  let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
449
450
  let(:default_output_second_line) { " - #{fqdn} (#{template})" }
450
451
 
451
452
  it 'prints output with job id, host, and template' do
452
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
453
- expect(STDOUT).to receive(:puts).with(default_output_second_line)
453
+ expect($stdout).to receive(:puts).with(default_output_first_line)
454
+ expect($stdout).to receive(:puts).with(default_output_second_line)
454
455
 
455
456
  subject
456
457
  end
457
458
 
458
459
  it 'prints more information when vmpooler_fallback is set output with job id, host, template, lifetime, user and role' do
459
- fallback = {'vmpooler_fallback' => 'vmpooler'}
460
+ fallback = { 'vmpooler_fallback' => 'vmpooler' }
460
461
  service.config.merge! fallback
461
- default_output_second_line=" - #{fqdn} (running, #{template}, 7.67/48 hours, user: bob, role: agent)"
462
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
463
- expect(STDOUT).to receive(:puts).with(default_output_second_line)
462
+ default_output_second_line = " - #{fqdn} (running, #{template}, 7.67/48 hours, user: bob, role: agent)"
463
+ expect($stdout).to receive(:puts).with(default_output_first_line)
464
+ expect($stdout).to receive(:puts).with(default_output_second_line)
464
465
 
465
466
  subject
466
467
  end
467
468
 
468
469
  it 'prints in red when destroyed' do
469
- fallback = {'vmpooler_fallback' => 'vmpooler'}
470
+ fallback = { 'vmpooler_fallback' => 'vmpooler' }
470
471
  service.config.merge! fallback
471
- response_body_vmpooler[fqdn_hostname]['state'] = "destroyed"
472
- default_output_second_line_red=" - #{fqdn} (destroyed, #{template}, 7.67/48 hours, user: bob, role: agent)".red
473
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
474
- expect(STDOUT).to receive(:puts).with(default_output_second_line_red)
472
+ response_body_vmpooler[fqdn_hostname]['state'] = 'destroyed'
473
+ default_output_second_line_red = " - #{fqdn} (destroyed, #{template}, 7.67/48 hours, user: bob, role: agent)".red
474
+ expect($stdout).to receive(:puts).with(default_output_first_line)
475
+ expect($stdout).to receive(:puts).with(default_output_second_line_red)
475
476
 
476
477
  subject
477
478
  end
@@ -480,8 +481,8 @@ describe Utils do
480
481
  let(:print_to_stderr) { true }
481
482
 
482
483
  it 'outputs to stderr instead of stdout' do
483
- expect(STDERR).to receive(:puts).with(default_output_first_line)
484
- expect(STDERR).to receive(:puts).with(default_output_second_line)
484
+ expect($stderr).to receive(:puts).with(default_output_first_line)
485
+ expect($stderr).to receive(:puts).with(default_output_second_line)
485
486
 
486
487
  subject
487
488
  end
@@ -494,34 +495,34 @@ describe Utils do
494
495
  let(:hostname) { '1597952189390' }
495
496
  let(:fqdn) { 'this-noun.delivery.mycompany.net' }
496
497
  let(:fqdn_ns) { 'that-noun.delivery.mycompany.net' }
497
- let(:fqdn_hostname) {'this-noun'}
498
- let(:fqdn_ns_hostname) {'that-noun'}
498
+ let(:fqdn_hostname) { 'this-noun' }
499
+ let(:fqdn_ns_hostname) { 'that-noun' }
499
500
  let(:template) { 'ubuntu-1604-x86_64' }
500
501
  let(:template_ns) { 'solaris-10-sparc' }
501
502
 
502
503
  # This seems to be the miminal stub response from ABS for the current output
503
504
  let(:response_body) do
504
505
  {
505
- hostname => {
506
- 'state' => 'allocated',
507
- 'allocated_resources' => [
508
- {
509
- 'hostname' => fqdn,
510
- 'type' => template,
511
- 'engine' => 'vmpooler',
512
- },
513
- {
514
- 'hostname' => fqdn_ns,
515
- 'type' => template_ns,
516
- 'engine' => 'nspooler',
517
- },
518
- ],
519
- 'request' => {
520
- 'job' => {
521
- 'id' => hostname,
522
- }
523
- },
506
+ hostname => {
507
+ 'state' => 'allocated',
508
+ 'allocated_resources' => [
509
+ {
510
+ 'hostname' => fqdn,
511
+ 'type' => template,
512
+ 'engine' => 'vmpooler'
513
+ },
514
+ {
515
+ 'hostname' => fqdn_ns,
516
+ 'type' => template_ns,
517
+ 'engine' => 'nspooler'
518
+ }
519
+ ],
520
+ 'request' => {
521
+ 'job' => {
522
+ 'id' => hostname
523
+ }
524
524
  }
525
+ }
525
526
  }
526
527
  end
527
528
 
@@ -529,29 +530,29 @@ describe Utils do
529
530
  let(:domain) { 'delivery.mycompany.net' }
530
531
  let(:response_body_vmpooler) do
531
532
  {
532
- fqdn_hostname => {
533
- 'template' => template,
534
- 'lifetime' => 48,
535
- 'running' => 7.67,
536
- 'state' => 'running',
537
- 'tags' => {
538
- 'user' => 'bob',
539
- 'role' => 'agent',
540
- },
541
- 'ip' => '127.0.0.1',
542
- 'domain' => domain,
543
- }
533
+ fqdn_hostname => {
534
+ 'template' => template,
535
+ 'lifetime' => 48,
536
+ 'running' => 7.67,
537
+ 'state' => 'running',
538
+ 'tags' => {
539
+ 'user' => 'bob',
540
+ 'role' => 'agent'
541
+ },
542
+ 'ip' => '127.0.0.1',
543
+ 'domain' => domain
544
+ }
544
545
  }
545
546
  end
546
547
 
547
548
  before(:each) do
548
549
  allow(Utils).to receive(:get_vmpooler_service_config).and_return({
549
- 'url' => 'http://vmpooler.example.com',
550
- 'token' => 'krypto-knight'
550
+ 'url' => 'http://vmpooler.example.com',
551
+ 'token' => 'krypto-knight'
551
552
  })
552
553
  allow(service).to receive(:query)
553
- .with(anything, fqdn_hostname)
554
- .and_return(response_body_vmpooler)
554
+ .with(anything, fqdn_hostname)
555
+ .and_return(response_body_vmpooler)
555
556
  end
556
557
 
557
558
  let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
@@ -559,9 +560,9 @@ describe Utils do
559
560
  let(:default_output_third_line) { " - #{fqdn_ns} (#{template_ns})" }
560
561
 
561
562
  it 'prints output with job id, host, and template' do
562
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
563
- expect(STDOUT).to receive(:puts).with(default_output_second_line)
564
- expect(STDOUT).to receive(:puts).with(default_output_third_line)
563
+ expect($stdout).to receive(:puts).with(default_output_first_line)
564
+ expect($stdout).to receive(:puts).with(default_output_second_line)
565
+ expect($stdout).to receive(:puts).with(default_output_third_line)
565
566
 
566
567
  subject
567
568
  end
@@ -570,9 +571,9 @@ describe Utils do
570
571
  let(:print_to_stderr) { true }
571
572
 
572
573
  it 'outputs to stderr instead of stdout' do
573
- expect(STDERR).to receive(:puts).with(default_output_first_line)
574
- expect(STDERR).to receive(:puts).with(default_output_second_line)
575
- expect(STDERR).to receive(:puts).with(default_output_third_line)
574
+ expect($stderr).to receive(:puts).with(default_output_first_line)
575
+ expect($stderr).to receive(:puts).with(default_output_second_line)
576
+ expect($stderr).to receive(:puts).with(default_output_third_line)
576
577
 
577
578
  subject
578
579
  end
@@ -586,54 +587,59 @@ describe Utils do
586
587
  config = {
587
588
  'user' => 'foo',
588
589
  'services' => {
589
- 'myabs' => {
590
- 'url' => 'http://abs.com',
591
- 'token' => 'krypto-night',
592
- 'type' => 'abs'
593
- }
590
+ 'myabs' => {
591
+ 'url' => 'http://abs.com',
592
+ 'token' => 'krypto-night',
593
+ 'type' => 'abs'
594
+ }
594
595
  }
595
596
  }
596
597
  allow(Conf).to receive(:read_config).and_return(config)
597
- expect{Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])}.to raise_error(ArgumentError)
598
+ expect do
599
+ Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])
600
+ end.to raise_error(ArgumentError)
598
601
  end
599
602
  it 'returns an error if the vmpooler_fallback is setup but cannot be found' do
600
603
  config = {
601
604
  'user' => 'foo',
602
605
  'services' => {
603
606
  'myabs' => {
604
- 'url' => 'http://abs.com',
605
- 'token' => 'krypto-night',
606
- 'type' => 'abs',
607
- 'vmpooler_fallback' => 'myvmpooler'
607
+ 'url' => 'http://abs.com',
608
+ 'token' => 'krypto-night',
609
+ 'type' => 'abs',
610
+ 'vmpooler_fallback' => 'myvmpooler'
608
611
  }
609
612
  }
610
613
  }
611
614
  allow(Conf).to receive(:read_config).and_return(config)
612
- expect{Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])}.to raise_error(ArgumentError, /myvmpooler/)
615
+ expect do
616
+ Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])
617
+ end.to raise_error(ArgumentError,
618
+ /myvmpooler/)
613
619
  end
614
620
  it 'returns the vmpooler_fallback config' do
615
621
  config = {
616
622
  'user' => 'foo',
617
623
  'services' => {
618
624
  'myabs' => {
619
- 'url' => 'http://abs.com',
620
- 'token' => 'krypto-night',
621
- 'type' => 'abs',
622
- 'vmpooler_fallback' => 'myvmpooler'
625
+ 'url' => 'http://abs.com',
626
+ 'token' => 'krypto-night',
627
+ 'type' => 'abs',
628
+ 'vmpooler_fallback' => 'myvmpooler'
623
629
  },
624
630
  'myvmpooler' => {
625
- 'url' => 'http://vmpooler.com',
626
- 'token' => 'krypto-knight'
631
+ 'url' => 'http://vmpooler.com',
632
+ 'token' => 'krypto-knight'
627
633
  }
628
634
  }
629
635
  }
630
636
  allow(Conf).to receive(:read_config).and_return(config)
631
637
  expect(Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])).to include({
632
- 'url' => 'http://vmpooler.com',
633
- 'token' => 'krypto-knight',
634
- 'user' => 'foo',
635
- 'type' => 'vmpooler'
636
- })
638
+ 'url' => 'http://vmpooler.com',
639
+ 'token' => 'krypto-knight',
640
+ 'user' => 'foo',
641
+ 'type' => 'vmpooler'
642
+ })
637
643
  end
638
644
  end
639
645
  end