vmware-vra 3.1.0 → 3.1.3
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/.github/workflows/linters.yml +9 -0
- data/.markdownlint.yaml +5 -0
- data/.mdlrc +1 -0
- data/CHANGELOG.md +196 -143
- data/Gemfile +3 -0
- data/README.md +37 -26
- data/Rakefile +2 -2
- data/lib/vra/catalog.rb +6 -7
- data/lib/vra/catalog_base.rb +4 -4
- data/lib/vra/catalog_item.rb +12 -12
- data/lib/vra/catalog_source.rb +13 -13
- data/lib/vra/catalog_type.rb +6 -6
- data/lib/vra/client.rb +13 -13
- data/lib/vra/deployment.rb +21 -21
- data/lib/vra/deployment_request.rb +8 -9
- data/lib/vra/deployments.rb +1 -1
- data/lib/vra/http.rb +6 -6
- data/lib/vra/request.rb +6 -6
- data/lib/vra/request_parameters.rb +9 -9
- data/lib/vra/resource.rb +16 -16
- data/lib/vra/version.rb +1 -1
- data/lib/vra.rb +14 -14
- data/spec/catalog_item_spec.rb +50 -50
- data/spec/catalog_source_spec.rb +53 -53
- data/spec/catalog_spec.rb +45 -45
- data/spec/catalog_type_spec.rb +32 -32
- data/spec/client_spec.rb +202 -202
- data/spec/deployment_request_spec.rb +74 -74
- data/spec/deployment_spec.rb +70 -70
- data/spec/deployments_spec.rb +19 -19
- data/spec/http_spec.rb +59 -59
- data/spec/request_spec.rb +34 -34
- data/spec/resource_spec.rb +55 -55
- data/spec/spec_helper.rb +4 -4
- data/vmware-vra.gemspec +1 -1
- metadata +8 -7
- data/.github/ISSUE_TEMPLATE.md +0 -23
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
@@ -17,69 +17,69 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "spec_helper"
|
21
21
|
|
22
22
|
describe Vra::DeploymentRequest do
|
23
23
|
let(:client) do
|
24
24
|
Vra::Client.new(
|
25
|
-
username:
|
26
|
-
password:
|
27
|
-
tenant:
|
28
|
-
base_url:
|
25
|
+
username: "user@corp.local",
|
26
|
+
password: "password",
|
27
|
+
tenant: "tenant",
|
28
|
+
base_url: "https://vra.corp.local"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
|
-
let(:catalog_id) {
|
32
|
+
let(:catalog_id) { "cat-123456" }
|
33
33
|
|
34
34
|
let(:request_payload) do
|
35
35
|
{
|
36
|
-
image_mapping:
|
37
|
-
name:
|
38
|
-
flavor_mapping:
|
39
|
-
version:
|
40
|
-
project_id:
|
36
|
+
image_mapping: "Centos Image",
|
37
|
+
name: "test deployment",
|
38
|
+
flavor_mapping: "Small",
|
39
|
+
version: "1",
|
40
|
+
project_id: "pro-123",
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
45
|
-
it
|
44
|
+
describe "#initialize" do
|
45
|
+
it "should raise errors for missing arguments" do
|
46
46
|
request = described_class.new(
|
47
47
|
client,
|
48
48
|
catalog_id,
|
49
49
|
request_payload
|
50
50
|
)
|
51
51
|
|
52
|
-
expect(request.name).to eq(
|
53
|
-
expect(request.image_mapping).to eq(
|
54
|
-
expect(request.flavor_mapping).to eq(
|
55
|
-
expect(request.version).to eq(
|
52
|
+
expect(request.name).to eq("test deployment")
|
53
|
+
expect(request.image_mapping).to eq("Centos Image")
|
54
|
+
expect(request.flavor_mapping).to eq("Small")
|
55
|
+
expect(request.version).to eq("1")
|
56
56
|
expect(request.count).to eq(1)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
61
|
-
it
|
60
|
+
describe "#validate!" do
|
61
|
+
it "should return error if params are missing" do
|
62
62
|
request = described_class.new(client, catalog_id)
|
63
63
|
expect { request.send(:validate!) }.to raise_error(ArgumentError)
|
64
64
|
|
65
|
-
request.image_mapping =
|
66
|
-
request.name =
|
67
|
-
request.flavor_mapping =
|
68
|
-
request.version =
|
69
|
-
request.project_id =
|
65
|
+
request.image_mapping = "Centos Image"
|
66
|
+
request.name = "test deployment"
|
67
|
+
request.flavor_mapping = "Small"
|
68
|
+
request.version = "1"
|
69
|
+
request.project_id = "pro-123"
|
70
70
|
|
71
71
|
expect { request.send(:validate!) }.not_to raise_error(ArgumentError)
|
72
72
|
end
|
73
73
|
|
74
|
-
context
|
74
|
+
context "versions" do
|
75
75
|
let(:dep_request) do
|
76
76
|
described_class.new(
|
77
77
|
client,
|
78
78
|
catalog_id,
|
79
|
-
image_mapping:
|
80
|
-
name:
|
81
|
-
flavor_mapping:
|
82
|
-
project_id:
|
79
|
+
image_mapping: "centos",
|
80
|
+
name: "sample dep",
|
81
|
+
flavor_mapping: "small",
|
82
|
+
project_id: "pro-123"
|
83
83
|
)
|
84
84
|
end
|
85
85
|
|
@@ -87,83 +87,83 @@ describe Vra::DeploymentRequest do
|
|
87
87
|
allow(client).to receive(:authorized?).and_return(true)
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it "should not call the api to fetch versions if provided in the params" do
|
91
91
|
expect(client).not_to receive(:http_get_paginated_array!)
|
92
92
|
|
93
|
-
dep_request.version =
|
93
|
+
dep_request.version = "1"
|
94
94
|
dep_request.send(:validate!)
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
98
|
-
expect(client).to receive(:http_get_paginated_array!).and_return([{
|
97
|
+
it "should fetch version from api if version is blank" do
|
98
|
+
expect(client).to receive(:http_get_paginated_array!).and_return([{ "id" => "2", "description" => "v2.0" }])
|
99
99
|
|
100
100
|
dep_request.send(:validate!)
|
101
|
-
expect(dep_request.version).to eq(
|
101
|
+
expect(dep_request.version).to eq("2")
|
102
102
|
end
|
103
103
|
|
104
|
-
it
|
104
|
+
it "should raise an exception if no valid versions found" do
|
105
105
|
expect(client).to receive(:http_get_paginated_array!).and_return([])
|
106
106
|
|
107
107
|
expect { dep_request.send(:validate!) }
|
108
108
|
.to raise_error(ArgumentError)
|
109
|
-
.with_message(
|
109
|
+
.with_message("Unable to fetch a valid catalog version")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
describe
|
114
|
+
describe "#additional parameters" do
|
115
115
|
let(:request) do
|
116
116
|
described_class.new(client, catalog_id, request_payload)
|
117
117
|
end
|
118
118
|
|
119
|
-
context
|
120
|
-
it
|
121
|
-
request.set_parameter(
|
119
|
+
context "set_parameter" do
|
120
|
+
it "should set the parameter" do
|
121
|
+
request.set_parameter("hardware-config", "stirng", "Small")
|
122
122
|
|
123
|
-
expect(request.parameters).to eq({ inputs: {
|
123
|
+
expect(request.parameters).to eq({ inputs: { "hardware-config" => "Small" } })
|
124
124
|
expect(request.parameters[:inputs].count).to be(1)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
context
|
129
|
-
it
|
130
|
-
request.set_parameters(
|
128
|
+
context "set_parameters" do
|
129
|
+
it "should be able to set multiple parameters" do
|
130
|
+
request.set_parameters("test-parent", { "param1" => { type: "string", value: 1234 } })
|
131
131
|
|
132
132
|
expect(request.parameters)
|
133
|
-
.to eq({ inputs: {
|
133
|
+
.to eq({ inputs: { "test-parent" => { "inputs" => { "param1" => 1234 } } } })
|
134
134
|
end
|
135
135
|
|
136
|
-
it
|
137
|
-
request.set_parameters(
|
138
|
-
request.set_parameters(
|
139
|
-
request.set_parameters(
|
136
|
+
it "should set multiple parameters with different data types" do
|
137
|
+
request.set_parameters("param1", { key1: { type: "string", value: "data" } })
|
138
|
+
request.set_parameters("param2", { key2: { type: "boolean", value: false } })
|
139
|
+
request.set_parameters("param3", { key3: { type: "integer", value: 100 } })
|
140
140
|
|
141
141
|
expect(request.parameters[:inputs].count).to be 3
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
context
|
145
|
+
context "delete_parameter" do
|
146
146
|
before(:each) do
|
147
|
-
request.set_parameter(
|
147
|
+
request.set_parameter("hardware-config", "string", "small")
|
148
148
|
end
|
149
149
|
|
150
|
-
it
|
150
|
+
it "should delete the existing parameter" do
|
151
151
|
expect(request.parameters[:inputs].count).to be(1)
|
152
|
-
request.delete_parameter(
|
152
|
+
request.delete_parameter("hardware-config")
|
153
153
|
expect(request.parameters[:inputs].count).to be(0)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
context
|
158
|
-
it
|
159
|
-
request.set_parameters(:param1, { key1: { type:
|
157
|
+
context "#hash_parameters" do
|
158
|
+
it "should have the correct representation" do
|
159
|
+
request.set_parameters(:param1, { key1: { type: "string", value: "data" } })
|
160
160
|
|
161
|
-
expect(request.hash_parameters).to eq({ param1: { :
|
161
|
+
expect(request.hash_parameters).to eq({ param1: { key1: "data" } })
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
describe
|
166
|
+
describe "#submit" do
|
167
167
|
let(:request) do
|
168
168
|
described_class.new(client, catalog_id, request_payload)
|
169
169
|
end
|
@@ -172,30 +172,30 @@ describe Vra::DeploymentRequest do
|
|
172
172
|
allow(client).to receive(:authorized?).and_return(true)
|
173
173
|
end
|
174
174
|
|
175
|
-
it
|
175
|
+
it "should call the validate before submit" do
|
176
176
|
expect(request).to receive(:validate!)
|
177
|
-
stub_request(:post, client.full_url(
|
177
|
+
stub_request(:post, client.full_url("/catalog/api/items/cat-123456/request"))
|
178
178
|
.to_return(status: 200, body: '[{"deploymentId": "123"}]', headers: {})
|
179
179
|
allow(Vra::Deployment).to receive(:new)
|
180
180
|
|
181
181
|
request.submit
|
182
182
|
end
|
183
183
|
|
184
|
-
it
|
185
|
-
response = double(
|
184
|
+
it "should call the api to submit the deployment request" do
|
185
|
+
response = double("response", body: '[{"deploymentId": "123"}]', success?: true)
|
186
186
|
allow(client)
|
187
187
|
.to receive(:http_post)
|
188
188
|
.with(
|
189
189
|
"/catalog/api/items/#{catalog_id}/request",
|
190
190
|
{
|
191
|
-
deploymentName:
|
192
|
-
projectId:
|
193
|
-
version:
|
191
|
+
deploymentName: "test deployment",
|
192
|
+
projectId: "pro-123",
|
193
|
+
version: "1",
|
194
194
|
inputs: {
|
195
195
|
count: 1,
|
196
|
-
image:
|
197
|
-
flavor:
|
198
|
-
}
|
196
|
+
image: "Centos Image",
|
197
|
+
flavor: "Small",
|
198
|
+
},
|
199
199
|
}.to_json
|
200
200
|
)
|
201
201
|
.and_return(response)
|
@@ -204,25 +204,25 @@ describe Vra::DeploymentRequest do
|
|
204
204
|
request.submit
|
205
205
|
end
|
206
206
|
|
207
|
-
it
|
208
|
-
response = double(
|
207
|
+
it "should return a deployment object" do
|
208
|
+
response = double("response", body: '[{"deploymentId": "123"}]', success?: true)
|
209
209
|
allow(client).to receive(:http_post).and_return(response)
|
210
210
|
allow(client)
|
211
211
|
.to receive(:get_parsed)
|
212
|
-
.and_return(JSON.parse(File.read(
|
212
|
+
.and_return(JSON.parse(File.read("spec/fixtures/resource/sample_deployment.json")))
|
213
213
|
|
214
214
|
dep = request.submit
|
215
215
|
expect(dep).to be_an_instance_of(Vra::Deployment)
|
216
|
-
expect(dep.id).to eq(
|
216
|
+
expect(dep.id).to eq("123")
|
217
217
|
end
|
218
218
|
|
219
|
-
it
|
219
|
+
it "should handle the VRA Errors" do
|
220
220
|
allow(request).to receive(:send_request!).and_raise(Vra::Exception::HTTPError)
|
221
221
|
|
222
222
|
expect { request.submit }.to raise_error(Vra::Exception::RequestError)
|
223
223
|
end
|
224
224
|
|
225
|
-
it
|
225
|
+
it "should handle the generic errors" do
|
226
226
|
allow(request).to receive(:send_request!).and_raise(ArgumentError)
|
227
227
|
|
228
228
|
expect { request.submit }.to raise_error(ArgumentError)
|
data/spec/deployment_spec.rb
CHANGED
@@ -17,20 +17,20 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "spec_helper"
|
21
21
|
|
22
22
|
describe ::Vra::Deployment do
|
23
23
|
let(:client) do
|
24
24
|
Vra::Client.new(
|
25
|
-
username:
|
26
|
-
password:
|
27
|
-
tenant:
|
28
|
-
base_url:
|
25
|
+
username: "user@corp.local",
|
26
|
+
password: "password",
|
27
|
+
tenant: "tenant",
|
28
|
+
base_url: "https://vra.corp.local"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
32
|
let(:sample_data) do
|
33
|
-
JSON.parse(File.read(
|
33
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_deployment.json"))
|
34
34
|
end
|
35
35
|
|
36
36
|
let(:deployment) do
|
@@ -41,7 +41,7 @@ describe ::Vra::Deployment do
|
|
41
41
|
allow(client).to receive(:authorized?).and_return(true)
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
44
|
+
describe "#initialize" do
|
45
45
|
let(:deployment) do
|
46
46
|
described_class.allocate
|
47
47
|
end
|
@@ -50,171 +50,171 @@ describe ::Vra::Deployment do
|
|
50
50
|
allow(client).to receive(:get_parsed).and_return(sample_data)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "should validate the attributes" do
|
54
54
|
expect(deployment).to receive(:validate!)
|
55
55
|
|
56
|
-
deployment.send(:initialize, client, id:
|
56
|
+
deployment.send(:initialize, client, id: "dep-123")
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
60
|
-
deployment.send(:initialize, client, id:
|
59
|
+
it "should fetch data when id is passed" do
|
60
|
+
deployment.send(:initialize, client, id: "dep-123")
|
61
61
|
|
62
62
|
expect(deployment.send(:data)).not_to be_nil
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it "should set id when data is passed" do
|
66
66
|
deployment.send(:initialize, client, data: sample_data)
|
67
67
|
|
68
|
-
expect(deployment.id).to eq(
|
68
|
+
expect(deployment.id).to eq("dep-123")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
73
|
-
it
|
72
|
+
describe "#refresh" do
|
73
|
+
it "should refresh the data correctly" do
|
74
74
|
expect(client).to receive(:get_parsed).and_return(sample_data)
|
75
75
|
|
76
76
|
deployment.refresh
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "should raise an exception if record not found" do
|
80
80
|
expect(client).to receive(:get_parsed).and_raise(Vra::Exception::HTTPNotFound)
|
81
81
|
|
82
82
|
expect { deployment.refresh }.to raise_error(Vra::Exception::NotFound)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe
|
87
|
-
it
|
88
|
-
expect(deployment.name).to eq(
|
89
|
-
expect(deployment.description).to eq(
|
90
|
-
expect(deployment.org_id).to eq(
|
91
|
-
expect(deployment.blueprint_id).to eq(
|
92
|
-
expect(deployment.owner).to eq(
|
93
|
-
expect(deployment.status).to eq(
|
86
|
+
describe "#attributes" do
|
87
|
+
it "should have the correct attributes" do
|
88
|
+
expect(deployment.name).to eq("win-DCI")
|
89
|
+
expect(deployment.description).to eq("win-dci deployment")
|
90
|
+
expect(deployment.org_id).to eq("origin-123")
|
91
|
+
expect(deployment.blueprint_id).to eq("blueprint-123")
|
92
|
+
expect(deployment.owner).to eq("administrator")
|
93
|
+
expect(deployment.status).to eq("CREATE_SUCCESSFUL")
|
94
94
|
expect(deployment.successful?).to be_truthy
|
95
95
|
expect(deployment.completed?).to be_truthy
|
96
96
|
expect(deployment.failed?).to be_falsey
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
describe
|
100
|
+
describe "#requests" do
|
101
101
|
let(:request_data) do
|
102
|
-
JSON.parse(File.read(
|
102
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_dep_request.json"))
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it "should call the api to fetch the requests" do
|
106
106
|
expect(client)
|
107
107
|
.to receive(:get_parsed)
|
108
|
-
.with(
|
109
|
-
.and_return({
|
108
|
+
.with("/deployment/api/deployments/dep-123/requests")
|
109
|
+
.and_return({ "content" => [request_data] })
|
110
110
|
|
111
111
|
deployment.requests
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
115
|
-
stub_request(:get, client.full_url(
|
116
|
-
.to_return(status: 200, body: {
|
114
|
+
it "should return the Vra::Request object" do
|
115
|
+
stub_request(:get, client.full_url("/deployment/api/deployments/dep-123/requests"))
|
116
|
+
.to_return(status: 200, body: { "content" => [request_data] }.to_json, headers: {})
|
117
117
|
|
118
118
|
res = deployment.requests.first
|
119
119
|
expect(res).to be_an_instance_of(Vra::Request)
|
120
120
|
end
|
121
121
|
|
122
|
-
it
|
122
|
+
it "should return the correct request data" do
|
123
123
|
allow(client)
|
124
124
|
.to receive(:get_parsed)
|
125
|
-
.with(
|
126
|
-
.and_return({
|
125
|
+
.with("/deployment/api/deployments/dep-123/requests")
|
126
|
+
.and_return({ "content" => [request_data] })
|
127
127
|
|
128
128
|
res = deployment.requests.first
|
129
|
-
expect(res.status).to eq(
|
130
|
-
expect(res.name).to eq(
|
131
|
-
expect(res.requested_by).to eq(
|
129
|
+
expect(res.status).to eq("SUCCESSFUL")
|
130
|
+
expect(res.name).to eq("Create")
|
131
|
+
expect(res.requested_by).to eq("admin")
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
describe
|
135
|
+
describe "#resources" do
|
136
136
|
let(:resource_data) do
|
137
|
-
JSON.parse(File.read(
|
137
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_dep_resource.json"))
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
140
|
+
it "should call the api to fetch the resources" do
|
141
141
|
expect(client)
|
142
142
|
.to receive(:get_parsed)
|
143
|
-
.with(
|
144
|
-
.and_return({
|
143
|
+
.with("/deployment/api/deployments/dep-123/resources")
|
144
|
+
.and_return({ "content" => [resource_data] })
|
145
145
|
|
146
146
|
res = deployment.resources.first
|
147
147
|
expect(res).to be_an_instance_of(Vra::Resource)
|
148
148
|
end
|
149
149
|
|
150
|
-
it
|
151
|
-
expect(client).to receive(:get_parsed).and_return({
|
150
|
+
it "should have the correct resource data" do
|
151
|
+
expect(client).to receive(:get_parsed).and_return({ "content" => [resource_data] })
|
152
152
|
|
153
153
|
res = deployment.resources.first
|
154
|
-
expect(res.name).to eq(
|
155
|
-
expect(res.status).to eq(
|
154
|
+
expect(res.name).to eq("Cloud_vSphere_Machine_1")
|
155
|
+
expect(res.status).to eq("SUCCESS")
|
156
156
|
expect(res.vm?).to be_truthy
|
157
|
-
expect(res.owner_names).to eq(
|
157
|
+
expect(res.owner_names).to eq("admin")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
describe
|
161
|
+
describe "#actions" do
|
162
162
|
let(:actions_data) do
|
163
|
-
JSON.parse(File.read(
|
163
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_dep_actions.json"))
|
164
164
|
end
|
165
165
|
|
166
166
|
def action_req(action)
|
167
167
|
{
|
168
168
|
actionId: "Deployment.#{camelize(action)}",
|
169
169
|
inputs: {},
|
170
|
-
reason: "Testing the #{action}"
|
170
|
+
reason: "Testing the #{action}",
|
171
171
|
}.to_json
|
172
172
|
end
|
173
173
|
|
174
174
|
def action_response(action)
|
175
175
|
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
176
|
+
"id" => "req-123",
|
177
|
+
"name" => camelize(action),
|
178
|
+
"requestedBy" => "admin",
|
179
|
+
"blueprintId" => "blueprint-123",
|
180
|
+
"inputs" => {
|
181
|
+
"flag" => "false",
|
182
|
+
"count" => "1",
|
183
|
+
"hardware-config" => "Medium",
|
184
184
|
},
|
185
|
-
|
185
|
+
"status" => "SUCCESSFUL",
|
186
186
|
}.to_json
|
187
187
|
end
|
188
188
|
|
189
189
|
def camelize(action_name)
|
190
|
-
action_name.split(
|
190
|
+
action_name.split("_").map(&:capitalize).join
|
191
191
|
end
|
192
192
|
|
193
|
-
it
|
193
|
+
it "should call the api to fetch the actions" do
|
194
194
|
expect(client)
|
195
195
|
.to receive(:get_parsed)
|
196
|
-
.with(
|
196
|
+
.with("/deployment/api/deployments/dep-123/actions")
|
197
197
|
.and_return(actions_data)
|
198
198
|
|
199
199
|
actions = deployment.actions
|
200
200
|
expect(actions).to be_an_instance_of(Array)
|
201
201
|
end
|
202
202
|
|
203
|
-
it
|
203
|
+
it "should return the correct actions" do
|
204
204
|
allow(client).to receive(:get_parsed).and_return(actions_data)
|
205
205
|
|
206
|
-
action_names = deployment.actions.map { |a| a[
|
207
|
-
expect(action_names).to eq(%w
|
206
|
+
action_names = deployment.actions.map { |a| a["name"] }
|
207
|
+
expect(action_names).to eq(%w{ChangeLease ChangeOwner Delete EditTags PowerOff PowerOn Update})
|
208
208
|
end
|
209
209
|
|
210
210
|
{
|
211
|
-
destroy:
|
212
|
-
power_on:
|
213
|
-
power_off:
|
211
|
+
destroy: "delete",
|
212
|
+
power_on: "power_on",
|
213
|
+
power_off: "power_off",
|
214
214
|
}.each do |method, action|
|
215
215
|
it "should perform the action: #{action} correctly" do
|
216
216
|
allow(client).to receive(:get_parsed).and_return(actions_data)
|
217
|
-
stub_request(:post, client.full_url(
|
217
|
+
stub_request(:post, client.full_url("/deployment/api/deployments/dep-123/requests"))
|
218
218
|
.with(body: action_req(action))
|
219
219
|
.to_return(status: 200, body: action_response(action), headers: {})
|
220
220
|
|
data/spec/deployments_spec.rb
CHANGED
@@ -17,54 +17,54 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "spec_helper"
|
21
21
|
|
22
22
|
describe ::Vra::Deployments do
|
23
23
|
let(:client) do
|
24
24
|
Vra::Client.new(
|
25
|
-
username:
|
26
|
-
password:
|
27
|
-
tenant:
|
28
|
-
base_url:
|
25
|
+
username: "user@corp.local",
|
26
|
+
password: "password",
|
27
|
+
tenant: "tenant",
|
28
|
+
base_url: "https://vra.corp.local"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
32
|
let(:deployment_response) do
|
33
|
-
JSON.parse(File.read(
|
33
|
+
JSON.parse(File.read("spec/fixtures/resource/sample_deployment.json"))
|
34
34
|
end
|
35
35
|
|
36
36
|
before(:each) do
|
37
37
|
allow(client).to receive(:authorized?).and_return(true)
|
38
38
|
end
|
39
39
|
|
40
|
-
describe
|
41
|
-
it
|
40
|
+
describe "#by_id" do
|
41
|
+
it "should call the api to fetch the deployments" do
|
42
42
|
expect(client).to receive(:get_parsed).and_return(deployment_response)
|
43
43
|
|
44
|
-
described_class.by_id(client,
|
44
|
+
described_class.by_id(client, "dep-123")
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
stub_request(:get, client.full_url(
|
47
|
+
it "should return the deployment by id" do
|
48
|
+
stub_request(:get, client.full_url("/deployment/api/deployments/dep-123"))
|
49
49
|
.to_return(status: 200, body: deployment_response.to_json, headers: {})
|
50
50
|
|
51
|
-
deployment = described_class.by_id(client,
|
51
|
+
deployment = described_class.by_id(client, "dep-123")
|
52
52
|
expect(deployment).to be_an_instance_of(Vra::Deployment)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
57
|
-
it
|
56
|
+
describe "#all" do
|
57
|
+
it "should call the api to fetch all deployments" do
|
58
58
|
expect(client)
|
59
59
|
.to receive(:http_get_paginated_array!)
|
60
|
-
.with(
|
60
|
+
.with("/deployment/api/deployments")
|
61
61
|
.and_return([deployment_response])
|
62
62
|
|
63
63
|
described_class.all(client)
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
stub_request(:get, client.full_url(
|
66
|
+
it "should return the Vra::Deployment object" do
|
67
|
+
stub_request(:get, client.full_url("/deployment/api/deployments?$skip=0&$top=20"))
|
68
68
|
.to_return(status: 200, body: { content: [deployment_response], totalPages: 1 }.to_json, headers: {})
|
69
69
|
|
70
70
|
deployment = described_class.all(client).first
|
@@ -72,8 +72,8 @@ describe ::Vra::Deployments do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
it
|
75
|
+
describe "called with client" do
|
76
|
+
it "should return the class object" do
|
77
77
|
expect(client.deployments).to be_an_instance_of described_class
|
78
78
|
end
|
79
79
|
end
|