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
@@ -1,224 +1,244 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require_relative '../../lib/vmfloaty/pooler'
|
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 '#list' do
|
10
12
|
before :each do
|
11
|
-
@list_response_body =
|
13
|
+
@list_response_body = '["debian-7-i386","debian-7-x86_64","centos-7-x86_64"]'
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
15
|
-
stub_request(:get, "#{@vmpooler_url}/vm")
|
16
|
-
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
16
|
+
it 'returns a hash with operating systems from the pooler' do
|
17
|
+
stub_request(:get, "#{@vmpooler_url}/vm")
|
18
|
+
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
17
19
|
|
18
20
|
list = Pooler.list(false, @vmpooler_url, nil)
|
19
21
|
expect(list).to be_an_instance_of Array
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
23
|
-
stub_request(:get, "#{@vmpooler_url}/vm")
|
24
|
-
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
24
|
+
it 'filters operating systems based on the filter param' do
|
25
|
+
stub_request(:get, "#{@vmpooler_url}/vm")
|
26
|
+
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
25
27
|
|
26
|
-
list = Pooler.list(false, @vmpooler_url,
|
28
|
+
list = Pooler.list(false, @vmpooler_url, 'deb')
|
27
29
|
expect(list).to be_an_instance_of Array
|
28
30
|
expect(list.size).to equal 2
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
32
|
-
stub_request(:get, "#{@vmpooler_url}/vm")
|
33
|
-
to_return(:status => 200, :body => @list_response_body, :headers => {})
|
33
|
+
it 'returns nothing if the filter does not match' do
|
34
|
+
stub_request(:get, "#{@vmpooler_url}/vm")
|
35
|
+
.to_return(:status => 200, :body => @list_response_body, :headers => {})
|
34
36
|
|
35
|
-
list = Pooler.list(false, @vmpooler_url,
|
37
|
+
list = Pooler.list(false, @vmpooler_url, 'windows')
|
36
38
|
expect(list).to be_an_instance_of Array
|
37
39
|
expect(list.size).to equal 0
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
describe
|
43
|
+
describe '#retrieve' do
|
42
44
|
before :each do
|
43
|
-
@retrieve_response_body_single =
|
44
|
-
@retrieve_response_body_double =
|
45
|
+
@retrieve_response_body_single = '{"ok":true,"debian-7-i386":{"hostname":"fq6qlpjlsskycq6"}}'
|
46
|
+
@retrieve_response_body_double = '{"ok":true,"debian-7-i386":{"hostname":["sc0o4xqtodlul5w","4m4dkhqiufnjmxy"]},"centos-7-x86_64":{"hostname":"zb91y9qbrbf6d3q"}}'
|
45
47
|
end
|
46
48
|
|
47
|
-
it
|
48
|
-
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
|
49
|
-
with(:headers => {
|
50
|
-
to_return(:status => 401, :body =>
|
49
|
+
it 'raises an AuthError if the token is invalid' do
|
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
53
|
|
52
54
|
vm_hash = {}
|
53
55
|
vm_hash['debian-7-i386'] = 1
|
54
|
-
expect{ Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url) }.to raise_error(AuthError)
|
56
|
+
expect { Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {}) }.to raise_error(AuthError)
|
55
57
|
end
|
56
58
|
|
57
|
-
it
|
58
|
-
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386")
|
59
|
-
with(:headers => {
|
60
|
-
to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
59
|
+
it 'retrieves a single vm with a token' do
|
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
63
|
|
62
64
|
vm_hash = {}
|
63
65
|
vm_hash['debian-7-i386'] = 1
|
64
|
-
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url)
|
66
|
+
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {})
|
65
67
|
expect(vm_req).to be_an_instance_of Hash
|
66
|
-
expect(vm_req[
|
67
|
-
expect(vm_req[
|
68
|
+
expect(vm_req['ok']).to equal true
|
69
|
+
expect(vm_req['debian-7-i386']['hostname']).to eq 'fq6qlpjlsskycq6'
|
68
70
|
end
|
69
71
|
|
70
|
-
it
|
71
|
-
stub_request(:post, "#{@vmpooler_url}/vm/debian-7-i386+debian-7-i386+centos-7-x86_64")
|
72
|
-
with(:headers => {
|
73
|
-
to_return(:status => 200, :body => @retrieve_response_body_double, :headers => {})
|
72
|
+
it 'retrieves a multiple vms with a token' do
|
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
76
|
|
75
77
|
vm_hash = {}
|
76
78
|
vm_hash['debian-7-i386'] = 2
|
77
79
|
vm_hash['centos-7-x86_64'] = 1
|
78
|
-
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url)
|
80
|
+
vm_req = Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {})
|
79
81
|
expect(vm_req).to be_an_instance_of Hash
|
80
|
-
expect(vm_req[
|
81
|
-
expect(vm_req[
|
82
|
-
expect(vm_req[
|
83
|
-
expect(vm_req[
|
82
|
+
expect(vm_req['ok']).to equal true
|
83
|
+
expect(vm_req['debian-7-i386']['hostname']).to be_an_instance_of Array
|
84
|
+
expect(vm_req['debian-7-i386']['hostname']).to eq %w[sc0o4xqtodlul5w 4m4dkhqiufnjmxy]
|
85
|
+
expect(vm_req['centos-7-x86_64']['hostname']).to eq 'zb91y9qbrbf6d3q'
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with ondemand provisioning' do
|
89
|
+
let(:ondemand_response) { '{"ok":true,"request_id":"1234"}' }
|
90
|
+
it 'retreives the vm with a token' do
|
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 => {})
|
94
|
+
|
95
|
+
stub_request(:get, "#{@vmpooler_url}/ondemandvm/1234")
|
96
|
+
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
97
|
+
|
98
|
+
vm_hash = {}
|
99
|
+
vm_hash['debian-7-i386'] = 1
|
100
|
+
Pooler.retrieve(false, vm_hash, 'mytokenfile', @vmpooler_url, 'user', {}, true)
|
101
|
+
vm_req = Pooler.check_ondemandvm(false, '1234', @vmpooler_url)
|
102
|
+
expect(vm_req).to be_an_instance_of Hash
|
103
|
+
expect(vm_req['ok']).to equal true
|
104
|
+
expect(vm_req['debian-7-i386']['hostname']).to eq 'fq6qlpjlsskycq6'
|
105
|
+
end
|
84
106
|
end
|
85
107
|
end
|
86
108
|
|
87
|
-
describe
|
109
|
+
describe '#modify' do
|
88
110
|
before :each do
|
89
|
-
@modify_response_body_success =
|
90
|
-
@modify_response_body_fail =
|
111
|
+
@modify_response_body_success = '{"ok":true}'
|
112
|
+
@modify_response_body_fail = '{"ok":false}'
|
91
113
|
end
|
92
114
|
|
93
|
-
it
|
94
|
-
expect{ Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, {}) }.to raise_error(TokenError)
|
115
|
+
it 'raises a TokenError if token provided is nil' do
|
116
|
+
expect { Pooler.modify(false, @vmpooler_url, 'myfakehost', nil, {}) }.to raise_error(TokenError)
|
95
117
|
end
|
96
118
|
|
97
|
-
it
|
119
|
+
it 'modifies the TTL of a vm' do
|
98
120
|
modify_hash = { :lifetime => 12 }
|
99
|
-
stub_request(:put, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
100
|
-
with(:body
|
101
|
-
|
102
|
-
to_return(:status => 200, :body => @modify_response_body_success, :headers => {})
|
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 => {})
|
103
125
|
|
104
126
|
modify_req = Pooler.modify(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', modify_hash)
|
105
|
-
expect(modify_req[
|
127
|
+
expect(modify_req['ok']).to be true
|
106
128
|
end
|
107
129
|
end
|
108
130
|
|
109
|
-
describe
|
131
|
+
describe '#delete' do
|
110
132
|
before :each do
|
111
|
-
@delete_response_body_success =
|
112
|
-
@delete_response = {
|
133
|
+
@delete_response_body_success = '{"ok":true}'
|
134
|
+
@delete_response = { 'fq6qlpjlsskycq6' => { 'ok' => true } }
|
113
135
|
end
|
114
136
|
|
115
|
-
it
|
116
|
-
stub_request(:delete, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
117
|
-
with(:headers => {
|
118
|
-
to_return(:status => 200, :body => @delete_response_body_success, :headers => {})
|
137
|
+
it 'deletes a specified vm' do
|
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 => {})
|
119
141
|
|
120
|
-
expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile')).to eq @delete_response
|
142
|
+
expect(Pooler.delete(false, @vmpooler_url, ['fq6qlpjlsskycq6'], 'mytokenfile', nil)).to eq @delete_response
|
121
143
|
end
|
122
144
|
|
123
|
-
it
|
124
|
-
expect{ Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil) }.to raise_error(TokenError)
|
145
|
+
it 'raises a token error if no token provided' do
|
146
|
+
expect { Pooler.delete(false, @vmpooler_url, ['myfakehost'], nil, nil) }.to raise_error(TokenError)
|
125
147
|
end
|
126
148
|
end
|
127
149
|
|
128
|
-
describe
|
150
|
+
describe '#status' do
|
129
151
|
before :each do
|
130
|
-
#smaller version
|
131
|
-
@status_response_body =
|
152
|
+
# smaller version
|
153
|
+
@status_response_body = '{"capacity":{"current":716,"total":717,"percent": 99.9},"status":{"ok":true,"message":"Battle station fully armed and operational."}}'
|
132
154
|
end
|
133
155
|
|
134
|
-
it
|
135
|
-
stub_request(:get, "#{@vmpooler_url}/status")
|
136
|
-
|
137
|
-
to_return(:status => 200, :body => @status_response_body, :headers => {})
|
156
|
+
it 'prints the status' do
|
157
|
+
stub_request(:get, "#{@vmpooler_url}/status")
|
158
|
+
.to_return(:status => 200, :body => @status_response_body, :headers => {})
|
138
159
|
|
139
160
|
status = Pooler.status(false, @vmpooler_url)
|
140
161
|
expect(status).to be_an_instance_of Hash
|
141
162
|
end
|
142
163
|
end
|
143
164
|
|
144
|
-
describe
|
165
|
+
describe '#summary' do
|
145
166
|
before :each do
|
146
|
-
@status_response_body =
|
167
|
+
@status_response_body = ''
|
147
168
|
|
148
|
-
it
|
169
|
+
it 'prints the summary' do
|
149
170
|
end
|
150
171
|
end
|
151
172
|
end
|
152
173
|
|
153
|
-
describe
|
174
|
+
describe '#query' do
|
154
175
|
before :each do
|
155
|
-
@query_response_body =
|
176
|
+
@query_response_body = '{"ok": true,"fq6qlpjlsskycq6":{"template":"debian-7-x86_64","lifetime": 2,"running": 0.08,"state":"running","snapshots":["n4eb4kdtp7rwv4x158366vd9jhac8btq" ],"domain": "delivery.puppetlabs.net"}}'
|
156
177
|
end
|
157
178
|
|
158
|
-
it
|
159
|
-
stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
160
|
-
|
161
|
-
to_return(:status => 200, :body => @query_response_body, :headers => {})
|
179
|
+
it 'makes a query about a vm' do
|
180
|
+
stub_request(:get, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6")
|
181
|
+
.to_return(:status => 200, :body => @query_response_body, :headers => {})
|
162
182
|
|
163
183
|
query_req = Pooler.query(false, @vmpooler_url, 'fq6qlpjlsskycq6')
|
164
184
|
expect(query_req).to be_an_instance_of Hash
|
165
185
|
end
|
166
186
|
end
|
167
187
|
|
168
|
-
describe
|
188
|
+
describe '#snapshot' do
|
169
189
|
before :each do
|
170
|
-
@snapshot_response_body =
|
190
|
+
@snapshot_response_body = '{"ok":true}'
|
171
191
|
end
|
172
192
|
|
173
|
-
it
|
174
|
-
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot")
|
175
|
-
with(:headers => {
|
176
|
-
to_return(:status => 200, :body => @snapshot_response_body, :headers => {})
|
193
|
+
it 'makes a snapshot for a single vm' do
|
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 => {})
|
177
197
|
|
178
198
|
snapshot_req = Pooler.snapshot(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile')
|
179
|
-
expect(snapshot_req[
|
199
|
+
expect(snapshot_req['ok']).to be true
|
180
200
|
end
|
181
201
|
end
|
182
202
|
|
183
|
-
describe
|
203
|
+
describe '#revert' do
|
184
204
|
before :each do
|
185
|
-
@revert_response_body =
|
205
|
+
@revert_response_body = '{"ok":true}'
|
186
206
|
end
|
187
207
|
|
188
|
-
it
|
189
|
-
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/snapshot/dAfewKNfaweLKNve")
|
190
|
-
with(:headers => {
|
191
|
-
to_return(:status => 200, :body => @revert_response_body, :headers => {})
|
208
|
+
it 'makes a request to revert a vm from a snapshot' do
|
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 => {})
|
192
212
|
|
193
213
|
revert_req = Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 'dAfewKNfaweLKNve')
|
194
|
-
expect(revert_req[
|
214
|
+
expect(revert_req['ok']).to be true
|
195
215
|
end
|
196
216
|
|
197
217
|
it "doesn't make a request to revert a vm if snapshot is not provided" do
|
198
|
-
expect{ Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError,
|
218
|
+
expect { Pooler.revert(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', nil) }.to raise_error(RuntimeError, 'Snapshot SHA provided was nil, could not revert fq6qlpjlsskycq6')
|
199
219
|
end
|
200
220
|
|
201
|
-
it
|
202
|
-
expect{ Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError)
|
221
|
+
it 'raises a TokenError if no token was provided' do
|
222
|
+
expect { Pooler.revert(false, @vmpooler_url, 'myfakehost', nil, 'shaaaaaaa') }.to raise_error(TokenError)
|
203
223
|
end
|
204
224
|
end
|
205
225
|
|
206
|
-
describe
|
226
|
+
describe '#disk' do
|
207
227
|
before :each do
|
208
|
-
@disk_response_body_success =
|
209
|
-
@disk_response_body_fail =
|
228
|
+
@disk_response_body_success = '{"ok":true}'
|
229
|
+
@disk_response_body_fail = '{"ok":false}'
|
210
230
|
end
|
211
231
|
|
212
|
-
it
|
213
|
-
stub_request(:post, "#{@vmpooler_url}/vm/fq6qlpjlsskycq6/disk/12")
|
214
|
-
with(:headers => {
|
232
|
+
it 'makes a request to extend disk space of a vm' do
|
233
|
+
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 => {})
|
215
235
|
|
216
236
|
disk_req = Pooler.disk(false, @vmpooler_url, 'fq6qlpjlsskycq6', 'mytokenfile', 12)
|
217
|
-
expect(disk_req[
|
237
|
+
expect(disk_req['ok']).to be true
|
218
238
|
end
|
219
239
|
|
220
|
-
it
|
221
|
-
expect{ Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError)
|
240
|
+
it 'raises a TokenError if no token was provided' do
|
241
|
+
expect { Pooler.disk(false, @vmpooler_url, 'myfakehost', nil, 12) }.to raise_error(TokenError)
|
222
242
|
end
|
223
243
|
end
|
224
244
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../../lib/vmfloaty/service'
|
2
4
|
|
3
5
|
describe Service do
|
4
|
-
|
5
6
|
describe '#initialize' do
|
6
7
|
it 'store configuration options' do
|
7
8
|
options = MockOptions.new({})
|
8
|
-
config = {'url' => 'http://example.url'}
|
9
|
+
config = { 'url' => 'http://example.url' }
|
9
10
|
service = Service.new(options, config)
|
10
11
|
expect(service.config).to include config
|
11
12
|
end
|
@@ -15,9 +16,9 @@ describe Service do
|
|
15
16
|
it 'prompts the user for their password and retrieves a token' do
|
16
17
|
config = { 'user' => 'first.last', 'url' => 'http://default.url' }
|
17
18
|
service = Service.new(MockOptions.new, config)
|
18
|
-
allow(STDOUT).to receive(:puts).with('Enter your
|
19
|
+
allow(STDOUT).to receive(:puts).with('Enter your http://default.url service password:')
|
19
20
|
allow(Commander::UI).to(receive(:password)
|
20
|
-
.with('Enter your
|
21
|
+
.with('Enter your http://default.url service password:', '*')
|
21
22
|
.and_return('hunter2'))
|
22
23
|
allow(Auth).to(receive(:get_token)
|
23
24
|
.with(nil, config['url'], config['user'], 'hunter2')
|
@@ -28,11 +29,11 @@ describe Service do
|
|
28
29
|
it 'prompts the user for their username and password if the username is unknown' do
|
29
30
|
config = { 'url' => 'http://default.url' }
|
30
31
|
service = Service.new(MockOptions.new({}), config)
|
31
|
-
allow(STDOUT).to receive(:puts).with 'Enter your
|
32
|
+
allow(STDOUT).to receive(:puts).with 'Enter your http://default.url service username:'
|
32
33
|
allow(STDOUT).to receive(:puts).with "\n"
|
33
34
|
allow(STDIN).to receive(:gets).and_return('first.last')
|
34
35
|
allow(Commander::UI).to(receive(:password)
|
35
|
-
.with('Enter your
|
36
|
+
.with('Enter your http://default.url service password:', '*')
|
36
37
|
.and_return('hunter2'))
|
37
38
|
allow(Auth).to(receive(:get_token)
|
38
39
|
.with(nil, config['url'], 'first.last', 'hunter2')
|
@@ -43,31 +44,31 @@ describe Service do
|
|
43
44
|
|
44
45
|
describe '#delete_token' do
|
45
46
|
it 'deletes a token' do
|
46
|
-
service = Service.new(MockOptions.new,
|
47
|
+
service = Service.new(MockOptions.new, 'user' => 'first.last', 'url' => 'http://default.url')
|
47
48
|
allow(Commander::UI).to(receive(:password)
|
48
|
-
.with('Enter your
|
49
|
+
.with('Enter your http://default.url service password:', '*')
|
49
50
|
.and_return('hunter2'))
|
50
51
|
allow(Auth).to(receive(:delete_token)
|
51
52
|
.with(nil, 'http://default.url', 'first.last', 'hunter2', 'token-value')
|
52
53
|
.and_return('ok' => true))
|
53
|
-
expect(service.delete_token(nil, 'token-value')).to eql(
|
54
|
+
expect(service.delete_token(nil, 'token-value')).to eql('ok' => true)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
58
|
describe '#token_status' do
|
58
59
|
it 'reports the status of a token' do
|
59
60
|
config = {
|
60
|
-
|
61
|
-
|
61
|
+
'user' => 'first.last',
|
62
|
+
'url' => 'http://default.url',
|
62
63
|
}
|
63
64
|
options = MockOptions.new('token' => 'token-value')
|
64
65
|
service = Service.new(options, config)
|
65
66
|
status = {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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' => [],
|
71
72
|
}
|
72
73
|
allow(Auth).to(receive(:token_status)
|
73
74
|
.with(nil, config['url'], 'token-value')
|
@@ -75,5 +76,4 @@ describe Service do
|
|
75
76
|
expect(service.token_status(nil, 'token-value')).to eql(status)
|
76
77
|
end
|
77
78
|
end
|
78
|
-
|
79
79
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'vmfloaty/ssh'
|
5
|
+
|
6
|
+
class ServiceStub
|
7
|
+
def retrieve(_verbose, os_types, _use_token)
|
8
|
+
if os_types.keys[0] == 'abs_host_string'
|
9
|
+
return {
|
10
|
+
os_types.keys[0] => { 'hostname' => ['abs-hostname.delivery.puppetlabs.net'] },
|
11
|
+
'ok' => true,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
os_types.keys[0] => { 'hostname' => 'vmpooler-hostname' },
|
17
|
+
'domain' => 'delivery.puppetlabs.net',
|
18
|
+
'ok' => true,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def type
|
23
|
+
return 'abs' if os_types == 'abs_host_string'
|
24
|
+
return 'vmpooler' if os_types == 'vmpooler_host_string'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Ssh do
|
29
|
+
before :each do
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'gets a hostname string for abs' do
|
33
|
+
verbose = false
|
34
|
+
service = ServiceStub.new
|
35
|
+
host_os = 'abs_host_string'
|
36
|
+
use_token = false
|
37
|
+
cmd = Ssh.command_string(verbose, service, host_os, use_token)
|
38
|
+
expect(cmd).to match(/ssh root@abs-hostname.delivery.puppetlabs.net/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'gets a hostname string for vmpooler' do
|
42
|
+
verbose = false
|
43
|
+
service = ServiceStub.new
|
44
|
+
host_os = 'vmpooler_host_string'
|
45
|
+
use_token = false
|
46
|
+
cmd = Ssh.command_string(verbose, service, host_os, use_token)
|
47
|
+
expect(cmd).to match(/ssh root@vmpooler-hostname.delivery.puppetlabs.net/)
|
48
|
+
end
|
49
|
+
end
|