vmfloaty 0.8.1 → 0.10.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 +5 -5
- data/README.md +96 -55
- data/bin/floaty +2 -1
- data/lib/vmfloaty.rb +60 -53
- data/lib/vmfloaty/abs.rb +318 -0
- data/lib/vmfloaty/auth.rb +14 -22
- data/lib/vmfloaty/conf.rb +3 -2
- data/lib/vmfloaty/errors.rb +6 -4
- data/lib/vmfloaty/http.rb +14 -25
- data/lib/vmfloaty/nonstandard_pooler.rb +15 -31
- data/lib/vmfloaty/pooler.rb +64 -55
- data/lib/vmfloaty/service.rb +25 -17
- data/lib/vmfloaty/ssh.rb +25 -25
- data/lib/vmfloaty/utils.rb +103 -97
- data/lib/vmfloaty/version.rb +3 -1
- data/spec/spec_helper.rb +13 -0
- data/spec/vmfloaty/abs/auth_spec.rb +84 -0
- data/spec/vmfloaty/abs_spec.rb +126 -0
- data/spec/vmfloaty/auth_spec.rb +39 -43
- data/spec/vmfloaty/nonstandard_pooler_spec.rb +132 -146
- data/spec/vmfloaty/pooler_spec.rb +121 -101
- data/spec/vmfloaty/service_spec.rb +17 -17
- data/spec/vmfloaty/ssh_spec.rb +49 -0
- data/spec/vmfloaty/utils_spec.rb +123 -98
- data/spec/vmfloaty/vmfloaty_services_spec.rb +39 -0
- metadata +38 -22
data/spec/vmfloaty/auth_spec.rb
CHANGED
@@ -1,86 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require_relative '../../lib/vmfloaty/auth'
|
3
5
|
|
4
6
|
describe Pooler do
|
5
7
|
before :each do
|
6
|
-
@vmpooler_url =
|
8
|
+
@vmpooler_url = 'https://vmpooler.example.com'
|
7
9
|
end
|
8
10
|
|
9
|
-
describe
|
11
|
+
describe '#get_token' do
|
10
12
|
before :each do
|
11
|
-
@get_token_response =
|
12
|
-
@token =
|
13
|
+
@get_token_response = '{"ok": true,"token":"utpg2i2xswor6h8ttjhu3d47z53yy47y"}'
|
14
|
+
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
13
15
|
end
|
14
16
|
|
15
|
-
it
|
16
|
-
stub_request(:post,
|
17
|
-
|
18
|
-
to_return(:status => 200, :body => @get_token_response, :headers => {})
|
17
|
+
it 'returns a token from vmpooler' do
|
18
|
+
stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
|
19
|
+
.to_return(:status => 200, :body => @get_token_response, :headers => {})
|
19
20
|
|
20
|
-
token = Auth.get_token(false, @vmpooler_url,
|
21
|
+
token = Auth.get_token(false, @vmpooler_url, 'first.last', 'password')
|
21
22
|
expect(token).to eq @token
|
22
23
|
end
|
23
24
|
|
24
|
-
it
|
25
|
-
stub_request(:post,
|
26
|
-
|
27
|
-
to_return(:status => 500, :body => "{\"ok\":false}", :headers => {})
|
25
|
+
it 'raises a token error if something goes wrong' do
|
26
|
+
stub_request(:post, 'https://first.last:password@vmpooler.example.com/token')
|
27
|
+
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
28
28
|
|
29
|
-
expect{ Auth.get_token(false, @vmpooler_url,
|
29
|
+
expect { Auth.get_token(false, @vmpooler_url, 'first.last', 'password') }.to raise_error(TokenError)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe
|
33
|
+
describe '#delete_token' do
|
34
34
|
before :each do
|
35
|
-
@delete_token_response =
|
36
|
-
@token =
|
35
|
+
@delete_token_response = '{"ok":true}'
|
36
|
+
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
stub_request(:delete,
|
41
|
-
|
42
|
-
to_return(:status => 200, :body => @delete_token_response, :headers => {})
|
39
|
+
it 'deletes the specified token' do
|
40
|
+
stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
41
|
+
.to_return(:status => 200, :body => @delete_token_response, :headers => {})
|
43
42
|
|
44
|
-
expect(Auth.delete_token(false, @vmpooler_url,
|
43
|
+
expect(Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
|
45
44
|
end
|
46
45
|
|
47
|
-
it
|
48
|
-
stub_request(:delete,
|
49
|
-
|
50
|
-
to_return(:status => 500, :body => "{\"ok\":false}", :headers => {})
|
46
|
+
it 'raises a token error if something goes wrong' do
|
47
|
+
stub_request(:delete, 'https://first.last:password@vmpooler.example.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
48
|
+
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
51
49
|
|
52
|
-
expect{ Auth.delete_token(false, @vmpooler_url,
|
50
|
+
expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
|
53
51
|
end
|
54
52
|
|
55
|
-
it
|
56
|
-
expect{ Auth.delete_token(false, @vmpooler_url,
|
53
|
+
it 'raises a token error if no token provided' do
|
54
|
+
expect { Auth.delete_token(false, @vmpooler_url, 'first.last', 'password', nil) }.to raise_error(TokenError)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
describe
|
58
|
+
describe '#token_status' do
|
61
59
|
before :each do
|
62
|
-
@token_status_response =
|
63
|
-
@token =
|
60
|
+
@token_status_response = '{"ok":true,"utpg2i2xswor6h8ttjhu3d47z53yy47y":{"created":"2015-04-28 19:17:47 -0700"}}'
|
61
|
+
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
64
62
|
end
|
65
63
|
|
66
|
-
it
|
67
|
-
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
68
|
-
|
69
|
-
to_return(:status => 200, :body => @token_status_response, :headers => {})
|
64
|
+
it 'checks the status of a token' do
|
65
|
+
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
66
|
+
.to_return(:status => 200, :body => @token_status_response, :headers => {})
|
70
67
|
|
71
68
|
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
|
72
69
|
end
|
73
70
|
|
74
|
-
it
|
75
|
-
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
76
|
-
|
77
|
-
to_return(:status => 500, :body => "{\"ok\":false}", :headers => {})
|
71
|
+
it 'raises a token error if something goes wrong' do
|
72
|
+
stub_request(:get, "#{@vmpooler_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
73
|
+
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
78
74
|
|
79
|
-
expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
|
75
|
+
expect { Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
|
80
76
|
end
|
81
77
|
|
82
|
-
it
|
83
|
-
expect{ Auth.token_status(false, @vmpooler_url, nil) }.to raise_error(TokenError)
|
78
|
+
it 'raises a token error if no token provided' do
|
79
|
+
expect { Auth.token_status(false, @vmpooler_url, nil) }.to raise_error(TokenError)
|
84
80
|
end
|
85
81
|
end
|
86
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'vmfloaty/utils'
|
3
5
|
require 'vmfloaty/errors'
|
@@ -6,48 +8,35 @@ require 'vmfloaty/nonstandard_pooler'
|
|
6
8
|
describe NonstandardPooler do
|
7
9
|
before :each do
|
8
10
|
@nspooler_url = 'https://nspooler.example.com'
|
9
|
-
@
|
10
|
-
'
|
11
|
-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
12
|
-
'User-Agent' => 'Faraday v0.9.2',
|
13
|
-
'X-Auth-Token' => 'token-value'
|
14
|
-
}
|
15
|
-
@get_request_headers = {
|
16
|
-
'Accept' => '*/*',
|
17
|
-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
18
|
-
'User-Agent' => 'Faraday v0.9.2',
|
19
|
-
'X-Auth-Token' => 'token-value'
|
11
|
+
@auth_token_headers = {
|
12
|
+
'X-Auth-Token' => 'token-value',
|
20
13
|
}
|
21
|
-
@get_request_headers_notoken = @get_request_headers.tap do |headers|
|
22
|
-
headers.delete('X-Auth-Token')
|
23
|
-
end
|
24
|
-
|
25
14
|
end
|
26
15
|
|
27
16
|
describe '#list' do
|
28
17
|
before :each do
|
29
|
-
@status_response_body =
|
30
|
-
{
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
18
|
+
@status_response_body = <<~BODY
|
19
|
+
{
|
20
|
+
"ok": true,
|
21
|
+
"solaris-10-sparc": {
|
22
|
+
"total_hosts": 11,
|
23
|
+
"available_hosts": 11
|
24
|
+
},
|
25
|
+
"ubuntu-16.04-power8": {
|
26
|
+
"total_hosts": 10,
|
27
|
+
"available_hosts": 10
|
28
|
+
},
|
29
|
+
"aix-7.2-power": {
|
30
|
+
"total_hosts": 5,
|
31
|
+
"available_hosts": 4
|
32
|
+
}
|
33
|
+
}
|
45
34
|
BODY
|
46
35
|
end
|
47
36
|
|
48
37
|
it 'returns an array with operating systems from the pooler' do
|
49
38
|
stub_request(:get, "#{@nspooler_url}/status")
|
50
|
-
.to_return(status
|
39
|
+
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
51
40
|
|
52
41
|
list = NonstandardPooler.list(false, @nspooler_url, nil)
|
53
42
|
expect(list).to be_an_instance_of Array
|
@@ -55,7 +44,7 @@ describe NonstandardPooler do
|
|
55
44
|
|
56
45
|
it 'filters operating systems based on the filter param' do
|
57
46
|
stub_request(:get, "#{@nspooler_url}/status")
|
58
|
-
.to_return(status
|
47
|
+
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
59
48
|
|
60
49
|
list = NonstandardPooler.list(false, @nspooler_url, 'aix')
|
61
50
|
expect(list).to be_an_instance_of Array
|
@@ -64,7 +53,7 @@ describe NonstandardPooler do
|
|
64
53
|
|
65
54
|
it 'returns nothing if the filter does not match' do
|
66
55
|
stub_request(:get, "#{@nspooler_url}/status")
|
67
|
-
.to_return(status
|
56
|
+
.to_return(:status => 199, :body => @status_response_body, :headers => {})
|
68
57
|
|
69
58
|
list = NonstandardPooler.list(false, @nspooler_url, 'windows')
|
70
59
|
expect(list).to be_an_instance_of Array
|
@@ -74,24 +63,24 @@ describe NonstandardPooler do
|
|
74
63
|
|
75
64
|
describe '#list_active' do
|
76
65
|
before :each do
|
77
|
-
@token_status_body_active =
|
78
|
-
{
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
BODY
|
86
|
-
@token_status_body_empty =
|
87
|
-
{
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
BODY
|
66
|
+
@token_status_body_active = <<~BODY
|
67
|
+
{
|
68
|
+
"ok": true,
|
69
|
+
"user": "first.last",
|
70
|
+
"created": "2017-09-18 01:25:41 +0000",
|
71
|
+
"last_accessed": "2017-09-21 19:46:25 +0000",
|
72
|
+
"reserved_hosts": ["sol10-9", "sol10-11"]
|
73
|
+
}
|
74
|
+
BODY
|
75
|
+
@token_status_body_empty = <<~BODY
|
76
|
+
{
|
77
|
+
"ok": true,
|
78
|
+
"user": "first.last",
|
79
|
+
"created": "2017-09-18 01:25:41 +0000",
|
80
|
+
"last_accessed": "2017-09-21 19:46:25 +0000",
|
81
|
+
"reserved_hosts": []
|
82
|
+
}
|
83
|
+
BODY
|
95
84
|
end
|
96
85
|
|
97
86
|
it 'prints an output of fqdn, template, and duration' do
|
@@ -99,65 +88,65 @@ BODY
|
|
99
88
|
.with(false, @nspooler_url, 'token-value')
|
100
89
|
.and_return(JSON.parse(@token_status_body_active))
|
101
90
|
|
102
|
-
list = NonstandardPooler.list_active(false, @nspooler_url, 'token-value')
|
91
|
+
list = NonstandardPooler.list_active(false, @nspooler_url, 'token-value', 'user')
|
103
92
|
expect(list).to eql ['sol10-9', 'sol10-11']
|
104
93
|
end
|
105
94
|
end
|
106
95
|
|
107
96
|
describe '#retrieve' do
|
108
97
|
before :each do
|
109
|
-
@retrieve_response_body_single =
|
110
|
-
{
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
BODY
|
117
|
-
@retrieve_response_body_many =
|
118
|
-
{
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
}
|
130
|
-
BODY
|
98
|
+
@retrieve_response_body_single = <<~BODY
|
99
|
+
{
|
100
|
+
"ok": true,
|
101
|
+
"solaris-11-sparc": {
|
102
|
+
"hostname": "sol11-4.delivery.puppetlabs.net"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
BODY
|
106
|
+
@retrieve_response_body_many = <<~BODY
|
107
|
+
{
|
108
|
+
"ok": true,
|
109
|
+
"solaris-10-sparc": {
|
110
|
+
"hostname": [
|
111
|
+
"sol10-9.delivery.puppetlabs.net",
|
112
|
+
"sol10-10.delivery.puppetlabs.net"
|
113
|
+
]
|
114
|
+
},
|
115
|
+
"aix-7.1-power": {
|
116
|
+
"hostname": "pe-aix-71-ci-acceptance.delivery.puppetlabs.net"
|
117
|
+
}
|
118
|
+
}
|
119
|
+
BODY
|
131
120
|
end
|
132
121
|
|
133
122
|
it 'raises an AuthError if the token is invalid' do
|
134
123
|
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
135
|
-
.with(headers
|
136
|
-
.to_return(status
|
124
|
+
.with(:headers => @auth_token_headers)
|
125
|
+
.to_return(:status => 401, :body => '{"ok":false,"reason": "token: token-value does not exist"}', :headers => {})
|
137
126
|
|
138
127
|
vm_hash = { 'solaris-11-sparc' => 1 }
|
139
|
-
expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url) }.to raise_error(AuthError)
|
128
|
+
expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {}) }.to raise_error(AuthError)
|
140
129
|
end
|
141
130
|
|
142
131
|
it 'retrieves a single vm with a token' do
|
143
132
|
stub_request(:post, "#{@nspooler_url}/host/solaris-11-sparc")
|
144
|
-
.with(headers
|
145
|
-
.to_return(status
|
133
|
+
.with(:headers => @auth_token_headers)
|
134
|
+
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
146
135
|
|
147
136
|
vm_hash = { 'solaris-11-sparc' => 1 }
|
148
|
-
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url)
|
137
|
+
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
149
138
|
expect(vm_req).to be_an_instance_of Hash
|
150
139
|
expect(vm_req['ok']).to equal true
|
151
140
|
expect(vm_req['solaris-11-sparc']['hostname']).to eq 'sol11-4.delivery.puppetlabs.net'
|
152
141
|
end
|
153
142
|
|
154
143
|
it 'retrieves a multiple vms with a token' do
|
155
|
-
stub_request(:post,"#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc")
|
156
|
-
.with(headers
|
157
|
-
.to_return(status
|
144
|
+
stub_request(:post, "#{@nspooler_url}/host/aix-7.1-power+solaris-10-sparc+solaris-10-sparc")
|
145
|
+
.with(:headers => @auth_token_headers)
|
146
|
+
.to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {})
|
158
147
|
|
159
148
|
vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 }
|
160
|
-
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url)
|
149
|
+
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last', {})
|
161
150
|
expect(vm_req).to be_an_instance_of Hash
|
162
151
|
expect(vm_req['ok']).to equal true
|
163
152
|
expect(vm_req['solaris-10-sparc']['hostname']).to be_an_instance_of Array
|
@@ -172,23 +161,23 @@ BODY
|
|
172
161
|
end
|
173
162
|
|
174
163
|
it 'raises an error if the user tries to modify an unsupported attribute' do
|
175
|
-
stub_request(:put,
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
details = { lifetime
|
164
|
+
stub_request(:put, 'https://nspooler.example.com/host/myfakehost')
|
165
|
+
.with(:body => { '{}' => true },
|
166
|
+
:headers => @auth_token_headers)
|
167
|
+
.to_return(:status => 200, :body => '', :headers => {})
|
168
|
+
details = { :lifetime => 12 }
|
180
169
|
expect { NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', details) }
|
181
|
-
|
170
|
+
.to raise_error(ModifyError)
|
182
171
|
end
|
183
172
|
|
184
173
|
it 'modifies the reason of a vm' do
|
185
174
|
modify_request_body = { '{"reserved_for_reason":"testing"}' => true }
|
186
175
|
stub_request(:put, "#{@nspooler_url}/host/myfakehost")
|
187
|
-
.with(body
|
188
|
-
headers
|
189
|
-
.to_return(status
|
176
|
+
.with(:body => modify_request_body,
|
177
|
+
:headers => @auth_token_headers)
|
178
|
+
.to_return(:status => 200, :body => '{"ok": true}', :headers => {})
|
190
179
|
|
191
|
-
modify_hash = { reason
|
180
|
+
modify_hash = { :reason => 'testing' }
|
192
181
|
modify_req = NonstandardPooler.modify(false, @nspooler_url, 'myfakehost', 'token-value', modify_hash)
|
193
182
|
expect(modify_req['ok']).to be true
|
194
183
|
end
|
@@ -198,29 +187,28 @@ BODY
|
|
198
187
|
before :each do
|
199
188
|
@status_response_body = '{"capacity":{"current":716,"total":717,"percent": 99.9},"status":{"ok":true,"message":"Battle station fully armed and operational."}}'
|
200
189
|
# TODO: make this report stuff like 'broken'
|
201
|
-
@status_response_body =
|
202
|
-
{
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
}
|
217
|
-
BODY
|
190
|
+
@status_response_body = <<~BODY
|
191
|
+
{
|
192
|
+
"ok": true,
|
193
|
+
"solaris-10-sparc": {
|
194
|
+
"total_hosts": 11,
|
195
|
+
"available_hosts": 10
|
196
|
+
},
|
197
|
+
"ubuntu-16.04-power8": {
|
198
|
+
"total_hosts": 10,
|
199
|
+
"available_hosts": 10
|
200
|
+
},
|
201
|
+
"aix-7.2-power": {
|
202
|
+
"total_hosts": 5,
|
203
|
+
"available_hosts": 4
|
204
|
+
}
|
205
|
+
}
|
206
|
+
BODY
|
218
207
|
end
|
219
208
|
|
220
209
|
it 'prints the status' do
|
221
210
|
stub_request(:get, "#{@nspooler_url}/status")
|
222
|
-
.
|
223
|
-
.to_return(status: 200, body: @status_response_body, headers: {})
|
211
|
+
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
224
212
|
|
225
213
|
status = NonstandardPooler.status(false, @nspooler_url)
|
226
214
|
expect(status).to be_an_instance_of Hash
|
@@ -229,22 +217,21 @@ BODY
|
|
229
217
|
|
230
218
|
describe '#summary' do
|
231
219
|
before :each do
|
232
|
-
@status_response_body =
|
233
|
-
{
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
}
|
241
|
-
BODY
|
220
|
+
@status_response_body = <<~BODY
|
221
|
+
{
|
222
|
+
"ok": true,
|
223
|
+
"total": 57,
|
224
|
+
"available": 39,
|
225
|
+
"in_use": 16,
|
226
|
+
"resetting": 2,
|
227
|
+
"broken": 0
|
228
|
+
}
|
229
|
+
BODY
|
242
230
|
end
|
243
231
|
|
244
232
|
it 'prints the summary' do
|
245
233
|
stub_request(:get, "#{@nspooler_url}/summary")
|
246
|
-
.
|
247
|
-
.to_return(status: 200, body: @status_response_body, headers: {})
|
234
|
+
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
248
235
|
|
249
236
|
summary = NonstandardPooler.summary(false, @nspooler_url)
|
250
237
|
expect(summary).to be_an_instance_of Hash
|
@@ -253,24 +240,23 @@ BODY
|
|
253
240
|
|
254
241
|
describe '#query' do
|
255
242
|
before :each do
|
256
|
-
@query_response_body =
|
257
|
-
{
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
}
|
267
|
-
BODY
|
243
|
+
@query_response_body = <<~BODY
|
244
|
+
{
|
245
|
+
"ok": true,
|
246
|
+
"sol10-11": {
|
247
|
+
"fqdn": "sol10-11.delivery.puppetlabs.net",
|
248
|
+
"os_triple": "solaris-10-sparc",
|
249
|
+
"reserved_by_user": "first.last",
|
250
|
+
"reserved_for_reason": "testing",
|
251
|
+
"hours_left_on_reservation": 29.12
|
252
|
+
}
|
253
|
+
}
|
254
|
+
BODY
|
268
255
|
end
|
269
256
|
|
270
257
|
it 'makes a query about a vm' do
|
271
258
|
stub_request(:get, "#{@nspooler_url}/host/sol10-11")
|
272
|
-
.
|
273
|
-
.to_return(status: 200, body: @query_response_body, headers: {})
|
259
|
+
.to_return(:status => 200, :body => @query_response_body, :headers => {})
|
274
260
|
|
275
261
|
query_req = NonstandardPooler.query(false, @nspooler_url, 'sol10-11')
|
276
262
|
expect(query_req).to be_an_instance_of Hash
|
@@ -285,19 +271,19 @@ BODY
|
|
285
271
|
|
286
272
|
it 'deletes a single existing vm' do
|
287
273
|
stub_request(:delete, "#{@nspooler_url}/host/sol11-7")
|
288
|
-
.with(headers
|
289
|
-
.to_return(status
|
274
|
+
.with(:headers => @auth_token_headers)
|
275
|
+
.to_return(:status => 200, :body => @delete_response_success, :headers => {})
|
290
276
|
|
291
|
-
request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value')
|
277
|
+
request = NonstandardPooler.delete(false, @nspooler_url, 'sol11-7', 'token-value', nil)
|
292
278
|
expect(request['sol11-7']['ok']).to be true
|
293
279
|
end
|
294
280
|
|
295
281
|
it 'does not delete a nonexistant vm' do
|
296
282
|
stub_request(:delete, "#{@nspooler_url}/host/fakehost")
|
297
|
-
.with(headers
|
298
|
-
.to_return(status
|
283
|
+
.with(:headers => @auth_token_headers)
|
284
|
+
.to_return(:status => 401, :body => @delete_response_failure, :headers => {})
|
299
285
|
|
300
|
-
request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value')
|
286
|
+
request = NonstandardPooler.delete(false, @nspooler_url, 'fakehost', 'token-value', nil)
|
301
287
|
expect(request['fakehost']['ok']).to be false
|
302
288
|
end
|
303
289
|
end
|