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