vmfloaty 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/extras/completions/floaty.bash +16 -8
- data/extras/completions/floaty.zsh +13 -7
- data/lib/vmfloaty.rb +62 -50
- data/lib/vmfloaty/abs.rb +86 -69
- data/lib/vmfloaty/http.rb +2 -6
- data/lib/vmfloaty/logger.rb +19 -3
- data/lib/vmfloaty/nonstandard_pooler.rb +3 -2
- data/lib/vmfloaty/pooler.rb +20 -25
- data/lib/vmfloaty/service.rb +6 -6
- data/lib/vmfloaty/utils.rb +67 -62
- data/lib/vmfloaty/version.rb +1 -2
- data/spec/spec_helper.rb +20 -3
- data/spec/vmfloaty/abs/auth_spec.rb +26 -17
- data/spec/vmfloaty/abs_spec.rb +55 -46
- data/spec/vmfloaty/auth_spec.rb +23 -13
- data/spec/vmfloaty/nonstandard_pooler_spec.rb +32 -31
- data/spec/vmfloaty/pooler_spec.rb +29 -26
- data/spec/vmfloaty/service_spec.rb +10 -10
- data/spec/vmfloaty/ssh_spec.rb +3 -3
- data/spec/vmfloaty/utils_spec.rb +191 -159
- metadata +17 -11
@@ -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(:
|
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(:
|
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(:
|
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(:
|
52
|
-
.to_return(:
|
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(:
|
62
|
-
.to_return(:
|
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(:
|
75
|
-
.to_return(:
|
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(:
|
93
|
-
.to_return(:
|
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(:
|
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 = { :
|
120
|
+
modify_hash = { lifetime: 12 }
|
121
121
|
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
122
|
-
.with(:
|
123
|
-
:
|
124
|
-
.to_return(:
|
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(:
|
140
|
-
.to_return(:
|
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(:
|
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(:
|
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(:
|
196
|
-
.to_return(:
|
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(:
|
211
|
-
.to_return(:
|
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
|
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(:
|
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(
|
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(
|
33
|
-
allow(
|
34
|
-
allow(
|
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'
|
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'
|
68
|
-
'user'
|
69
|
-
'created'
|
70
|
-
'last_accessed'
|
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')
|
data/spec/vmfloaty/ssh_spec.rb
CHANGED
@@ -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'
|
11
|
+
'ok' => true
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
15
|
{
|
16
16
|
os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
|
17
|
-
'domain'
|
18
|
-
'ok'
|
17
|
+
'domain' => 'delivery.puppetlabs.net',
|
18
|
+
'ok' => true
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
data/spec/vmfloaty/utils_spec.rb
CHANGED
@@ -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'
|
35
|
-
'ubuntu-1610-x86_64' => ['gdoy8q3nckuob0i.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'
|
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'
|
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'
|
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'
|
97
|
-
'user'
|
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'
|
104
|
-
'user'
|
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'
|
109
|
-
'user'
|
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(:
|
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(:
|
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(:
|
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(:
|
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'
|
181
|
-
'state'
|
182
|
-
'ip'
|
183
|
-
'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(
|
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'
|
200
|
-
'os_triple'
|
201
|
-
'reserved_by_user'
|
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(
|
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(
|
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'
|
274
|
-
'state'
|
275
|
-
'ip'
|
276
|
-
'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(
|
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'
|
297
|
-
'state'
|
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'
|
303
|
-
'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(
|
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(
|
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'
|
336
|
-
'os_triple'
|
337
|
-
'reserved_by_user'
|
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(
|
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'
|
357
|
-
'os_triple'
|
358
|
-
'reserved_by_user'
|
359
|
-
'reserved_for_reason'
|
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(
|
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(
|
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
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
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
|
-
|
436
|
-
|
437
|
-
|
441
|
+
'url' => 'http://vmpooler.example.com',
|
442
|
+
'token' => 'krypto-knight'
|
443
|
+
})
|
438
444
|
allow(service).to receive(:query)
|
439
|
-
|
440
|
-
|
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}
|
450
|
+
let(:default_output_second_line) { " - #{fqdn} (#{template})" }
|
445
451
|
|
446
452
|
it 'prints output with job id, host, and template' do
|
447
|
-
expect(
|
448
|
-
expect(
|
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(
|
458
|
-
expect(
|
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
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
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
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
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
|
-
|
524
|
-
|
550
|
+
'url' => 'http://vmpooler.example.com',
|
551
|
+
'token' => 'krypto-knight'
|
525
552
|
})
|
526
553
|
allow(service).to receive(:query)
|
527
|
-
|
528
|
-
|
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}
|
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(
|
537
|
-
expect(
|
538
|
-
expect(
|
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(
|
548
|
-
expect(
|
549
|
-
expect(
|
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
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
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
|
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
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
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
|
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
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
625
|
+
'url' => 'http://abs.com',
|
626
|
+
'token' => 'krypto-night',
|
627
|
+
'type' => 'abs',
|
628
|
+
'vmpooler_fallback' => 'myvmpooler'
|
597
629
|
},
|
598
630
|
'myvmpooler' => {
|
599
|
-
|
600
|
-
|
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
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|