vmfloaty 1.0.0 → 1.4.0
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/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
data/lib/vmfloaty/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'simplecov'
|
4
4
|
require 'coveralls'
|
5
|
+
require 'base64'
|
5
6
|
|
6
7
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
7
|
-
|
8
|
-
|
9
|
-
])
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
])
|
10
11
|
SimpleCov.start do
|
11
12
|
add_filter %r{^/spec/}
|
12
13
|
end
|
@@ -26,3 +27,19 @@ RSpec.configure do |config|
|
|
26
27
|
config.tty = true
|
27
28
|
config.formatter = :documentation
|
28
29
|
end
|
30
|
+
|
31
|
+
def get_headers(username: nil, password: nil, token: nil, content_type: nil, content_length: nil)
|
32
|
+
headers = {
|
33
|
+
'Accept' => '*/*',
|
34
|
+
'Accept-Encoding' => /gzip/,
|
35
|
+
'User-Agent' => /Faraday/,
|
36
|
+
}
|
37
|
+
if username && password
|
38
|
+
auth = Base64.encode64("#{username}:#{password}").chomp
|
39
|
+
headers['Authorization'] = "Basic #{auth}"
|
40
|
+
end
|
41
|
+
headers['X-Auth-Token'] = token if token
|
42
|
+
headers['Content-Type'] = content_type if content_type
|
43
|
+
headers['Content-Length'] = content_length.to_s if content_length
|
44
|
+
headers
|
45
|
+
end
|
@@ -3,7 +3,11 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require_relative '../../../lib/vmfloaty/auth'
|
5
5
|
|
6
|
+
user = 'first.last'
|
7
|
+
pass = 'password'
|
8
|
+
|
6
9
|
describe Pooler do
|
10
|
+
|
7
11
|
before :each do
|
8
12
|
@abs_url = 'https://abs.example.com/api/v2'
|
9
13
|
end
|
@@ -15,18 +19,20 @@ describe Pooler do
|
|
15
19
|
end
|
16
20
|
|
17
21
|
it 'returns a token from abs' do
|
18
|
-
stub_request(:post, 'https://
|
19
|
-
.
|
22
|
+
stub_request(:post, 'https://abs.example.com/api/v2/token')
|
23
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
24
|
+
.to_return(status: 200, body: @get_token_response, headers: {})
|
20
25
|
|
21
|
-
token = Auth.get_token(false, @abs_url,
|
26
|
+
token = Auth.get_token(false, @abs_url, user, pass)
|
22
27
|
expect(token).to eq @token
|
23
28
|
end
|
24
29
|
|
25
30
|
it 'raises a token error if something goes wrong' do
|
26
|
-
stub_request(:post, 'https://
|
27
|
-
.
|
31
|
+
stub_request(:post, 'https://abs.example.com/api/v2/token')
|
32
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
33
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
28
34
|
|
29
|
-
expect { Auth.get_token(false, @abs_url,
|
35
|
+
expect { Auth.get_token(false, @abs_url, user, pass) }.to raise_error(TokenError)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
@@ -37,21 +43,24 @@ describe Pooler do
|
|
37
43
|
end
|
38
44
|
|
39
45
|
it 'deletes the specified token' do
|
40
|
-
stub_request(:delete, 'https://
|
41
|
-
.
|
46
|
+
stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
47
|
+
.with(headers: get_headers(username: user, password: pass))
|
48
|
+
.to_return(status: 200, body: @delete_token_response, headers: {})
|
42
49
|
|
43
|
-
expect(Auth.delete_token(false, @abs_url,
|
50
|
+
expect(Auth.delete_token(false, @abs_url, user, pass,
|
51
|
+
@token)).to eq JSON.parse(@delete_token_response)
|
44
52
|
end
|
45
53
|
|
46
54
|
it 'raises a token error if something goes wrong' do
|
47
|
-
stub_request(:delete, 'https://
|
48
|
-
.
|
55
|
+
stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
56
|
+
.with(headers: get_headers(username: user, password: pass))
|
57
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
49
58
|
|
50
|
-
expect { Auth.delete_token(false, @abs_url,
|
59
|
+
expect { Auth.delete_token(false, @abs_url, user, pass, @token) }.to raise_error(TokenError)
|
51
60
|
end
|
52
61
|
|
53
62
|
it 'raises a token error if no token provided' do
|
54
|
-
expect { Auth.delete_token(false, @abs_url,
|
63
|
+
expect { Auth.delete_token(false, @abs_url, user, pass, nil) }.to raise_error(TokenError)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
@@ -63,16 +72,16 @@ describe Pooler do
|
|
63
72
|
|
64
73
|
it 'checks the status of a token' do
|
65
74
|
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
66
|
-
.with(:
|
67
|
-
.to_return(:
|
75
|
+
.with(headers: get_headers)
|
76
|
+
.to_return(status: 200, body: @token_status_response, headers: {})
|
68
77
|
|
69
78
|
expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
|
70
79
|
end
|
71
80
|
|
72
81
|
it 'raises a token error if something goes wrong' do
|
73
82
|
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
74
|
-
.with(:
|
75
|
-
.to_return(:
|
83
|
+
.with(headers: get_headers)
|
84
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
76
85
|
|
77
86
|
expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
|
78
87
|
end
|
data/spec/vmfloaty/abs_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe ABS do
|
|
11
11
|
|
12
12
|
describe '#list' do
|
13
13
|
it 'skips empty platforms and lists aws' do
|
14
|
-
stub_request(:get,
|
15
|
-
|
16
|
-
stub_request(:get,
|
17
|
-
|
18
|
-
stub_request(:get,
|
19
|
-
|
14
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/vmpooler')
|
15
|
+
.to_return(status: 200, body: '', headers: {})
|
16
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/ondemand_vmpooler')
|
17
|
+
.to_return(status: 200, body: '', headers: {})
|
18
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/nspooler')
|
19
|
+
.to_return(status: 200, body: '', headers: {})
|
20
20
|
body = '{
|
21
21
|
"aws_platforms": [
|
22
22
|
"amazon-6-x86_64",
|
@@ -26,50 +26,55 @@ describe ABS do
|
|
26
26
|
"redhat-8-arm64"
|
27
27
|
]
|
28
28
|
}'
|
29
|
-
stub_request(:get,
|
30
|
-
|
29
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
|
30
|
+
.to_return(status: 200, body: body, headers: {})
|
31
31
|
|
32
|
+
results = ABS.list(false, 'http://foo')
|
32
33
|
|
33
|
-
results
|
34
|
-
|
35
|
-
expect(results).to include("amazon-6-x86_64", "amazon-7-x86_64", "amazon-7-arm64", "centos-7-x86-64-west", "redhat-8-arm64")
|
34
|
+
expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
|
35
|
+
'redhat-8-arm64')
|
36
36
|
end
|
37
37
|
it 'legacy JSON string, prior to PR 306' do
|
38
|
-
stub_request(:get,
|
39
|
-
|
40
|
-
stub_request(:get,
|
41
|
-
|
42
|
-
stub_request(:get,
|
43
|
-
|
38
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/vmpooler')
|
39
|
+
.to_return(status: 200, body: '', headers: {})
|
40
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/ondemand_vmpooler')
|
41
|
+
.to_return(status: 200, body: '', headers: {})
|
42
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/nspooler')
|
43
|
+
.to_return(status: 200, body: '', headers: {})
|
44
44
|
body = '{
|
45
45
|
"aws_platforms": "[\"amazon-6-x86_64\",\"amazon-7-x86_64\",\"amazon-7-arm64\",\"centos-7-x86-64-west\",\"redhat-8-arm64\"]"
|
46
46
|
}'
|
47
|
-
stub_request(:get,
|
48
|
-
|
47
|
+
stub_request(:get, 'http://foo/api/v2/status/platforms/aws')
|
48
|
+
.to_return(status: 200, body: body, headers: {})
|
49
49
|
|
50
|
-
results = ABS.list(false,
|
50
|
+
results = ABS.list(false, 'http://foo')
|
51
51
|
|
52
|
-
expect(results).to include(
|
52
|
+
expect(results).to include('amazon-6-x86_64', 'amazon-7-x86_64', 'amazon-7-arm64', 'centos-7-x86-64-west',
|
53
|
+
'redhat-8-arm64')
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
describe '#format' do
|
57
58
|
it 'returns an hash formatted like a vmpooler return, plus the job_id' do
|
58
|
-
job_id =
|
59
|
+
job_id = 'generated_by_floaty_12345'
|
59
60
|
abs_formatted_response = [
|
60
|
-
{ 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
|
61
|
-
|
62
|
-
{ 'hostname' => '
|
61
|
+
{ 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
|
62
|
+
'engine' => 'vmpooler' },
|
63
|
+
{ 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64',
|
64
|
+
'engine' => 'vmpooler' },
|
65
|
+
{ 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64',
|
66
|
+
'engine' => 'vmpooler' }
|
63
67
|
]
|
64
68
|
|
65
69
|
vmpooler_formatted_response = ABS.translated(abs_formatted_response, job_id)
|
66
70
|
|
67
71
|
vmpooler_formatted_compare = {
|
68
72
|
'centos-7.2-x86_64' => {},
|
69
|
-
'ubuntu-7.2-x86_64' => {}
|
73
|
+
'ubuntu-7.2-x86_64' => {}
|
70
74
|
}
|
71
75
|
|
72
|
-
vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] =
|
76
|
+
vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] =
|
77
|
+
['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
|
73
78
|
vmpooler_formatted_compare['ubuntu-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaac.delivery.puppetlabs.net']
|
74
79
|
|
75
80
|
vmpooler_formatted_compare['ok'] = true
|
@@ -86,22 +91,22 @@ describe ABS do
|
|
86
91
|
hosts = ['host1']
|
87
92
|
allocated_resources = [
|
88
93
|
{
|
89
|
-
'hostname' => 'host1'
|
94
|
+
'hostname' => 'host1'
|
90
95
|
},
|
91
96
|
{
|
92
|
-
'hostname' => 'host2'
|
93
|
-
}
|
97
|
+
'hostname' => 'host2'
|
98
|
+
}
|
94
99
|
]
|
95
100
|
expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(false)
|
96
101
|
|
97
|
-
hosts = [
|
102
|
+
hosts = %w[host1 host2]
|
98
103
|
allocated_resources = [
|
99
104
|
{
|
100
|
-
'hostname' => 'host1'
|
105
|
+
'hostname' => 'host1'
|
101
106
|
},
|
102
107
|
{
|
103
|
-
'hostname' => 'host2'
|
104
|
-
}
|
108
|
+
'hostname' => 'host2'
|
109
|
+
}
|
105
110
|
]
|
106
111
|
expect(ABS.all_job_resources_accounted_for(allocated_resources, hosts)).to eq(true)
|
107
112
|
end
|
@@ -125,17 +130,17 @@ describe ABS do
|
|
125
130
|
end
|
126
131
|
|
127
132
|
it 'will skip a line with a null value returned from abs' do
|
128
|
-
stub_request(:get, 'https://abs.example.com/status/queue')
|
129
|
-
.to_return(:
|
133
|
+
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
134
|
+
.to_return(status: 200, body: @active_requests_response, headers: {})
|
130
135
|
|
131
136
|
ret = ABS.get_active_requests(false, @abs_url, @test_user)
|
132
137
|
|
133
138
|
expect(ret[0]).to include(
|
134
139
|
'allocated_resources' => [{
|
135
140
|
'hostname' => 'take-this.delivery.puppetlabs.net',
|
136
|
-
'type'
|
137
|
-
'engine'
|
138
|
-
}]
|
141
|
+
'type' => 'win-2012r2-x86_64',
|
142
|
+
'engine' => 'vmpooler'
|
143
|
+
}]
|
139
144
|
)
|
140
145
|
end
|
141
146
|
end
|
@@ -147,7 +152,11 @@ describe ABS do
|
|
147
152
|
[
|
148
153
|
{ "state":"allocated", "last_processed":"2020-01-17 22:29:13 +0000", "allocated_resources":[{"hostname":"craggy-chord.delivery.puppetlabs.net", "type":"centos-7-x86_64", "engine":"vmpooler"}, {"hostname":"visible-revival.delivery.puppetlabs.net", "type":"centos-7-x86_64", "engine":"vmpooler"}], "audit_log":{"2020-01-17 22:28:45 +0000":"Allocated craggy-chord.delivery.puppetlabs.net, visible-revival.delivery.puppetlabs.net for job 1579300120799"}, "request":{"resources":{"centos-7-x86_64":2}, "job":{"id":"1579300120799", "tags":{"user":"test-user"}, "user":"test-user", "time-received":1579300120}, "priority":3}}
|
149
154
|
]'
|
150
|
-
@return_request = {
|
155
|
+
@return_request = {
|
156
|
+
"job_id" => "1579300120799",
|
157
|
+
"hosts" => [{"hostname"=>"craggy-chord.delivery.puppetlabs.net","type"=>"centos-7-x86_64","engine"=>"vmpooler"},
|
158
|
+
{"hostname"=>"visible-revival.delivery.puppetlabs.net","type"=>"centos-7-x86_64","engine"=>"vmpooler"}]
|
159
|
+
}
|
151
160
|
# rubocop:enable Layout/LineLength
|
152
161
|
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
153
162
|
@test_user = 'test-user'
|
@@ -156,16 +165,16 @@ describe ABS do
|
|
156
165
|
end
|
157
166
|
|
158
167
|
it 'will delete the whole job' do
|
159
|
-
stub_request(:get, 'https://abs.example.com/status/queue')
|
160
|
-
.to_return(:
|
161
|
-
stub_request(:post, 'https://abs.example.com/return')
|
162
|
-
.with(:
|
163
|
-
.to_return(:
|
168
|
+
stub_request(:get, 'https://abs.example.com/api/v2/status/queue')
|
169
|
+
.to_return(status: 200, body: @active_requests_response, headers: {})
|
170
|
+
stub_request(:post, 'https://abs.example.com/api/v2/return')
|
171
|
+
.with(headers: get_headers(content_type: 'application/x-www-form-urlencoded', token: @token), body: @return_request.to_json)
|
172
|
+
.to_return(status: 200, body: 'OK', headers: {})
|
164
173
|
|
165
174
|
ret = ABS.delete(false, @abs_url, @hosts, @token, @test_user)
|
166
175
|
|
167
176
|
expect(ret).to include(
|
168
|
-
'craggy-chord.delivery.puppetlabs.net' => { 'ok'=>true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok'=>true }
|
177
|
+
'craggy-chord.delivery.puppetlabs.net' => { 'ok' => true }, 'visible-revival.delivery.puppetlabs.net' => { 'ok' => true }
|
169
178
|
)
|
170
179
|
end
|
171
180
|
end
|
data/spec/vmfloaty/auth_spec.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require_relative '../../lib/vmfloaty/auth'
|
5
5
|
|
6
|
+
user = 'first.last'
|
7
|
+
pass = 'password'
|
8
|
+
|
6
9
|
describe Pooler do
|
7
10
|
before :each do
|
8
11
|
@vmpooler_url = 'https://vmpooler.example.com'
|
@@ -15,18 +18,20 @@ describe Pooler do
|
|
15
18
|
end
|
16
19
|
|
17
20
|
it 'returns a token from vmpooler' do
|
18
|
-
stub_request(:post, 'https://
|
19
|
-
.
|
21
|
+
stub_request(:post, 'https://vmpooler.example.com/token')
|
22
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
23
|
+
.to_return(status: 200, body: @get_token_response, headers: {})
|
20
24
|
|
21
|
-
token = Auth.get_token(false, @vmpooler_url,
|
25
|
+
token = Auth.get_token(false, @vmpooler_url, user, pass)
|
22
26
|
expect(token).to eq @token
|
23
27
|
end
|
24
28
|
|
25
29
|
it 'raises a token error if something goes wrong' do
|
26
|
-
stub_request(:post, 'https://
|
27
|
-
|
30
|
+
stub_request(:post, 'https://vmpooler.example.com/token')
|
31
|
+
.with(headers: get_headers(username: user, password: pass, content_length: 0))
|
32
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
28
33
|
|
29
|
-
expect { Auth.get_token(false, @vmpooler_url,
|
34
|
+
expect { Auth.get_token(false, @vmpooler_url, user, pass) }.to raise_error(TokenError)
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
@@ -37,15 +42,18 @@ describe Pooler do
|
|
37
42
|
end
|
38
43
|
|
39
44
|
it 'deletes the specified token' do
|
40
|
-
stub_request(:delete, 'https://
|
41
|
-
.
|
45
|
+
stub_request(:delete, 'https://vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
46
|
+
.with(headers: get_headers(username: user, password: pass))
|
47
|
+
.to_return(status: 200, body: @delete_token_response, headers: {})
|
42
48
|
|
43
|
-
expect(Auth.delete_token(false, @vmpooler_url,
|
49
|
+
expect(Auth.delete_token(false, @vmpooler_url, user, pass,
|
50
|
+
@token)).to eq JSON.parse(@delete_token_response)
|
44
51
|
end
|
45
52
|
|
46
53
|
it 'raises a token error if something goes wrong' do
|
47
|
-
stub_request(:delete, 'https://
|
48
|
-
.
|
54
|
+
stub_request(:delete, 'https://vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
55
|
+
.with(headers: get_headers(username: user, password: pass))
|
56
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
49
57
|
|
50
58
|
expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
|
51
59
|
end
|
@@ -63,14 +71,16 @@ describe Pooler do
|
|
63
71
|
|
64
72
|
it 'checks the status of a token' do
|
65
73
|
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
66
|
-
.
|
74
|
+
.with(headers: get_headers)
|
75
|
+
.to_return(status: 200, body: @token_status_response, headers: {})
|
67
76
|
|
68
77
|
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
|
69
78
|
end
|
70
79
|
|
71
80
|
it 'raises a token error if something goes wrong' do
|
72
81
|
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
73
|
-
.
|
82
|
+
.with(headers: get_headers)
|
83
|
+
.to_return(status: 500, body: '{"ok":false}', headers: {})
|
74
84
|
|
75
85
|
expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
|
76
86
|
end
|
@@ -8,9 +8,7 @@ require 'vmfloaty/nonstandard_pooler'
|
|
8
8
|
describe NonstandardPooler do
|
9
9
|
before :each do
|
10
10
|
@nspooler_url = 'https://nspooler.example.com'
|
11
|
-
@auth_token_headers =
|
12
|
-
'X-Auth-Token' => 'token-value',
|
13
|
-
}
|
11
|
+
@auth_token_headers = get_headers(token: 'token-value')
|
14
12
|
end
|
15
13
|
|
16
14
|
describe '#list' do
|
@@ -36,7 +34,7 @@ describe NonstandardPooler do
|
|
36
34
|
|
37
35
|
it 'returns an array with operating systems from the pooler' do
|
38
36
|
stub_request(:get, "#{@nspooler_url}/status")
|
39
|
-
.to_return(:
|
37
|
+
.to_return(status: 200, body: @status_response_body, headers: {})
|
40
38
|
|
41
39
|
list = NonstandardPooler.list(false, @nspooler_url, nil)
|
42
40
|
expect(list).to be_an_instance_of Array
|
@@ -44,7 +42,7 @@ describe NonstandardPooler do
|
|
44
42
|
|
45
43
|
it 'filters operating systems based on the filter param' do
|
46
44
|
stub_request(:get, "#{@nspooler_url}/status")
|
47
|
-
.to_return(:
|
45
|
+
.to_return(status: 200, body: @status_response_body, headers: {})
|
48
46
|
|
49
47
|
list = NonstandardPooler.list(false, @nspooler_url, 'aix')
|
50
48
|
expect(list).to be_an_instance_of Array
|
@@ -53,7 +51,7 @@ describe NonstandardPooler do
|
|
53
51
|
|
54
52
|
it 'returns nothing if the filter does not match' do
|
55
53
|
stub_request(:get, "#{@nspooler_url}/status")
|
56
|
-
.to_return(:
|
54
|
+
.to_return(status: 199, body: @status_response_body, headers: {})
|
57
55
|
|
58
56
|
list = NonstandardPooler.list(false, @nspooler_url, 'windows')
|
59
57
|
expect(list).to be_an_instance_of Array
|
@@ -89,7 +87,7 @@ describe NonstandardPooler do
|
|
89
87
|
.and_return(JSON.parse(@token_status_body_active))
|
90
88
|
|
91
89
|
list = NonstandardPooler.list_active(false, @nspooler_url, 'token-value', 'user')
|
92
|
-
expect(list).to eql [
|
90
|
+
expect(list).to eql %w[sol10-9 sol10-11]
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
@@ -121,17 +119,19 @@ describe NonstandardPooler do
|
|
121
119
|
|
122
120
|
it 'raises an AuthError if the token is invalid' do
|
123
121
|
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
124
|
-
.with(:
|
125
|
-
.to_return(:
|
122
|
+
.with(headers: get_headers(token: 'token-value'))
|
123
|
+
.to_return(status: 401, body: '{"ok":false,"reason": "token: token-value does not exist"}', headers: {})
|
126
124
|
|
127
125
|
vm_hash = { 'solaris-11-sparc' => 1 }
|
128
|
-
expect
|
126
|
+
expect do
|
127
|
+
NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
128
|
+
end.to raise_error(AuthError)
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'retrieves a single vm with a token' do
|
132
132
|
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
133
|
-
.with(:
|
134
|
-
.to_return(:
|
133
|
+
.with(headers: @auth_token_headers)
|
134
|
+
.to_return(status: 200, body: @retrieve_response_body_single, headers: {})
|
135
135
|
|
136
136
|
vm_hash = { 'solaris-11-sparc' => 1 }
|
137
137
|
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
@@ -142,15 +142,16 @@ describe NonstandardPooler do
|
|
142
142
|
|
143
143
|
it 'retrieves a multiple vms with a token' do
|
144
144
|
stub_request(:post, "#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc")
|
145
|
-
.with(:
|
146
|
-
.to_return(:
|
145
|
+
.with(headers: @auth_token_headers)
|
146
|
+
.to_return(status: 200, body: @retrieve_response_body_many, headers: {})
|
147
147
|
|
148
148
|
vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 }
|
149
149
|
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
150
150
|
expect(vm_req).to be_an_instance_of Hash
|
151
151
|
expect(vm_req['ok']).to equal true
|
152
152
|
expect(vm_req['solaris-10-sparc']['hostname']).to be_an_instance_of Array
|
153
|
-
expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net',
|
153
|
+
expect(vm_req['solaris-10-sparc']['hostname']).to eq ['sol10-9.delivery.puppetlabs.net',
|
154
|
+
'sol10-10.delivery.puppetlabs.net']
|
154
155
|
expect(vm_req['aix-7.1-power']['hostname']).to eq 'pe-aix-71-ci-acceptance.delivery.puppetlabs.net'
|
155
156
|
end
|
156
157
|
end
|
@@ -162,22 +163,22 @@ describe NonstandardPooler do
|
|
162
163
|
|
163
164
|
it 'raises an error if the user tries to modify an unsupported attribute' do
|
164
165
|
stub_request(:put, 'https://nspooler.example.com/host/myfakehost')
|
165
|
-
.with(:
|
166
|
-
:
|
167
|
-
.to_return(:
|
168
|
-
details = { :
|
166
|
+
.with(body: { '{}' => true },
|
167
|
+
headers: @auth_token_headers)
|
168
|
+
.to_return(status: 200, body: '', headers: {})
|
169
|
+
details = { lifetime: 12 }
|
169
170
|
expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
|
170
171
|
.to raise_error(ModifyError)
|
171
172
|
end
|
172
173
|
|
173
174
|
it 'modifies the reason of a vm' do
|
174
|
-
modify_request_body = { '{"reserved_for_reason":"testing"}' =>
|
175
|
+
modify_request_body = { '{"reserved_for_reason":"testing"}' => nil }
|
175
176
|
stub_request(:put, "#{@nspooler_url}/host/myfakehost")
|
176
|
-
.with(:
|
177
|
-
:
|
178
|
-
.to_return(:
|
177
|
+
.with(body: modify_request_body,
|
178
|
+
headers: @auth_token_headers)
|
179
|
+
.to_return(status: 200, body: '{"ok": true}', headers: {})
|
179
180
|
|
180
|
-
modify_hash = { :
|
181
|
+
modify_hash = { reason: 'testing' }
|
181
182
|
modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash)
|
182
183
|
expect(modify_req['ok']).to be true
|
183
184
|
end
|
@@ -208,7 +209,7 @@ describe NonstandardPooler do
|
|
208
209
|
|
209
210
|
it 'prints the status' do
|
210
211
|
stub_request(:get, "#{@nspooler_url}/status")
|
211
|
-
.to_return(:
|
212
|
+
.to_return(status: 200, body: @status_response_body, headers: {})
|
212
213
|
|
213
214
|
status = NonstandardPooler.status(false, @nspooler_url)
|
214
215
|
expect(status).to be_an_instance_of Hash
|
@@ -231,7 +232,7 @@ describe NonstandardPooler do
|
|
231
232
|
|
232
233
|
it 'prints the summary' do
|
233
234
|
stub_request(:get, "#{@nspooler_url}/summary")
|
234
|
-
.to_return(:
|
235
|
+
.to_return(status: 200, body: @status_response_body, headers: {})
|
235
236
|
|
236
237
|
summary = NonstandardPooler.summary(false, @nspooler_url)
|
237
238
|
expect(summary).to be_an_instance_of Hash
|
@@ -256,7 +257,7 @@ describe NonstandardPooler do
|
|
256
257
|
|
257
258
|
it 'makes a query about a vm' do
|
258
259
|
stub_request(:get, "#{@nspooler_url}/host/sol10-11")
|
259
|
-
.to_return(:
|
260
|
+
.to_return(status: 200, body: @query_response_body, headers: {})
|
260
261
|
|
261
262
|
query_req = NonstandardPooler.query(false, @nspooler_url, 'sol10-11')
|
262
263
|
expect(query_req).to be_an_instance_of Hash
|
@@ -271,8 +272,8 @@ describe NonstandardPooler do
|
|
271
272
|
|
272
273
|
it 'deletes a single existing vm' do
|
273
274
|
stub_request(:delete, "#{@nspooler_url}/host/sol11-7")
|
274
|
-
.with(:
|
275
|
-
.to_return(:
|
275
|
+
.with(headers: @auth_token_headers)
|
276
|
+
.to_return(status: 200, body: @delete_response_success, headers: {})
|
276
277
|
|
277
278
|
request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil)
|
278
279
|
expect(request['sol11-7']['ok']).to be true
|
@@ -280,8 +281,8 @@ describe NonstandardPooler do
|
|
280
281
|
|
281
282
|
it 'does not delete a nonexistant vm' do
|
282
283
|
stub_request(:delete, "#{@nspooler_url}/host/fakehost")
|
283
|
-
.with(:
|
284
|
-
.to_return(:
|
284
|
+
.with(headers: @auth_token_headers)
|
285
|
+
.to_return(status: 401, body: @delete_response_failure, headers: {})
|
285
286
|
|
286
287
|
request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil)
|
287
288
|
expect(request['fakehost']['ok']).to be false
|