kitchen-vra 2.6.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +22 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +3 -2
- data/README.md +23 -13
- data/Rakefile +6 -15
- data/kitchen-vra.gemspec +23 -22
- data/lib/kitchen/driver/vra.rb +83 -75
- data/lib/kitchen/driver/vra_version.rb +2 -1
- data/spec/spec_helper.rb +7 -6
- data/spec/vra_spec.rb +179 -187
- metadata +54 -29
- data/.rubocop.yml +0 -19
- data/.travis.yml +0 -23
data/spec/vra_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
5
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
@@ -17,33 +18,33 @@
|
|
17
18
|
# limitations under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
21
|
+
require "spec_helper"
|
22
|
+
require "kitchen/driver/vra"
|
23
|
+
require "kitchen/provisioner/dummy"
|
24
|
+
require "kitchen/transport/dummy"
|
25
|
+
require "kitchen/verifier/dummy"
|
25
26
|
|
26
27
|
describe Kitchen::Driver::Vra do
|
27
28
|
let(:logged_output) { StringIO.new }
|
28
29
|
let(:logger) { Logger.new(logged_output) }
|
29
|
-
let(:platform) { Kitchen::Platform.new(name:
|
30
|
+
let(:platform) { Kitchen::Platform.new(name: "fake_platform") }
|
30
31
|
let(:transport) { Kitchen::Transport::Dummy.new }
|
31
32
|
let(:driver) { Kitchen::Driver::Vra.new(config) }
|
32
33
|
|
33
34
|
let(:config) do
|
34
35
|
{
|
35
|
-
base_url:
|
36
|
-
username:
|
37
|
-
password:
|
38
|
-
tenant:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
base_url: "https://vra.corp.local",
|
37
|
+
username: "myuser",
|
38
|
+
password: "mypassword",
|
39
|
+
tenant: "mytenant",
|
40
|
+
project_id: "6ba69375-79d5-42c3-a099-7d32739f71a7",
|
41
|
+
image_mapping: "VRA-nc-lnx-ce8.4-Docker",
|
42
|
+
flavor_mapping: "Small",
|
43
|
+
verify_ssl: true,
|
44
|
+
subtenant_id: "160b473a-0ec9-473d-8156-28dd96c0b6b7",
|
45
|
+
use_dns: false,
|
46
|
+
deployment_name: "test-instance",
|
47
|
+
version: 1,
|
47
48
|
}
|
48
49
|
end
|
49
50
|
|
@@ -52,28 +53,28 @@ describe Kitchen::Driver::Vra do
|
|
52
53
|
logger: logger,
|
53
54
|
transport: transport,
|
54
55
|
platform: platform,
|
55
|
-
to_str:
|
56
|
+
to_str: "instance_str")
|
56
57
|
end
|
57
58
|
|
58
59
|
before do
|
59
60
|
allow(driver).to receive(:instance).and_return(instance)
|
60
61
|
end
|
61
62
|
|
62
|
-
it
|
63
|
+
it "driver API version is 2" do
|
63
64
|
expect(driver.diagnose_plugin[:api_version]).to eq(2)
|
64
65
|
end
|
65
66
|
|
66
|
-
describe
|
67
|
-
it
|
68
|
-
expect(driver.name).to eq(
|
67
|
+
describe "#name" do
|
68
|
+
it "has an overridden name" do
|
69
|
+
expect(driver.name).to eq("vRA")
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
describe
|
73
|
-
context
|
74
|
-
let(:state) { {
|
73
|
+
describe "#create" do
|
74
|
+
context "when the server is already created" do
|
75
|
+
let(:state) { { deployment_id: "48959518-6a0d-46e1-8415-3749696b65f4" } }
|
75
76
|
|
76
|
-
it
|
77
|
+
it "does not submit a catalog request" do
|
77
78
|
expect(driver).not_to receive(:request_server)
|
78
79
|
driver.create(state)
|
79
80
|
end
|
@@ -81,10 +82,10 @@ describe Kitchen::Driver::Vra do
|
|
81
82
|
|
82
83
|
let(:state) { {} }
|
83
84
|
let(:resource) do
|
84
|
-
double(
|
85
|
-
|
86
|
-
name:
|
87
|
-
|
85
|
+
double("server1",
|
86
|
+
deployment_id: "e8706351-cf4c-4c12-acb7-c90cc683b22c",
|
87
|
+
name: "test-server",
|
88
|
+
ip_address: "1.2.3.4",
|
88
89
|
vm?: true)
|
89
90
|
end
|
90
91
|
|
@@ -93,91 +94,91 @@ describe Kitchen::Driver::Vra do
|
|
93
94
|
allow(driver).to receive(:wait_for_server)
|
94
95
|
end
|
95
96
|
|
96
|
-
it
|
97
|
+
it "requests the server" do
|
97
98
|
expect(driver).to receive(:request_server).and_return(resource)
|
98
99
|
driver.create(state)
|
99
100
|
end
|
100
101
|
|
101
|
-
it
|
102
|
+
it "sets the server ID in the state hash" do
|
102
103
|
driver.create(state)
|
103
|
-
expect(state[:
|
104
|
+
expect(state[:deployment_id]).to eq("e8706351-cf4c-4c12-acb7-c90cc683b22c")
|
104
105
|
end
|
105
106
|
|
106
|
-
it
|
107
|
-
allow(driver).to receive(:hostname_for).and_return(
|
107
|
+
it "sets the hostname in the state hash" do
|
108
|
+
allow(driver).to receive(:hostname_for).and_return("test_hostname")
|
108
109
|
driver.create(state)
|
109
|
-
expect(state[:hostname]).to eq(
|
110
|
+
expect(state[:hostname]).to eq("test_hostname")
|
110
111
|
end
|
111
112
|
|
112
|
-
it
|
113
|
+
it "waits for the server to be ready" do
|
113
114
|
expect(driver).to receive(:wait_for_server)
|
114
115
|
driver.create(state)
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
|
-
describe
|
119
|
+
describe "#hostname_for" do
|
119
120
|
let(:server) do
|
120
|
-
double(
|
121
|
-
|
122
|
-
name:
|
123
|
-
|
121
|
+
double("server",
|
122
|
+
deployment_id: "test_id",
|
123
|
+
name: "test_hostname",
|
124
|
+
ip_address: "1.2.3.4",
|
124
125
|
vm?: true)
|
125
126
|
end
|
126
127
|
|
127
|
-
context
|
128
|
+
context "when use_dns is true and dns_suffix is defined" do
|
128
129
|
let(:config) do
|
129
130
|
{
|
130
131
|
use_dns: true,
|
131
|
-
dns_suffix:
|
132
|
+
dns_suffix: "my.com",
|
132
133
|
}
|
133
134
|
end
|
134
135
|
|
135
|
-
it
|
136
|
-
expect(driver.hostname_for(server)).to eq(
|
136
|
+
it "returns the server name with suffix appended" do
|
137
|
+
expect(driver.hostname_for(server)).to eq("test_hostname.my.com")
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
140
|
-
context
|
141
|
+
context "when use_dns is true" do
|
141
142
|
let(:config) { { use_dns: true } }
|
142
143
|
|
143
|
-
it
|
144
|
+
it "raises an exception if the server name is nil" do
|
144
145
|
allow(server).to receive(:name).and_return(nil)
|
145
146
|
expect { driver.hostname_for(server) }.to raise_error(RuntimeError)
|
146
147
|
end
|
147
148
|
|
148
|
-
it
|
149
|
-
expect(driver.hostname_for(server)).to eq(
|
149
|
+
it "returns the server name" do
|
150
|
+
expect(driver.hostname_for(server)).to eq("test_hostname")
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
153
|
-
context
|
154
|
-
it
|
155
|
-
allow(server).to receive(:
|
154
|
+
context "when use_dns is false" do
|
155
|
+
it "falls back to the server name if no IP address exists" do
|
156
|
+
allow(server).to receive(:ip_address).and_return(nil)
|
156
157
|
expect(driver).to receive(:warn)
|
157
|
-
expect(driver.hostname_for(server)).to eq(
|
158
|
+
expect(driver.hostname_for(server)).to eq("test_hostname")
|
158
159
|
end
|
159
160
|
|
160
|
-
it
|
161
|
-
expect(driver.hostname_for(server)).to eq(
|
161
|
+
it "returns the IP address if it exists" do
|
162
|
+
expect(driver.hostname_for(server)).to eq("1.2.3.4")
|
162
163
|
end
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
166
|
-
describe
|
167
|
-
let(:submitted_request) { double(
|
168
|
-
let(:catalog_request) { double(
|
167
|
+
describe "#request_server" do
|
168
|
+
let(:submitted_request) { double("submitted_request") }
|
169
|
+
let(:catalog_request) { double("catalog_request") }
|
169
170
|
let(:resource1) do
|
170
|
-
double(
|
171
|
-
id:
|
172
|
-
name:
|
173
|
-
|
171
|
+
double("server1",
|
172
|
+
id: "e8706351-cf4c-4c12-acb7-c90cc683b22c",
|
173
|
+
name: "server1",
|
174
|
+
ip_address: "1.2.3.4",
|
174
175
|
vm?: true)
|
175
176
|
end
|
176
177
|
let(:resource2) do
|
177
|
-
double(
|
178
|
-
id:
|
179
|
-
name:
|
180
|
-
|
178
|
+
double("server2",
|
179
|
+
id: "9e2364cf-7af4-4b85-93fd-1f03ee2ac865",
|
180
|
+
name: "server2",
|
181
|
+
ip_address: "4.3.2.1",
|
181
182
|
vm?: true)
|
182
183
|
end
|
183
184
|
let(:resources) { [resource1] }
|
@@ -185,63 +186,63 @@ describe Kitchen::Driver::Vra do
|
|
185
186
|
before do
|
186
187
|
allow(driver).to receive(:catalog_request).and_return(catalog_request)
|
187
188
|
allow(catalog_request).to receive(:submit).and_return(submitted_request)
|
188
|
-
allow(submitted_request).to receive(:id).and_return(
|
189
|
+
allow(submitted_request).to receive(:id).and_return("74e26af9-2d2f-4889-a472-95dbcedb70b8")
|
189
190
|
allow(submitted_request).to receive(:resources).and_return(resources)
|
190
191
|
allow(submitted_request).to receive(:failed?).and_return(false)
|
191
192
|
allow(driver).to receive(:wait_for_request).with(submitted_request)
|
192
193
|
end
|
193
194
|
|
194
|
-
it
|
195
|
+
it "submits a catalog request" do
|
195
196
|
expect(driver.catalog_request).to receive(:submit).and_return(submitted_request)
|
196
197
|
driver.request_server
|
197
198
|
end
|
198
199
|
|
199
|
-
it
|
200
|
+
it "waits for the request to complete" do
|
200
201
|
expect(driver).to receive(:wait_for_request).with(submitted_request)
|
201
202
|
driver.request_server
|
202
203
|
end
|
203
204
|
|
204
|
-
it
|
205
|
+
it "raises an exception if the request failed" do
|
205
206
|
allow(submitted_request).to receive(:failed?).and_return(true)
|
206
|
-
allow(submitted_request).to receive(:completion_details).and_return(
|
207
|
+
allow(submitted_request).to receive(:completion_details).and_return("it failed")
|
207
208
|
expect { driver.request_server }.to raise_error(RuntimeError)
|
208
209
|
end
|
209
210
|
|
210
|
-
describe
|
211
|
-
context
|
212
|
-
it
|
211
|
+
describe "getting the server from the request" do
|
212
|
+
context "when only one server is returned" do
|
213
|
+
it "does not raise an exception" do
|
213
214
|
expect { driver.request_server }.not_to raise_error
|
214
215
|
end
|
215
216
|
end
|
216
217
|
|
217
|
-
context
|
218
|
-
it
|
218
|
+
context "when multiple servers are returned" do
|
219
|
+
it "raises an exception" do
|
219
220
|
allow(submitted_request).to receive(:resources).and_return([ resource1, resource2 ])
|
220
221
|
expect { driver.request_server }.to raise_error(RuntimeError)
|
221
222
|
end
|
222
223
|
end
|
223
224
|
|
224
|
-
context
|
225
|
-
it
|
225
|
+
context "when no servers are returned" do
|
226
|
+
it "raises an exception" do
|
226
227
|
allow(submitted_request).to receive(:resources).and_return([])
|
227
228
|
expect { driver.request_server }.to raise_error(RuntimeError)
|
228
229
|
end
|
229
230
|
end
|
230
231
|
end
|
231
232
|
|
232
|
-
it
|
233
|
+
it "returns the the single server resource object" do
|
233
234
|
expect(driver.request_server).to eq(resource1)
|
234
235
|
end
|
235
236
|
end
|
236
237
|
|
237
|
-
describe
|
238
|
+
describe "#wait_for_server" do
|
238
239
|
let(:connection) { instance.transport.connection(state) }
|
239
240
|
let(:state) { {} }
|
240
241
|
let(:resource1) do
|
241
|
-
double(
|
242
|
-
id:
|
243
|
-
name:
|
244
|
-
|
242
|
+
double("server1",
|
243
|
+
id: "test_id",
|
244
|
+
name: "server1",
|
245
|
+
ip_address: "1.2.3.4",
|
245
246
|
vm?: true)
|
246
247
|
end
|
247
248
|
|
@@ -252,58 +253,58 @@ describe Kitchen::Driver::Vra do
|
|
252
253
|
allow(driver).to receive(:error)
|
253
254
|
end
|
254
255
|
|
255
|
-
it
|
256
|
+
it "waits for the server to be ready" do
|
256
257
|
expect(connection).to receive(:wait_until_ready)
|
257
258
|
driver.wait_for_server(state, resource1)
|
258
259
|
end
|
259
260
|
|
260
|
-
context
|
261
|
+
context "when an exception is caught and retries is 0" do
|
261
262
|
let(:config) { { server_ready_retries: 0 } }
|
262
263
|
|
263
|
-
it
|
264
|
+
it "does not sleep and raises an exception" do
|
264
265
|
allow(connection).to receive(:wait_until_ready).and_raise(Timeout::Error)
|
265
266
|
expect(driver).not_to receive(:sleep)
|
266
|
-
expect(driver).to receive(:error).with(
|
267
|
+
expect(driver).to receive(:error).with("Retries exceeded. Destroying server...")
|
267
268
|
expect { driver.wait_for_server(state, resource1) }.to raise_error(Timeout::Error)
|
268
269
|
end
|
269
270
|
end
|
270
271
|
|
271
|
-
context
|
272
|
+
context "when retries is 1 and it errors out twice" do
|
272
273
|
let(:config) { { server_ready_retries: 1 } }
|
273
274
|
|
274
|
-
it
|
275
|
+
it "displays a warning, sleeps once, retries, errors, destroys, and raises" do
|
275
276
|
expect(connection).to receive(:wait_until_ready).twice.and_raise(Timeout::Error)
|
276
|
-
expect(driver).to receive(:warn).once.with(
|
277
|
+
expect(driver).to receive(:warn).once.with("Sleeping 5 seconds and retrying...")
|
277
278
|
expect(driver).to receive(:sleep).once.with(5)
|
278
|
-
expect(driver).to receive(:error).with(
|
279
|
+
expect(driver).to receive(:error).with("Retries exceeded. Destroying server...")
|
279
280
|
expect(driver).to receive(:destroy).with(state)
|
280
281
|
expect { driver.wait_for_server(state, resource1) }.to raise_error(Timeout::Error)
|
281
282
|
end
|
282
283
|
end
|
283
284
|
|
284
|
-
context
|
285
|
+
context "when retries is 2 and it errors out all 3 times" do
|
285
286
|
let(:config) { { server_ready_retries: 2 } }
|
286
287
|
|
287
|
-
it
|
288
|
+
it "displays 2 warnings, sleeps twice, retries, errors, destroys, and raises" do
|
288
289
|
expect(connection).to receive(:wait_until_ready).exactly(3).times.and_raise(Timeout::Error)
|
289
|
-
expect(driver).to receive(:warn).once.with(
|
290
|
-
expect(driver).to receive(:warn).once.with(
|
290
|
+
expect(driver).to receive(:warn).once.with("Sleeping 5 seconds and retrying...")
|
291
|
+
expect(driver).to receive(:warn).once.with("Sleeping 10 seconds and retrying...")
|
291
292
|
expect(driver).to receive(:sleep).once.with(5)
|
292
293
|
expect(driver).to receive(:sleep).once.with(10)
|
293
|
-
expect(driver).to receive(:error).with(
|
294
|
+
expect(driver).to receive(:error).with("Retries exceeded. Destroying server...")
|
294
295
|
expect(driver).to receive(:destroy).with(state)
|
295
296
|
expect { driver.wait_for_server(state, resource1) }.to raise_error(Timeout::Error)
|
296
297
|
end
|
297
298
|
end
|
298
299
|
|
299
|
-
context
|
300
|
+
context "when retries is 5, it errors out the first 2 tries, but works on the 3rd" do
|
300
301
|
let(:config) { { server_ready_retries: 5 } }
|
301
302
|
|
302
|
-
it
|
303
|
+
it "displays 2 warnings, sleeps twice, retries, but does not destroy or raise" do
|
303
304
|
expect(connection).to receive(:wait_until_ready).twice.and_raise(Timeout::Error)
|
304
305
|
expect(connection).to receive(:wait_until_ready).once.and_return(true)
|
305
|
-
expect(driver).to receive(:warn).once.with(
|
306
|
-
expect(driver).to receive(:warn).once.with(
|
306
|
+
expect(driver).to receive(:warn).once.with("Sleeping 5 seconds and retrying...")
|
307
|
+
expect(driver).to receive(:warn).once.with("Sleeping 10 seconds and retrying...")
|
307
308
|
expect(driver).to receive(:sleep).once.with(5)
|
308
309
|
expect(driver).to receive(:sleep).once.with(10)
|
309
310
|
expect(driver).not_to receive(:error)
|
@@ -312,10 +313,10 @@ describe Kitchen::Driver::Vra do
|
|
312
313
|
end
|
313
314
|
end
|
314
315
|
|
315
|
-
context
|
316
|
+
context "when retries is 7, always erroring" do
|
316
317
|
let(:config) { { server_ready_retries: 8 } }
|
317
318
|
|
318
|
-
it
|
319
|
+
it "caps the delays at 30 seconds" do
|
319
320
|
expect(connection).to receive(:wait_until_ready).exactly(9).times.and_raise(Timeout::Error)
|
320
321
|
expect(driver).to receive(:sleep).once.with(5)
|
321
322
|
expect(driver).to receive(:sleep).once.with(10)
|
@@ -328,144 +329,135 @@ describe Kitchen::Driver::Vra do
|
|
328
329
|
end
|
329
330
|
end
|
330
331
|
|
331
|
-
describe
|
332
|
-
let(:
|
333
|
-
let(:state) { {
|
334
|
-
let(:vra_client) { double(
|
335
|
-
let(:
|
336
|
-
let(:destroy_request) { double(
|
332
|
+
describe "#destroy" do
|
333
|
+
let(:deployment_id) { "8c1a833a-5844-4100-b58c-9cab3543c958" }
|
334
|
+
let(:state) { { deployment_id: deployment_id } }
|
335
|
+
let(:vra_client) { double("vra_client") }
|
336
|
+
let(:deployments) { double("resources") }
|
337
|
+
let(:destroy_request) { double("destroy_request") }
|
337
338
|
let(:resource) do
|
338
|
-
double(
|
339
|
-
|
340
|
-
name:
|
341
|
-
|
339
|
+
double("server1",
|
340
|
+
deployment_id: deployment_id,
|
341
|
+
name: "server1",
|
342
|
+
ip_address: "5.6.7.8",
|
342
343
|
vm?: true)
|
343
344
|
end
|
344
345
|
|
345
346
|
before do
|
346
347
|
allow(driver).to receive(:vra_client).and_return(vra_client)
|
347
348
|
allow(driver).to receive(:wait_for_request).with(destroy_request)
|
348
|
-
allow(vra_client).to receive(:
|
349
|
-
allow(
|
349
|
+
allow(vra_client).to receive(:deployments).and_return(deployments)
|
350
|
+
allow(deployments).to receive(:by_id).and_return(resource)
|
350
351
|
allow(resource).to receive(:destroy).and_return(destroy_request)
|
351
|
-
allow(destroy_request).to receive(:id).and_return(
|
352
|
+
allow(destroy_request).to receive(:id).and_return("6da65982-7c33-4e6e-b346-fdf4bcbf01ab")
|
352
353
|
end
|
353
354
|
|
354
|
-
context
|
355
|
+
context "when the resource is not created" do
|
355
356
|
let(:state) { {} }
|
356
|
-
it
|
357
|
-
expect(vra_client.
|
357
|
+
it "does not look up the resource if no resource ID exists" do
|
358
|
+
expect(vra_client.deployments).not_to receive(:by_id)
|
358
359
|
driver.destroy(state)
|
359
360
|
end
|
360
361
|
end
|
361
362
|
|
362
|
-
it
|
363
|
-
expect(vra_client.
|
363
|
+
it "looks up the resource record" do
|
364
|
+
expect(vra_client.deployments).to receive(:by_id).with(deployment_id).and_return(resource)
|
364
365
|
driver.destroy(state)
|
365
366
|
end
|
366
367
|
|
367
|
-
context
|
368
|
-
it
|
369
|
-
allow(vra_client.
|
368
|
+
context "when the resource record cannot be found" do
|
369
|
+
it "does not raise an exception" do
|
370
|
+
allow(vra_client.deployments).to receive(:by_id).with(deployment_id).and_raise(Vra::Exception::NotFound)
|
370
371
|
expect { driver.destroy(state) }.not_to raise_error
|
371
372
|
end
|
372
373
|
end
|
373
374
|
|
374
|
-
describe
|
375
|
-
context
|
376
|
-
it
|
375
|
+
describe "creating the destroy request" do
|
376
|
+
context "when the destroy method or server is not found" do
|
377
|
+
it "does not raise an exception" do
|
377
378
|
allow(resource).to receive(:destroy).and_raise(Vra::Exception::NotFound)
|
378
379
|
expect { driver.destroy(state) }.not_to raise_error
|
379
380
|
end
|
380
381
|
end
|
381
382
|
|
382
|
-
it
|
383
|
+
it "calls #destroy on the server" do
|
383
384
|
expect(resource).to receive(:destroy).and_return(destroy_request)
|
384
385
|
driver.destroy(state)
|
385
386
|
end
|
386
387
|
end
|
387
388
|
|
388
|
-
it
|
389
|
+
it "waits for the destroy request to succeed" do
|
389
390
|
expect(driver).to receive(:wait_for_request).with(destroy_request)
|
390
391
|
driver.destroy(state)
|
391
392
|
end
|
392
393
|
end
|
393
394
|
|
394
|
-
describe
|
395
|
-
let(:catalog_request) { double(
|
396
|
-
let(:vra_client) { double(
|
397
|
-
let(:catalog) { double(
|
395
|
+
describe "#catalog_request" do
|
396
|
+
let(:catalog_request) { double("catalog_request") }
|
397
|
+
let(:vra_client) { double("vra_client") }
|
398
|
+
let(:catalog) { double("catalog") }
|
398
399
|
before do
|
399
400
|
allow(driver).to receive(:vra_client).and_return(vra_client)
|
400
401
|
allow(vra_client).to receive(:catalog).and_return(catalog)
|
401
402
|
allow(catalog).to receive(:request).and_return(catalog_request)
|
402
|
-
|
403
|
+
%i{subtenant_id= set_parameter}.each do |method|
|
403
404
|
allow(catalog_request).to receive(method)
|
404
405
|
end
|
405
406
|
end
|
406
407
|
|
407
|
-
it
|
408
|
+
it "creates a catalog_request" do
|
408
409
|
expect(vra_client.catalog).to receive(:request).and_return(catalog_request)
|
409
410
|
driver.catalog_request
|
410
411
|
end
|
411
412
|
|
412
|
-
|
413
|
-
expect(catalog_request).to receive(:cpus=).with(config[:cpus])
|
414
|
-
expect(catalog_request).to receive(:memory=).with(config[:memory])
|
415
|
-
expect(catalog_request).to receive(:requested_for=).with(config[:requested_for])
|
416
|
-
expect(catalog_request).to receive(:lease_days=).with(config[:lease_days])
|
417
|
-
expect(catalog_request).to receive(:notes=).with(config[:notes])
|
418
|
-
expect(catalog_request).to receive(:subtenant_id=).with(config[:subtenant_id])
|
419
|
-
driver.catalog_request
|
420
|
-
end
|
421
|
-
|
422
|
-
context 'when option parameters are not supplied' do
|
413
|
+
context "when option parameters are not supplied" do
|
423
414
|
let(:config) do
|
424
415
|
{
|
425
|
-
base_url:
|
426
|
-
username:
|
427
|
-
password:
|
428
|
-
tenant:
|
429
|
-
verify_ssl:
|
430
|
-
|
431
|
-
|
432
|
-
|
416
|
+
base_url: "https://vra.corp.local",
|
417
|
+
username: "myuser",
|
418
|
+
password: "mypassword",
|
419
|
+
tenant: "mytenant",
|
420
|
+
verify_ssl: true,
|
421
|
+
project_id: "6ba69375-79d5-42c3-a099-7d32739f71a7",
|
422
|
+
image_mapping: "VRA-nc-lnx-ce8.4-Docker",
|
423
|
+
flavor_mapping: "Small",
|
424
|
+
version: 1,
|
433
425
|
}
|
434
426
|
end
|
435
427
|
|
436
|
-
it
|
437
|
-
expect(catalog_request).not_to receive(:lease_days=)
|
438
|
-
expect(catalog_request).not_to receive(:notes=)
|
428
|
+
it "does not attempt to set params on the catalog_request" do
|
439
429
|
expect(catalog_request).not_to receive(:subtenant_id=)
|
440
430
|
driver.catalog_request
|
441
431
|
end
|
442
432
|
end
|
443
433
|
|
444
|
-
context
|
434
|
+
context "when extra parameters are set" do
|
445
435
|
let(:config) do
|
446
436
|
{
|
447
|
-
base_url:
|
448
|
-
username:
|
449
|
-
password:
|
450
|
-
tenant:
|
451
|
-
verify_ssl:
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
437
|
+
base_url: "https://vra.corp.local",
|
438
|
+
username: "myuser",
|
439
|
+
password: "mypassword",
|
440
|
+
tenant: "mytenant",
|
441
|
+
verify_ssl: true,
|
442
|
+
project_id: "6ba69375-79d5-42c3-a099-7d32739f71a7",
|
443
|
+
image_mapping: "VRA-nc-lnx-ce8.4-Docker",
|
444
|
+
flavor_mapping: "Small",
|
445
|
+
version: 1,
|
446
|
+
extra_parameters: { "key1" => { type: "string", value: "value1" },
|
447
|
+
"key2" => { type: "integer", value: 123 } },
|
456
448
|
}
|
457
449
|
end
|
458
450
|
|
459
|
-
it
|
460
|
-
expect(catalog_request).to receive(:
|
461
|
-
expect(catalog_request).to receive(:
|
451
|
+
it "sets extra parmeters" do
|
452
|
+
expect(catalog_request).to receive(:set_parameters).with("key1", type: "string", value: "value1")
|
453
|
+
expect(catalog_request).to receive(:set_parameters).with("key2", type: "integer", value: 123)
|
462
454
|
driver.catalog_request
|
463
455
|
end
|
464
456
|
end
|
465
457
|
end
|
466
458
|
|
467
|
-
describe
|
468
|
-
it
|
459
|
+
describe "#vra_client" do
|
460
|
+
it "sets up a client object" do
|
469
461
|
expect(Vra::Client).to receive(:new).with(base_url: config[:base_url],
|
470
462
|
username: config[:username],
|
471
463
|
password: config[:password],
|
@@ -475,15 +467,15 @@ describe Kitchen::Driver::Vra do
|
|
475
467
|
end
|
476
468
|
end
|
477
469
|
|
478
|
-
describe
|
470
|
+
describe "#wait_for_request" do
|
479
471
|
before do
|
480
472
|
# don't actually sleep
|
481
473
|
allow(driver).to receive(:sleep)
|
482
474
|
end
|
483
475
|
|
484
|
-
context
|
485
|
-
it
|
486
|
-
request = double(
|
476
|
+
context "when the requests completes normally, 3 loops" do
|
477
|
+
it "only refreshes the request 3 times" do
|
478
|
+
request = double("request")
|
487
479
|
allow(request).to receive(:status)
|
488
480
|
allow(request).to receive(:completed?).exactly(3).times.and_return(false, false, true)
|
489
481
|
expect(request).to receive(:refresh).exactly(3).times
|
@@ -492,9 +484,9 @@ describe Kitchen::Driver::Vra do
|
|
492
484
|
end
|
493
485
|
end
|
494
486
|
|
495
|
-
context
|
496
|
-
it
|
497
|
-
request = double(
|
487
|
+
context "when the request is completed on the first loop" do
|
488
|
+
it "only refreshes the request 1 time" do
|
489
|
+
request = double("request")
|
498
490
|
allow(request).to receive(:status)
|
499
491
|
allow(request).to receive(:completed?).once.and_return(true)
|
500
492
|
expect(request).to receive(:refresh).once
|
@@ -503,17 +495,17 @@ describe Kitchen::Driver::Vra do
|
|
503
495
|
end
|
504
496
|
end
|
505
497
|
|
506
|
-
context
|
507
|
-
it
|
508
|
-
request = double(
|
498
|
+
context "when the timeout is exceeded" do
|
499
|
+
it "prints a warning and exits" do
|
500
|
+
request = double("request")
|
509
501
|
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
|
510
502
|
expect { driver.wait_for_request(request) }.to raise_error(Timeout::Error)
|
511
503
|
end
|
512
504
|
end
|
513
505
|
|
514
|
-
context
|
515
|
-
it
|
516
|
-
request = double(
|
506
|
+
context "when a non-timeout exception is raised" do
|
507
|
+
it "raises the original exception" do
|
508
|
+
request = double("request")
|
517
509
|
allow(request).to receive(:refresh).and_raise(RuntimeError)
|
518
510
|
expect { driver.wait_for_request(request) }.to raise_error(RuntimeError)
|
519
511
|
end
|