vmfloaty 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ describe Pooler do
15
15
 
16
16
  it 'returns a hash with operating systems from the pooler' do
17
17
  stub_request(:get, "#{@vmpooler_url}/vm")
18
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
18
+ .to_return(status: 200, body: @list_response_body, headers: {})
19
19
 
20
20
  list = Pooler.list(false, @vmpooler_url, nil)
21
21
  expect(list).to be_an_instance_of Array
@@ -23,7 +23,7 @@ describe Pooler do
23
23
 
24
24
  it 'filters operating systems based on the filter param' do
25
25
  stub_request(:get, "#{@vmpooler_url}/vm")
26
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
26
+ .to_return(status: 200, body: @list_response_body, headers: {})
27
27
 
28
28
  list = Pooler.list(false, @vmpooler_url, 'deb')
29
29
  expect(list).to be_an_instance_of Array
@@ -32,7 +32,7 @@ describe Pooler do
32
32
 
33
33
  it 'returns nothing if the filter does not match' do
34
34
  stub_request(:get, "#{@vmpooler_url}/vm")
35
- .to_return(:status => 200, :body => @list_response_body, :headers => {})
35
+ .to_return(status: 200, body: @list_response_body, headers: {})
36
36
 
37
37
  list = Pooler.list(false, @vmpooler_url, 'windows')
38
38
  expect(list).to be_an_instance_of Array
@@ -48,8 +48,8 @@ describe Pooler do
48
48
 
49
49
  it 'raises an AuthError if the token is invalid' do
50
50
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
51
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
52
- .to_return(:status => 401, :body => '{"ok":false}', :headers => {})
51
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
52
+ .to_return(status: 401, body: '{"ok":false}', headers: {})
53
53
 
54
54
  vm_hash = {}
55
55
  vm_hash['debian-7-i386'] = 1
@@ -58,8 +58,8 @@ describe Pooler do
58
58
 
59
59
  it 'retrieves a single vm with a token' do
60
60
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
61
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
62
- .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
61
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
62
+ .to_return(status: 200, body: @retrieve_response_body_single, headers: {})
63
63
 
64
64
  vm_hash = {}
65
65
  vm_hash['debian-7-i386'] = 1
@@ -71,8 +71,8 @@ describe Pooler do
71
71
 
72
72
  it 'retrieves a multiple vms with a token' do
73
73
  stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64")
74
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
75
- .to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {})
74
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
75
+ .to_return(status: 200, body: @retrieve_response_body_double, headers: {})
76
76
 
77
77
  vm_hash = {}
78
78
  vm_hash['debian-7-i386'] = 2
@@ -89,11 +89,11 @@ describe Pooler do
89
89
  let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
90
90
  it 'retreives the vm with a token' do
91
91
  stub_request(:post, "#{@vmpooler_url}/ondemandvm/debian-7-i386")
92
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
93
- .to_return(:status => 200, :body => ondemand_response, :headers => {})
92
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
93
+ .to_return(status: 200, body: ondemand_response, headers: {})
94
94
 
95
95
  stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
96
- .to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
96
+ .to_return(status: 200, body: @retrieve_response_body_single, headers: {})
97
97
 
98
98
  vm_hash = {}
99
99
  vm_hash['debian-7-i386'] = 1
@@ -117,11 +117,11 @@ describe Pooler do
117
117
  end
118
118
 
119
119
  it 'modifies the TTL of a vm' do
120
- modify_hash = { :lifetime => 12 }
120
+ modify_hash = { lifetime: 12 }
121
121
  stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
122
- .with(:body => { '{"lifetime":12}' => true },
123
- :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'X-Auth-Token' => 'mytokenfile' })
124
- .to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
122
+ .with(body: { '{"lifetime":12}' => nil },
123
+ headers: get_headers(content_type: 'application/x-www-form-urlencoded', token: 'mytokenfile'))
124
+ .to_return(status: 200, body: @modify_response_body_success, headers: {})
125
125
 
126
126
  modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
127
127
  expect(modify_req['ok']).to be true
@@ -136,8 +136,8 @@ describe Pooler do
136
136
 
137
137
  it 'deletes a specified vm' do
138
138
  stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
139
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
140
- .to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
139
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
140
+ .to_return(status: 200, body: @delete_response_body_success, headers: {})
141
141
 
142
142
  expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response
143
143
  end
@@ -155,7 +155,7 @@ describe Pooler do
155
155
 
156
156
  it 'prints the status' do
157
157
  stub_request(:get, "#{@vmpooler_url}/status")
158
- .to_return(:status => 200, :body => @status_response_body, :headers => {})
158
+ .to_return(status: 200, body: @status_response_body, headers: {})
159
159
 
160
160
  status = Pooler.status(false, @vmpooler_url)
161
161
  expect(status).to be_an_instance_of Hash
@@ -178,7 +178,7 @@ describe Pooler do
178
178
 
179
179
  it 'makes a query about a vm' do
180
180
  stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
181
- .to_return(:status => 200, :body => @query_response_body, :headers => {})
181
+ .to_return(status: 200, body: @query_response_body, headers: {})
182
182
 
183
183
  query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6')
184
184
  expect(query_req).to be_an_instance_of Hash
@@ -192,8 +192,8 @@ describe Pooler do
192
192
 
193
193
  it 'makes a snapshot for a single vm' do
194
194
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot")
195
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
196
- .to_return(:status => 200, :body => @snapshot_response_body, :headers => {})
195
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
196
+ .to_return(status: 200, body: @snapshot_response_body, headers: {})
197
197
 
198
198
  snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')
199
199
  expect(snapshot_req['ok']).to be true
@@ -207,15 +207,18 @@ describe Pooler do
207
207
 
208
208
  it 'makes a request to revert a vm from a snapshot' do
209
209
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve")
210
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' })
211
- .to_return(:status => 200, :body => @revert_response_body, :headers => {})
210
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' })
211
+ .to_return(status: 200, body: @revert_response_body, headers: {})
212
212
 
213
213
  revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
214
214
  expect(revert_req['ok']).to be true
215
215
  end
216
216
 
217
217
  it "doesn't make a request to revert a vm if snapshot is not provided" do
218
- expect { Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
218
+ expect do
219
+ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile',
220
+ nil)
221
+ end.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
219
222
  end
220
223
 
221
224
  it 'raises a TokenError if no token was provided' do
@@ -231,7 +234,7 @@ describe Pooler do
231
234
 
232
235
  it 'makes a request to extend disk space of a vm' do
233
236
  stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12")
234
- .with(:headers => { 'X-Auth-Token' => 'mytokenfile' }). to_return(:status => 200, :body => @disk_response_body_success, :headers => {})
237
+ .with(headers: { 'X-Auth-Token' => 'mytokenfile' }).to_return(status: 200, body: @disk_response_body_success, headers: {})
235
238
 
236
239
  disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12)
237
240
  expect(disk_req['ok']).to be true
@@ -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
 
@@ -5,6 +5,11 @@ require 'json'
5
5
  require 'commander/command'
6
6
  require_relative '../../lib/vmfloaty/utils'
7
7
 
8
+ # allow changing config in service for tests
9
+ class Service
10
+ attr_writer :config
11
+ end
12
+
8
13
  describe Utils do
9
14
  describe '#standardize_hostnames' do
10
15
  before :each do
@@ -31,13 +36,14 @@ describe Utils do
31
36
 
32
37
  it 'formats a result from vmpooler into a hash of os to hostnames' do
33
38
  result = Utils.standardize_hostnames(JSON.parse(@vmpooler_response_body))
34
- expect(result).to eq('centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
35
- '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'])
36
42
  end
37
43
 
38
44
  it 'formats a result from the nonstandard pooler into a hash of os to hostnames' do
39
45
  result = Utils.standardize_hostnames(JSON.parse(@nonstandard_response_body))
40
- 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'],
41
47
  'ubuntu-16.04-power8' => ['power8-ubuntu16.04-6.delivery.mycompany.net'])
42
48
  end
43
49
  end
@@ -45,12 +51,12 @@ describe Utils do
45
51
  describe '#format_host_output' do
46
52
  before :each do
47
53
  @vmpooler_results = {
48
- 'centos-7-x86_64' => ['dlgietfmgeegry2.delivery.mycompany.net'],
49
- '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']
50
56
  }
51
57
  @nonstandard_results = {
52
- 'solaris-10-sparc' => ['sol10-10.delivery.mycompany.net', 'sol10-11.delivery.mycompany.net'],
53
- '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']
54
60
  }
55
61
  @vmpooler_output = <<~OUT.chomp
56
62
  - dlgietfmgeegry2.delivery.mycompany.net (centos-7-x86_64)
@@ -93,23 +99,23 @@ describe Utils do
93
99
  describe '#get_service_config' do
94
100
  before :each do
95
101
  @default_config = {
96
- 'url' => 'http://default.url',
97
- 'user' => 'first.last.default',
98
- 'token' => 'default-token',
102
+ 'url' => 'http://default.url',
103
+ 'user' => 'first.last.default',
104
+ 'token' => 'default-token'
99
105
  }
100
106
  @services_config = {
101
107
  'services' => {
102
108
  'vm' => {
103
- 'url' => 'http://vmpooler.url',
104
- 'user' => 'first.last.vmpooler',
105
- 'token' => 'vmpooler-token',
109
+ 'url' => 'http://vmpooler.url',
110
+ 'user' => 'first.last.vmpooler',
111
+ 'token' => 'vmpooler-token'
106
112
  },
107
113
  'ns' => {
108
- 'url' => 'http://nspooler.url',
109
- 'user' => 'first.last.nspooler',
110
- 'token' => 'nspooler-token',
111
- },
112
- },
114
+ 'url' => 'http://nspooler.url',
115
+ 'user' => 'first.last.nspooler',
116
+ 'token' => 'nspooler-token'
117
+ }
118
+ }
113
119
  }
114
120
  end
115
121
 
@@ -121,26 +127,26 @@ describe Utils do
121
127
 
122
128
  it 'allows selection by configured service key' do
123
129
  config = @default_config.merge @services_config
124
- options = MockOptions.new(:service => 'ns')
130
+ options = MockOptions.new(service: 'ns')
125
131
  expect(Utils.get_service_config(config, options)).to include @services_config['services']['ns']
126
132
  end
127
133
 
128
134
  it 'uses top-level service config values as defaults when configured service values are missing' do
129
135
  config = @default_config.merge @services_config
130
136
  config['services']['vm'].delete 'url'
131
- options = MockOptions.new(:service => 'vm')
137
+ options = MockOptions.new(service: 'vm')
132
138
  expect(Utils.get_service_config(config, options)['url']).to eq 'http://default.url'
133
139
  end
134
140
 
135
141
  it "raises an error if passed a service name that hasn't been configured" do
136
142
  config = @default_config.merge @services_config
137
- options = MockOptions.new(:service => 'none')
143
+ options = MockOptions.new(service: 'none')
138
144
  expect { Utils.get_service_config(config, options) }.to raise_error ArgumentError
139
145
  end
140
146
 
141
147
  it 'prioritizes values passed as command line options over configuration options' do
142
148
  config = @default_config
143
- options = MockOptions.new(:url => 'http://alternate.url', :token => 'alternate-token')
149
+ options = MockOptions.new(url: 'http://alternate.url', token: 'alternate-token')
144
150
  expected = config.merge('url' => 'http://alternate.url', 'token' => 'alternate-token')
145
151
  expect(Utils.get_service_config(config, options)).to include expected
146
152
  end
@@ -177,15 +183,15 @@ describe Utils do
177
183
  {
178
184
  'template' => 'ubuntu-1604-x86_64',
179
185
  'lifetime' => 12,
180
- 'running' => 9.66,
181
- 'state' => 'running',
182
- 'ip' => '127.0.0.1',
183
- 'domain' => domain,
186
+ 'running' => 9.66,
187
+ 'state' => 'running',
188
+ 'ip' => '127.0.0.1',
189
+ 'domain' => domain
184
190
  }
185
191
  end
186
192
 
187
193
  it 'outputs fqdn for host' do
188
- expect(STDOUT).to receive(:puts).with(fqdn)
194
+ expect($stdout).to receive(:puts).with(fqdn)
189
195
 
190
196
  subject
191
197
  end
@@ -196,17 +202,17 @@ describe Utils do
196
202
  let(:hostname) { 'sol11-9.delivery.mycompany.net' }
197
203
  let(:host_data) do
198
204
  {
199
- 'fqdn' => hostname,
200
- 'os_triple' => 'solaris-11-sparc',
201
- 'reserved_by_user' => 'first.last',
202
- 'reserved_for_reason' => '',
203
- '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
204
210
  }
205
211
  end
206
212
  let(:fqdn) { hostname } # for nspooler these are the same
207
213
 
208
214
  it 'outputs fqdn for host' do
209
- expect(STDOUT).to receive(:puts).with(fqdn)
215
+ expect($stdout).to receive(:puts).with(fqdn)
210
216
 
211
217
  subject
212
218
  end
@@ -226,19 +232,19 @@ describe Utils do
226
232
  {
227
233
  'hostname' => fqdn,
228
234
  'type' => template,
229
- 'enging' => 'vmpooler',
230
- },
235
+ 'enging' => 'vmpooler'
236
+ }
231
237
  ],
232
238
  'request' => {
233
239
  'job' => {
234
- 'id' => hostname,
240
+ 'id' => hostname
235
241
  }
236
- },
242
+ }
237
243
  }
238
244
  end
239
245
 
240
246
  it 'outputs fqdn for host' do
241
- expect(STDOUT).to receive(:puts).with(fqdn)
247
+ expect($stdout).to receive(:puts).with(fqdn)
242
248
 
243
249
  subject
244
250
  end
@@ -270,18 +276,18 @@ describe Utils do
270
276
  hostname => {
271
277
  'template' => 'ubuntu-1604-x86_64',
272
278
  'lifetime' => 12,
273
- 'running' => 9.66,
274
- 'state' => 'running',
275
- 'ip' => '127.0.0.1',
276
- 'domain' => domain,
279
+ 'running' => 9.66,
280
+ 'state' => 'running',
281
+ 'ip' => '127.0.0.1',
282
+ 'domain' => domain
277
283
  }
278
284
  }
279
285
  end
280
286
 
281
- let(:default_output) { "- #{fqdn} (ubuntu-1604-x86_64, 9.66/12 hours)" }
287
+ let(:default_output) { "- #{fqdn} (running, ubuntu-1604-x86_64, 9.66/12 hours)" }
282
288
 
283
289
  it 'prints output with host fqdn, template and duration info' do
284
- expect(STDOUT).to receive(:puts).with(default_output)
290
+ expect($stdout).to receive(:puts).with(default_output)
285
291
 
286
292
  subject
287
293
  end
@@ -293,22 +299,22 @@ describe Utils do
293
299
  hostname => {
294
300
  'template' => 'redhat-7-x86_64',
295
301
  'lifetime' => 48,
296
- 'running' => 7.67,
297
- 'state' => 'running',
298
- 'tags' => {
302
+ 'running' => 7.67,
303
+ 'state' => 'running',
304
+ 'tags' => {
299
305
  'user' => 'bob',
300
- 'role' => 'agent',
306
+ 'role' => 'agent'
301
307
  },
302
- 'ip' => '127.0.0.1',
303
- 'domain' => domain,
308
+ 'ip' => '127.0.0.1',
309
+ 'domain' => domain
304
310
  }
305
311
  }
306
312
  end
307
313
 
308
314
  it 'prints output with host fqdn, template, duration info, and tags' do
309
- output = "- #{fqdn} (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
315
+ output = "- #{fqdn} (running, redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
310
316
 
311
- expect(STDOUT).to receive(:puts).with(output)
317
+ expect($stdout).to receive(:puts).with(output)
312
318
 
313
319
  subject
314
320
  end
@@ -318,7 +324,7 @@ describe Utils do
318
324
  let(:print_to_stderr) { true }
319
325
 
320
326
  it 'outputs to stderr instead of stdout' do
321
- expect(STDERR).to receive(:puts).with(default_output)
327
+ expect($stderr).to receive(:puts).with(default_output)
322
328
 
323
329
  subject
324
330
  end
@@ -332,11 +338,11 @@ describe Utils do
332
338
  let(:response_body) do
333
339
  {
334
340
  hostname => {
335
- 'fqdn' => hostname,
336
- 'os_triple' => 'solaris-11-sparc',
337
- 'reserved_by_user' => 'first.last',
338
- 'reserved_for_reason' => '',
339
- '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
340
346
  }
341
347
  }
342
348
  end
@@ -344,7 +350,7 @@ describe Utils do
344
350
  let(:default_output) { "- #{hostname} (solaris-11-sparc, 35.89h remaining)" }
345
351
 
346
352
  it 'prints output with host, template, and time remaining' do
347
- expect(STDOUT).to receive(:puts).with(default_output)
353
+ expect($stdout).to receive(:puts).with(default_output)
348
354
 
349
355
  subject
350
356
  end
@@ -353,11 +359,11 @@ describe Utils do
353
359
  let(:response_body) do
354
360
  {
355
361
  hostname => {
356
- 'fqdn' => hostname,
357
- 'os_triple' => 'solaris-11-sparc',
358
- 'reserved_by_user' => 'first.last',
359
- 'reserved_for_reason' => 'testing',
360
- '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
361
367
  }
362
368
  }
363
369
  end
@@ -365,7 +371,7 @@ describe Utils do
365
371
  it 'prints output with host, template, time remaining, and reason' do
366
372
  output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
367
373
 
368
- expect(STDOUT).to receive(:puts).with(output)
374
+ expect($stdout).to receive(:puts).with(output)
369
375
 
370
376
  subject
371
377
  end
@@ -375,7 +381,7 @@ describe Utils do
375
381
  let(:print_to_stderr) { true }
376
382
 
377
383
  it 'outputs to stderr instead of stdout' do
378
- expect(STDERR).to receive(:puts).with(default_output)
384
+ expect($stderr).to receive(:puts).with(default_output)
379
385
 
380
386
  subject
381
387
  end
@@ -387,7 +393,7 @@ describe Utils do
387
393
 
388
394
  let(:hostname) { '1597952189390' }
389
395
  let(:fqdn) { 'example-noun.delivery.mycompany.net' }
390
- let(:fqdn_hostname) {'example-noun'}
396
+ let(:fqdn_hostname) { 'example-noun' }
391
397
  let(:template) { 'ubuntu-1604-x86_64' }
392
398
 
393
399
  # This seems to be the miminal stub response from ABS for the current output
@@ -399,14 +405,14 @@ describe Utils do
399
405
  {
400
406
  'hostname' => fqdn,
401
407
  'type' => template,
402
- 'engine' => 'vmpooler',
403
- },
408
+ 'engine' => 'vmpooler'
409
+ }
404
410
  ],
405
411
  'request' => {
406
412
  'job' => {
407
- 'id' => hostname,
413
+ 'id' => hostname
408
414
  }
409
- },
415
+ }
410
416
  }
411
417
  }
412
418
  end
@@ -415,37 +421,58 @@ describe Utils do
415
421
  let(:domain) { 'delivery.mycompany.net' }
416
422
  let(:response_body_vmpooler) do
417
423
  {
418
- fqdn_hostname => {
419
- 'template' => template,
420
- 'lifetime' => 48,
421
- 'running' => 7.67,
422
- 'state' => 'running',
423
- 'tags' => {
424
- 'user' => 'bob',
425
- 'role' => 'agent',
426
- },
427
- 'ip' => '127.0.0.1',
428
- 'domain' => domain,
429
- }
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
+ }
430
436
  }
431
437
  end
432
438
 
433
439
  before(:each) do
434
440
  allow(Utils).to receive(:get_vmpooler_service_config).and_return({
435
- 'url' => 'http://vmpooler.example.com',
436
- 'token' => 'krypto-knight'
437
- })
441
+ 'url' => 'http://vmpooler.example.com',
442
+ 'token' => 'krypto-knight'
443
+ })
438
444
  allow(service).to receive(:query)
439
- .with(anything, fqdn_hostname)
440
- .and_return(response_body_vmpooler)
445
+ .with(anything, fqdn_hostname)
446
+ .and_return(response_body_vmpooler)
441
447
  end
442
448
 
443
449
  let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
444
- let(:default_output_second_line) { " - #{fqdn} (#{template}, 7.67/48 hours, user: bob, role: agent)" }
450
+ let(:default_output_second_line) { " - #{fqdn} (#{template})" }
445
451
 
446
452
  it 'prints output with job id, host, and template' do
447
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
448
- 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)
455
+
456
+ subject
457
+ end
458
+
459
+ it 'prints more information when vmpooler_fallback is set output with job id, host, template, lifetime, user and role' do
460
+ fallback = { 'vmpooler_fallback' => 'vmpooler' }
461
+ service.config.merge! fallback
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)
465
+
466
+ subject
467
+ end
468
+
469
+ it 'prints in red when destroyed' do
470
+ fallback = { 'vmpooler_fallback' => 'vmpooler' }
471
+ service.config.merge! fallback
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)
449
476
 
450
477
  subject
451
478
  end
@@ -454,8 +481,8 @@ describe Utils do
454
481
  let(:print_to_stderr) { true }
455
482
 
456
483
  it 'outputs to stderr instead of stdout' do
457
- expect(STDERR).to receive(:puts).with(default_output_first_line)
458
- 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)
459
486
 
460
487
  subject
461
488
  end
@@ -468,34 +495,34 @@ describe Utils do
468
495
  let(:hostname) { '1597952189390' }
469
496
  let(:fqdn) { 'this-noun.delivery.mycompany.net' }
470
497
  let(:fqdn_ns) { 'that-noun.delivery.mycompany.net' }
471
- let(:fqdn_hostname) {'this-noun'}
472
- let(:fqdn_ns_hostname) {'that-noun'}
498
+ let(:fqdn_hostname) { 'this-noun' }
499
+ let(:fqdn_ns_hostname) { 'that-noun' }
473
500
  let(:template) { 'ubuntu-1604-x86_64' }
474
501
  let(:template_ns) { 'solaris-10-sparc' }
475
502
 
476
503
  # This seems to be the miminal stub response from ABS for the current output
477
504
  let(:response_body) do
478
505
  {
479
- hostname => {
480
- 'state' => 'allocated',
481
- 'allocated_resources' => [
482
- {
483
- 'hostname' => fqdn,
484
- 'type' => template,
485
- 'engine' => 'vmpooler',
486
- },
487
- {
488
- 'hostname' => fqdn_ns,
489
- 'type' => template_ns,
490
- 'engine' => 'nspooler',
491
- },
492
- ],
493
- 'request' => {
494
- 'job' => {
495
- 'id' => hostname,
496
- }
497
- },
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
+ }
498
524
  }
525
+ }
499
526
  }
500
527
  end
501
528
 
@@ -503,39 +530,39 @@ describe Utils do
503
530
  let(:domain) { 'delivery.mycompany.net' }
504
531
  let(:response_body_vmpooler) do
505
532
  {
506
- fqdn_hostname => {
507
- 'template' => template,
508
- 'lifetime' => 48,
509
- 'running' => 7.67,
510
- 'state' => 'running',
511
- 'tags' => {
512
- 'user' => 'bob',
513
- 'role' => 'agent',
514
- },
515
- 'ip' => '127.0.0.1',
516
- 'domain' => domain,
517
- }
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
+ }
518
545
  }
519
546
  end
520
547
 
521
548
  before(:each) do
522
549
  allow(Utils).to receive(:get_vmpooler_service_config).and_return({
523
- 'url' => 'http://vmpooler.example.com',
524
- 'token' => 'krypto-knight'
550
+ 'url' => 'http://vmpooler.example.com',
551
+ 'token' => 'krypto-knight'
525
552
  })
526
553
  allow(service).to receive(:query)
527
- .with(anything, fqdn_hostname)
528
- .and_return(response_body_vmpooler)
554
+ .with(anything, fqdn_hostname)
555
+ .and_return(response_body_vmpooler)
529
556
  end
530
557
 
531
558
  let(:default_output_first_line) { "- [JobID:#{hostname}] <allocated>" }
532
- let(:default_output_second_line) { " - #{fqdn} (#{template}, 7.67/48 hours, user: bob, role: agent)" }
559
+ let(:default_output_second_line) { " - #{fqdn} (#{template})" }
533
560
  let(:default_output_third_line) { " - #{fqdn_ns} (#{template_ns})" }
534
561
 
535
562
  it 'prints output with job id, host, and template' do
536
- expect(STDOUT).to receive(:puts).with(default_output_first_line)
537
- expect(STDOUT).to receive(:puts).with(default_output_second_line)
538
- 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)
539
566
 
540
567
  subject
541
568
  end
@@ -544,9 +571,9 @@ describe Utils do
544
571
  let(:print_to_stderr) { true }
545
572
 
546
573
  it 'outputs to stderr instead of stdout' do
547
- expect(STDERR).to receive(:puts).with(default_output_first_line)
548
- expect(STDERR).to receive(:puts).with(default_output_second_line)
549
- 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)
550
577
 
551
578
  subject
552
579
  end
@@ -560,54 +587,59 @@ describe Utils do
560
587
  config = {
561
588
  'user' => 'foo',
562
589
  'services' => {
563
- 'myabs' => {
564
- 'url' => 'http://abs.com',
565
- 'token' => 'krypto-night',
566
- 'type' => 'abs'
567
- }
590
+ 'myabs' => {
591
+ 'url' => 'http://abs.com',
592
+ 'token' => 'krypto-night',
593
+ 'type' => 'abs'
594
+ }
568
595
  }
569
596
  }
570
597
  allow(Conf).to receive(:read_config).and_return(config)
571
- 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)
572
601
  end
573
602
  it 'returns an error if the vmpooler_fallback is setup but cannot be found' do
574
603
  config = {
575
604
  'user' => 'foo',
576
605
  'services' => {
577
606
  'myabs' => {
578
- 'url' => 'http://abs.com',
579
- 'token' => 'krypto-night',
580
- 'type' => 'abs',
581
- 'vmpooler_fallback' => 'myvmpooler'
607
+ 'url' => 'http://abs.com',
608
+ 'token' => 'krypto-night',
609
+ 'type' => 'abs',
610
+ 'vmpooler_fallback' => 'myvmpooler'
582
611
  }
583
612
  }
584
613
  }
585
614
  allow(Conf).to receive(:read_config).and_return(config)
586
- 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/)
587
619
  end
588
620
  it 'returns the vmpooler_fallback config' do
589
621
  config = {
590
622
  'user' => 'foo',
591
623
  'services' => {
592
624
  'myabs' => {
593
- 'url' => 'http://abs.com',
594
- 'token' => 'krypto-night',
595
- 'type' => 'abs',
596
- 'vmpooler_fallback' => 'myvmpooler'
625
+ 'url' => 'http://abs.com',
626
+ 'token' => 'krypto-night',
627
+ 'type' => 'abs',
628
+ 'vmpooler_fallback' => 'myvmpooler'
597
629
  },
598
630
  'myvmpooler' => {
599
- 'url' => 'http://vmpooler.com',
600
- 'token' => 'krypto-knight'
631
+ 'url' => 'http://vmpooler.com',
632
+ 'token' => 'krypto-knight'
601
633
  }
602
634
  }
603
635
  }
604
636
  allow(Conf).to receive(:read_config).and_return(config)
605
637
  expect(Utils.get_vmpooler_service_config(config['services']['myabs']['vmpooler_fallback'])).to include({
606
- 'url' => 'http://vmpooler.com',
607
- 'token' => 'krypto-knight',
608
- 'user' => 'foo',
609
- 'type' => 'vmpooler'
610
- })
638
+ 'url' => 'http://vmpooler.com',
639
+ 'token' => 'krypto-knight',
640
+ 'user' => 'foo',
641
+ 'type' => 'vmpooler'
642
+ })
611
643
  end
612
644
  end
613
645
  end