vmware-vra 2.7.0 → 3.0.1
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/.gitignore +3 -1
- data/CHANGELOG.md +27 -1
- data/README.md +91 -141
- data/Rakefile +1 -12
- data/lib/vra/catalog.rb +39 -8
- data/lib/vra/catalog_base.rb +62 -0
- data/lib/vra/catalog_item.rb +29 -75
- data/lib/vra/catalog_source.rb +116 -0
- data/lib/vra/catalog_type.rb +56 -0
- data/lib/vra/client.rb +72 -53
- data/lib/vra/deployment.rb +155 -0
- data/lib/vra/deployment_request.rb +117 -0
- data/lib/vra/{resources.rb → deployments.rb} +26 -17
- data/lib/vra/exceptions.rb +2 -2
- data/lib/vra/http.rb +20 -7
- data/lib/vra/request.rb +28 -36
- data/lib/vra/request_parameters.rb +12 -10
- data/lib/vra/resource.rb +33 -203
- data/lib/vra/version.rb +2 -2
- data/lib/vra.rb +15 -12
- data/spec/catalog_item_spec.rb +64 -222
- data/spec/catalog_source_spec.rb +178 -0
- data/spec/catalog_spec.rb +112 -72
- data/spec/catalog_type_spec.rb +114 -0
- data/spec/client_spec.rb +287 -228
- data/spec/deployment_request_spec.rb +192 -0
- data/spec/deployment_spec.rb +227 -0
- data/spec/deployments_spec.rb +80 -0
- data/spec/fixtures/resource/sample_catalog_item.json +18 -0
- data/spec/fixtures/resource/sample_catalog_item_2.json +18 -0
- data/spec/fixtures/resource/sample_catalog_source.json +20 -0
- data/spec/fixtures/resource/sample_catalog_type.json +49 -0
- data/spec/fixtures/resource/sample_dep_actions.json +58 -0
- data/spec/fixtures/resource/sample_dep_request.json +19 -0
- data/spec/fixtures/resource/sample_dep_resource.json +112 -0
- data/spec/fixtures/resource/sample_deployment.json +26 -0
- data/spec/fixtures/resource/sample_entitlements.json +25 -0
- data/spec/http_spec.rb +63 -61
- data/spec/request_spec.rb +62 -68
- data/spec/resource_spec.rb +71 -390
- data/spec/spec_helper.rb +10 -4
- data/vmware-vra.gemspec +2 -4
- metadata +42 -32
- data/.travis.yml +0 -14
- data/lib/vra/catalog_request.rb +0 -127
- data/lib/vra/requests.rb +0 -41
- data/spec/catalog_request_spec.rb +0 -265
- data/spec/requests_spec.rb +0 -60
- data/spec/resources_spec.rb +0 -71
data/spec/resource_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,463 +17,144 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
|
23
|
-
shared_examples_for "a resource action" do |action_method, action_name|
|
24
|
-
context "when the action is available" do
|
25
|
-
it "calls gets the action ID and submits the request" do
|
26
|
-
expect(resource).to receive(:action_id_by_name).with(action_name).and_return("action-123")
|
27
|
-
expect(resource).to receive(:submit_action_request).with("action-123")
|
28
|
-
resource.send(action_method)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when the action is not available" do
|
33
|
-
it "raises an exception" do
|
34
|
-
expect(resource).to receive(:action_id_by_name).with(action_name).and_return nil
|
35
|
-
expect { resource.send(action_method) }.to raise_error(Vra::Exception::NotFound)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'ffi_yajl'
|
39
22
|
|
40
23
|
describe Vra::Resource do
|
41
24
|
let(:client) do
|
42
|
-
Vra::Client.new(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
let(:resource_id) { "31a7badc-6562-458d-84f3-ec58d74a6953" }
|
49
|
-
let(:vm_payload) do
|
50
|
-
FFI_Yajl::Parser.parse(File.read(File.join(File.dirname(__FILE__),
|
51
|
-
"fixtures",
|
52
|
-
"resource",
|
53
|
-
"vm_resource.json")))
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:vm_payload_no_ops) do
|
57
|
-
FFI_Yajl::Parser.parse(File.read(File.join(File.dirname(__FILE__),
|
58
|
-
"fixtures",
|
59
|
-
"resource",
|
60
|
-
"vm_resource_no_operations.json")))
|
25
|
+
Vra::Client.new(
|
26
|
+
username: 'user@corp.local',
|
27
|
+
password: 'password',
|
28
|
+
tenant: 'tenant',
|
29
|
+
base_url: 'https://vra.corp.local'
|
30
|
+
)
|
61
31
|
end
|
62
32
|
|
63
|
-
let(:
|
64
|
-
|
65
|
-
"fixtures",
|
66
|
-
"resource",
|
67
|
-
"non_vm_resource.json")))
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#by_name" do
|
71
|
-
it "can lookup and return resource" do
|
72
|
-
resource = Vra::Resource.allocate
|
73
|
-
allow(resource).to receive(:name).and_return("host1234")
|
74
|
-
name = resource.name
|
75
|
-
expect(Vra::Resources).to receive(:all).with(client).and_return([resource])
|
76
|
-
expect(Vra::Resource.by_name(client, name)).to eq(resource)
|
77
|
-
end
|
33
|
+
let(:resource_id) { 'res-123' }
|
34
|
+
let(:deployment_id) { 'dep-123' }
|
78
35
|
|
79
|
-
|
80
|
-
|
81
|
-
allow(resource).to receive(:name).and_return("host1234")
|
82
|
-
name = "somethingelse1234"
|
83
|
-
expect(Vra::Resources).to receive(:all).with(client).and_return([resource])
|
84
|
-
expect(Vra::Resource.by_name(client, name)).to be nil
|
85
|
-
end
|
36
|
+
let(:vm_payload) do
|
37
|
+
JSON.parse(File.read('spec/fixtures/resource/sample_dep_resource.json'))
|
86
38
|
end
|
87
39
|
|
88
|
-
describe
|
89
|
-
it
|
90
|
-
expect { Vra::Resource.new }.to raise_error(ArgumentError)
|
40
|
+
describe '#initialize' do
|
41
|
+
it 'raises an error if no ID or resource data have been provided' do
|
42
|
+
expect { Vra::Resource.new(client, deployment_id) }.to raise_error(ArgumentError)
|
91
43
|
end
|
92
44
|
|
93
|
-
it
|
94
|
-
expect { Vra::Resource.new(id: 123, data:
|
45
|
+
it 'raises an error if an ID and resource data have both been provided' do
|
46
|
+
expect { Vra::Resource.new(client, deployment_id, id: 123, data: 'foo') }.to raise_error(ArgumentError)
|
95
47
|
end
|
96
48
|
|
97
|
-
context
|
98
|
-
it
|
49
|
+
context 'when an ID is provided' do
|
50
|
+
it 'calls fetch_resource_data' do
|
99
51
|
resource = Vra::Resource.allocate
|
100
52
|
expect(resource).to receive(:fetch_resource_data)
|
101
|
-
resource.send(:initialize, client, id: resource_id)
|
53
|
+
resource.send(:initialize, client, deployment_id, id: resource_id)
|
102
54
|
end
|
103
55
|
end
|
104
56
|
|
105
|
-
context
|
106
|
-
it
|
107
|
-
resource = Vra::Resource.new(client, data: vm_payload)
|
57
|
+
context 'when resource data is provided' do
|
58
|
+
it 'populates the ID correctly' do
|
59
|
+
resource = Vra::Resource.new(client, deployment_id, data: vm_payload)
|
108
60
|
expect(resource.id).to eq resource_id
|
109
61
|
end
|
110
62
|
end
|
111
63
|
end
|
112
64
|
|
113
|
-
describe
|
114
|
-
it
|
65
|
+
describe '#fetch_resource_data' do
|
66
|
+
it 'calls get_parsed against the resources API endpoint' do
|
115
67
|
expect(client).to receive(:get_parsed)
|
116
|
-
.with("/
|
68
|
+
.with("/deployment/api/deployments/#{deployment_id}/resources/#{resource_id}")
|
117
69
|
.and_return({})
|
118
70
|
|
119
|
-
Vra::Resource.new(client, id: resource_id)
|
71
|
+
Vra::Resource.new(client, deployment_id, id: resource_id)
|
120
72
|
end
|
121
|
-
end
|
122
73
|
|
123
|
-
|
124
|
-
|
74
|
+
it 'should raise an exception if the resource not found' do
|
75
|
+
allow(client).to receive(:get_parsed).and_raise(Vra::Exception::HTTPNotFound)
|
125
76
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
77
|
+
expect { Vra::Resource.new(client, deployment_id, id: resource_id) }
|
78
|
+
.to raise_error(Vra::Exception::NotFound)
|
79
|
+
.with_message("resource ID #{resource_id} does not exist")
|
130
80
|
end
|
81
|
+
end
|
131
82
|
|
132
|
-
|
133
|
-
|
134
|
-
|
83
|
+
context 'when a valid VM resource instance has been created' do
|
84
|
+
let(:resource) { Vra::Resource.new(client, deployment_id, data: vm_payload) }
|
85
|
+
|
86
|
+
describe '#name' do
|
87
|
+
it 'returns the correct name' do
|
88
|
+
expect(resource.name).to eq 'Cloud_vSphere_Machine_1'
|
135
89
|
end
|
136
90
|
end
|
137
91
|
|
138
|
-
describe
|
139
|
-
it
|
140
|
-
expect(resource.status).to eq
|
92
|
+
describe '#status' do
|
93
|
+
it 'returns the correct status' do
|
94
|
+
expect(resource.status).to eq 'SUCCESS'
|
141
95
|
end
|
142
96
|
end
|
143
97
|
|
144
|
-
describe
|
145
|
-
context
|
146
|
-
let(:resource_data) { {
|
147
|
-
it
|
98
|
+
describe '#vm?' do
|
99
|
+
context 'when the resource type is Cloud.vSphere.Machine' do
|
100
|
+
let(:resource_data) { { 'type' => 'Cloud.vSphere.Machine' } }
|
101
|
+
it 'returns true' do
|
148
102
|
allow(resource).to receive(:resource_data).and_return(resource_data)
|
149
103
|
expect(resource.vm?).to eq(true)
|
150
104
|
end
|
151
105
|
end
|
152
106
|
|
153
|
-
context
|
154
|
-
let(:resource_data) { {
|
155
|
-
it
|
107
|
+
context 'when the resource type is Cloud.Machine' do
|
108
|
+
let(:resource_data) { { 'type' => 'Cloud.Machine' } }
|
109
|
+
it 'returns true' do
|
156
110
|
allow(resource).to receive(:resource_data).and_return(resource_data)
|
157
111
|
expect(resource.vm?).to eq(true)
|
158
112
|
end
|
159
113
|
end
|
160
114
|
|
161
|
-
context
|
162
|
-
let(:resource_data) { {
|
163
|
-
it
|
115
|
+
context 'when the resource type is an unknown type' do
|
116
|
+
let(:resource_data) { { 'type' => 'Infrastructure.Unknown' } }
|
117
|
+
it 'returns false' do
|
164
118
|
allow(resource).to receive(:resource_data).and_return(resource_data)
|
165
119
|
expect(resource.vm?).to eq(false)
|
166
120
|
end
|
167
121
|
end
|
168
122
|
end
|
169
123
|
|
170
|
-
describe
|
171
|
-
it
|
172
|
-
expect(resource.
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#tenant_name" do
|
177
|
-
it "returns the correct tenant name" do
|
178
|
-
expect(resource.tenant_name).to eq "vsphere.local"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "#subtenant_id" do
|
183
|
-
it "returns the correct subtenant ID" do
|
184
|
-
expect(resource.subtenant_id).to eq "5327ddd3-1a4e-4663-9e9d-63db86ffc8af"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "#subtenant_name" do
|
189
|
-
it "returns the correct subtenant name" do
|
190
|
-
expect(resource.subtenant_name).to eq "Rainpole Developers"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe "#owner_ids" do
|
195
|
-
it "returns the correct owner IDs" do
|
196
|
-
expect(resource.owner_ids).to eq %w{user1@corp.local user2@corp.local}
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "#owner_names" do
|
201
|
-
it "returns the correct owner names" do
|
202
|
-
expect(resource.owner_names).to eq [ "Joe User", "Jane User" ]
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "#machine_status" do
|
207
|
-
context "when no MachineStatus exists" do
|
208
|
-
let(:resource_data) { { "resourceData" => { "entries" => [] } } }
|
209
|
-
|
210
|
-
it "raises an exception" do
|
211
|
-
allow(resource).to receive(:resource_data).and_return(resource_data)
|
212
|
-
expect { resource.machine_status }.to raise_error(RuntimeError)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "when MachineStatus Exists" do
|
217
|
-
let(:resource_data) do
|
218
|
-
{
|
219
|
-
"resourceData" => {
|
220
|
-
"entries" => [
|
221
|
-
{
|
222
|
-
"key" => "MachineStatus",
|
223
|
-
"value" => { "type" => "string", "value" => "Off" },
|
224
|
-
},
|
225
|
-
],
|
226
|
-
},
|
227
|
-
}
|
228
|
-
end
|
229
|
-
|
230
|
-
it "returns the correct status value" do
|
231
|
-
allow(resource).to receive(:resource_data).and_return(resource_data)
|
232
|
-
expect(resource.machine_status).to eq("Off")
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "#machine_on?" do
|
238
|
-
it "returns true if the machine_status is On" do
|
239
|
-
allow(resource).to receive(:machine_status).and_return("On")
|
240
|
-
expect(resource.machine_on?).to eq(true)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "returns false if the machine_status is not On" do
|
244
|
-
allow(resource).to receive(:machine_status).and_return("Off")
|
245
|
-
expect(resource.machine_on?).to eq(false)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "#machine_off?" do
|
250
|
-
it "returns true if the machine_status is Off" do
|
251
|
-
allow(resource).to receive(:machine_status).and_return("Off")
|
252
|
-
expect(resource.machine_off?).to eq(true)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "returns false if the machine_status is not Off" do
|
256
|
-
allow(resource).to receive(:machine_status).and_return("On")
|
257
|
-
expect(resource.machine_off?).to eq(false)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
describe "#machine_turning_on?" do
|
262
|
-
it "returns true if the machine_status is TurningOn" do
|
263
|
-
allow(resource).to receive(:machine_status).and_return("TurningOn")
|
264
|
-
expect(resource.machine_turning_on?).to eq(true)
|
265
|
-
end
|
266
|
-
|
267
|
-
it "returns true if the machine_status is MachineActivated" do
|
268
|
-
allow(resource).to receive(:machine_status).and_return("MachineActivated")
|
269
|
-
expect(resource.machine_turning_on?).to eq(true)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "returns false if the machine_status is not TurningOn" do
|
273
|
-
allow(resource).to receive(:machine_status).and_return("On")
|
274
|
-
expect(resource.machine_turning_on?).to eq(false)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
describe "#machine_turning_off?" do
|
279
|
-
it "returns true if the machine_status is TurningOff" do
|
280
|
-
allow(resource).to receive(:machine_status).and_return("TurningOff")
|
281
|
-
expect(resource.machine_turning_off?).to eq(true)
|
282
|
-
end
|
283
|
-
|
284
|
-
it "returns true if the machine_status is ShuttingDown" do
|
285
|
-
allow(resource).to receive(:machine_status).and_return("ShuttingDown")
|
286
|
-
expect(resource.machine_turning_off?).to eq(true)
|
287
|
-
end
|
288
|
-
|
289
|
-
it "returns false if the machine_status is not TurningOff or ShuttingDown" do
|
290
|
-
allow(resource).to receive(:machine_status).and_return("Off")
|
291
|
-
expect(resource.machine_turning_off?).to eq(false)
|
124
|
+
describe '#project' do
|
125
|
+
it 'returns the correct project ID' do
|
126
|
+
expect(resource.project_id).to eq 'pro-123'
|
292
127
|
end
|
293
128
|
end
|
294
129
|
|
295
|
-
describe
|
296
|
-
it
|
297
|
-
|
298
|
-
expect(resource.machine_in_provisioned_state?).to eq(true)
|
299
|
-
end
|
300
|
-
|
301
|
-
it "returns false if the machine_status is not MachineProvisioned" do
|
302
|
-
allow(resource).to receive(:machine_status).and_return("On")
|
303
|
-
expect(resource.machine_in_provisioned_state?).to eq(false)
|
130
|
+
describe '#owner_names' do
|
131
|
+
it 'returns the correct owner names' do
|
132
|
+
expect(resource.owner_names).to eq 'admin'
|
304
133
|
end
|
305
134
|
end
|
306
135
|
|
307
|
-
describe
|
308
|
-
it
|
136
|
+
describe '#network_interfaces' do
|
137
|
+
it 'returns an array of 2 elements' do
|
309
138
|
expect(resource.network_interfaces.size).to be 2
|
310
139
|
end
|
311
140
|
|
312
|
-
it
|
141
|
+
it 'contains the correct data' do
|
313
142
|
nic1, nic2 = resource.network_interfaces
|
314
143
|
|
315
|
-
expect(nic1[
|
316
|
-
expect(nic1[
|
317
|
-
expect(nic1[
|
318
|
-
|
319
|
-
expect(nic2["NETWORK_NAME"]).to eq "Management Network"
|
320
|
-
expect(nic2["NETWORK_ADDRESS"]).to eq "192.168.220.200"
|
321
|
-
expect(nic2["NETWORK_MAC_ADDRESS"]).to eq "00:50:56:ae:95:3d"
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
describe "#ip_addresses" do
|
326
|
-
let(:authn_payload) do
|
327
|
-
{
|
328
|
-
"username" => "user@corp.local",
|
329
|
-
"password" => "password",
|
330
|
-
"tenant" => "tenant",
|
331
|
-
}.to_json
|
332
|
-
end
|
333
|
-
|
334
|
-
let(:resource_view_body) do
|
335
|
-
File.read(File.join(File.dirname(__FILE__),
|
336
|
-
"fixtures",
|
337
|
-
"resource",
|
338
|
-
"ip_address.txt"))
|
339
|
-
end
|
340
|
-
|
341
|
-
before do
|
342
|
-
stub_request(
|
343
|
-
:post,
|
344
|
-
"https://vra.corp.local/identity/api/tokens"
|
345
|
-
).with(
|
346
|
-
body: authn_payload,
|
347
|
-
headers: { "Accept" => "application/json", "Content-Type" => "application/json" }
|
348
|
-
).to_return(
|
349
|
-
status: 200,
|
350
|
-
body: '{"id":"12345"}',
|
351
|
-
headers: {}
|
352
|
-
)
|
353
|
-
|
354
|
-
stub_request(
|
355
|
-
:head,
|
356
|
-
"https://vra.corp.local/identity/api/tokens/12345"
|
357
|
-
).with(
|
358
|
-
headers: { "Accept" => "application/json", "Authorization" => "Bearer 12345", "Content-Type" => "application/json" }
|
359
|
-
).to_return(
|
360
|
-
status: 204,
|
361
|
-
body: "",
|
362
|
-
headers: {}
|
363
|
-
)
|
364
|
-
|
365
|
-
stub_request(
|
366
|
-
:get,
|
367
|
-
"https://vra.corp.local/catalog-service/api/consumer/requests/bogus/resourceViews"
|
368
|
-
).with(
|
369
|
-
headers: { "Accept" => "application/json", "Content-Type" => "application/json" }
|
370
|
-
).to_return(
|
371
|
-
status: 200,
|
372
|
-
body: resource_view_body,
|
373
|
-
headers: {}
|
374
|
-
)
|
375
|
-
end
|
376
|
-
|
377
|
-
context "with IP address in the second element" do
|
378
|
-
it "returns the correct IP addresses" do
|
379
|
-
expect(resource.ip_addresses).to eq [ "172.16.20.147" ]
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
context "with IP address in the third element" do
|
384
|
-
let(:resource_view_body) do
|
385
|
-
File.read(File.join(File.dirname(__FILE__),
|
386
|
-
"fixtures",
|
387
|
-
"resource",
|
388
|
-
"ip_address_third_element.txt"))
|
389
|
-
end
|
390
|
-
|
391
|
-
it "returns the correct IP addresses" do
|
392
|
-
expect(resource.ip_addresses).to eq [ "172.16.20.147" ]
|
393
|
-
end
|
394
|
-
end
|
144
|
+
expect(nic1['NETWORK_NAME']).to eq 'VM Network'
|
145
|
+
expect(nic1['NETWORK_ADDRESS']).to eq '192.168.110.200'
|
146
|
+
expect(nic1['NETWORK_MAC_ADDRESS']).to eq '00:50:56:ae:95:3c'
|
395
147
|
|
396
|
-
|
397
|
-
|
398
|
-
expect(
|
148
|
+
expect(nic2['NETWORK_NAME']).to eq 'Management Network'
|
149
|
+
expect(nic2['NETWORK_ADDRESS']).to eq '192.168.220.200'
|
150
|
+
expect(nic2['NETWORK_MAC_ADDRESS']).to eq '00:50:56:ae:95:3d'
|
399
151
|
end
|
400
152
|
end
|
401
153
|
|
402
|
-
describe
|
403
|
-
it
|
404
|
-
expect(resource).
|
405
|
-
resource.actions
|
154
|
+
describe '#ip_addresses' do
|
155
|
+
it 'should have the correct ip address' do
|
156
|
+
expect(resource.ip_address).to eq '10.30.236.64'
|
406
157
|
end
|
407
158
|
end
|
408
|
-
|
409
|
-
describe "#action_id_by_name" do
|
410
|
-
it "returns the correct action ID for the destroy action" do
|
411
|
-
expect(resource.action_id_by_name("Destroy")).to eq "ace8ba42-e724-48d8-9614-9b3a62b5a464"
|
412
|
-
end
|
413
|
-
|
414
|
-
it "returns nil if there are no resource operations" do
|
415
|
-
allow(resource).to receive(:actions).and_return nil
|
416
|
-
expect(resource.action_id_by_name("Destroy")).to be_nil
|
417
|
-
end
|
418
|
-
|
419
|
-
it "returns nil if there are actions, but none with the right name" do
|
420
|
-
allow(resource).to receive(:actions).and_return([ { "name" => "some action" }, { "name" => "another action" } ])
|
421
|
-
expect(resource.action_id_by_name("Destroy")).to be_nil
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
describe "#destroy" do
|
426
|
-
it_behaves_like "a resource action", :destroy, "Destroy"
|
427
|
-
end
|
428
|
-
|
429
|
-
describe "#shutdown" do
|
430
|
-
it_behaves_like "a resource action", :shutdown, "Shutdown"
|
431
|
-
end
|
432
|
-
|
433
|
-
describe "#poweroff" do
|
434
|
-
it_behaves_like "a resource action", :poweroff, "Power Off"
|
435
|
-
end
|
436
|
-
|
437
|
-
describe "#poweron" do
|
438
|
-
it_behaves_like "a resource action", :poweron, "Power On"
|
439
|
-
end
|
440
|
-
|
441
|
-
describe "#submit_action_request" do
|
442
|
-
before do
|
443
|
-
allow(resource).to receive(:action_request_payload).and_return({})
|
444
|
-
response = double("response", location: "/requests/request-12345")
|
445
|
-
allow(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}").and_return(response)
|
446
|
-
end
|
447
|
-
|
448
|
-
it "calls http_post" do
|
449
|
-
expect(client).to receive(:http_post).with("/catalog-service/api/consumer/requests", "{}")
|
450
|
-
|
451
|
-
resource.submit_action_request("action-123")
|
452
|
-
end
|
453
|
-
|
454
|
-
it "returns a Vra::Request object" do
|
455
|
-
expect(resource.submit_action_request("action-123")).to be_an_instance_of(Vra::Request)
|
456
|
-
end
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
context "when a valid VM resource instance with no operations is created" do
|
461
|
-
let(:resource) { Vra::Resource.new(client, data: vm_payload_no_ops) }
|
462
|
-
|
463
|
-
describe "#actions" do
|
464
|
-
it "calls #fetch_resource_data" do
|
465
|
-
expect(resource).to receive(:fetch_resource_data)
|
466
|
-
resource.actions
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
context "when a valid non-VM resource instance has been created" do
|
472
|
-
let(:resource) { Vra::Resource.new(client, data: non_vm_payload) }
|
473
|
-
|
474
|
-
it "returns nil for network_interfaces and ip_addresses" do
|
475
|
-
expect(resource.network_interfaces).to be_nil
|
476
|
-
expect(resource.ip_addresses).to be_nil
|
477
|
-
end
|
478
159
|
end
|
479
160
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
|
-
# Copyright:: Copyright (c)
|
4
|
+
# Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,13 +17,19 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require 'webmock/rspec'
|
21
|
+
require 'simplecov'
|
22
|
+
|
23
|
+
SimpleCov.start do
|
24
|
+
enable_coverage :branch
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'vra'
|
22
28
|
|
23
29
|
def fixtures_dir
|
24
30
|
@fixtures_dir ||= begin
|
25
31
|
base_dir = File.dirname(__FILE__)
|
26
|
-
File.join(base_dir,
|
32
|
+
File.join(base_dir, 'fixtures')
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
data/vmware-vra.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
|
-
lib = File.expand_path("
|
2
|
+
lib = File.expand_path("lib", __dir__)
|
4
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
4
|
require "vra/version"
|
6
5
|
|
@@ -22,9 +21,8 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.add_dependency "ffi-yajl", "~> 2.2"
|
23
22
|
spec.add_dependency "passwordmasker", "~> 1.2"
|
24
23
|
|
25
|
-
spec.add_development_dependency "bundler", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.7"
|
26
25
|
spec.add_development_dependency "chefstyle"
|
27
|
-
spec.add_development_dependency "github_changelog_generator"
|
28
26
|
spec.add_development_dependency "pry", "~> 0.10"
|
29
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|