knife-vrealize 3.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
- require 'rubocop/rake_task'
6
-
7
- RSpec::Core::RakeTask.new(:spec)
8
- RuboCop::RakeTask.new(:style)
9
-
10
- begin
11
- require 'github_changelog_generator/task'
12
-
13
- GitHubChangelogGenerator::RakeTask.new :changelog do |config|
14
- config.future_release = KnifeVrealize::VERSION
15
- config.issues = true
16
- end
17
- rescue LoadError
18
- puts 'github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs'
19
- end
20
-
21
- task default: %i[spec style]
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
-
4
- lib = File.expand_path('../lib', __FILE__)
5
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
-
7
- require 'knife-vrealize/version'
8
-
9
- Gem::Specification.new do |spec|
10
- spec.name = 'knife-vrealize'
11
- spec.version = KnifeVrealize::VERSION
12
- spec.authors = ['Chef Partner Engineering']
13
- spec.email = ['partnereng@chef.io']
14
- spec.summary = 'Knife plugin to interact with VMware vRealize.'
15
- spec.description = spec.summary
16
- spec.homepage = 'https://github.com/chef-partners/knife-vrealize'
17
- spec.license = 'Apache 2.0'
18
-
19
- spec.files = `git ls-files -z`.split("\x0")
20
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
- spec.require_paths = ['lib']
23
-
24
- spec.add_dependency 'cookstyle'
25
- spec.add_dependency 'knife-cloud', '~> 1.2.0'
26
- spec.add_dependency 'vmware-vra', '~> 2'
27
- spec.add_dependency 'vcoworkflows', '~> 0.2'
28
- spec.add_dependency 'rb-readline', '~> 0.5'
29
-
30
- spec.add_development_dependency 'bundler', '~> 1.7'
31
- spec.add_development_dependency 'github_changelog_generator'
32
- spec.add_development_dependency 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rubocop', '~> 0.35'
34
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
@@ -1,153 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require 'spec_helper'
21
- require 'chef/knife'
22
- require 'chef/knife/cloud/vra_service'
23
- require 'chef/knife/cloud/vra_service_helpers'
24
-
25
- class HelpersTester
26
- include Chef::Knife::Cloud::VraServiceHelpers
27
- attr_accessor :ui
28
- end
29
-
30
- describe 'Chef::Knife::Cloud::VraServiceHelpers' do
31
- subject { HelpersTester.new }
32
-
33
- before(:each) do
34
- subject.ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
35
- end
36
-
37
- describe '#create_service_instance' do
38
- it 'creates a service instance' do
39
- allow(subject).to receive(:locate_config_value).with(:vra_username).and_return('myuser')
40
- allow(subject).to receive(:locate_config_value).with(:vra_password).and_return('mypassword')
41
- allow(subject).to receive(:locate_config_value).with(:vra_base_url).and_return('https://vra.corp.local')
42
- allow(subject).to receive(:locate_config_value).with(:vra_tenant).and_return('mytenant')
43
- allow(subject).to receive(:locate_config_value).with(:vra_page_size).and_return(50)
44
- allow(subject).to receive(:locate_config_value).with(:vra_disable_ssl_verify).and_return(false)
45
-
46
- expect(Chef::Knife::Cloud::VraService).to receive(:new)
47
- .with(username: 'myuser',
48
- password: 'mypassword',
49
- base_url: 'https://vra.corp.local',
50
- tenant: 'mytenant',
51
- page_size: 50,
52
- verify_ssl: true)
53
-
54
- subject.create_service_instance
55
- end
56
- end
57
-
58
- describe '#verify_ssl?' do
59
- context 'when vra_disable_ssl_verify is true' do
60
- it 'returns false' do
61
- allow(subject).to receive(:locate_config_value).with(:vra_disable_ssl_verify).and_return(true)
62
- expect(subject.verify_ssl?).to be false
63
- end
64
- end
65
-
66
- context 'when vra_disable_ssl_verify is false' do
67
- it 'returns true' do
68
- allow(subject).to receive(:locate_config_value).with(:vra_disable_ssl_verify).and_return(false)
69
- expect(subject.verify_ssl?).to be true
70
- end
71
- end
72
- end
73
-
74
- describe '#wait_for_request' do
75
- before(:each) do
76
- # muffle any stdout output from this method
77
- allow(subject).to receive(:print)
78
-
79
- # don't actually sleep
80
- allow(subject).to receive(:sleep)
81
- end
82
-
83
- context 'when the requests completes normally, 3 loops' do
84
- it 'only refreshes the request 3 times' do
85
- request = double('request')
86
- allow(request).to receive(:status)
87
- allow(request).to receive(:completed?).exactly(3).times.and_return(false, false, true)
88
- expect(request).to receive(:refresh).exactly(3).times
89
-
90
- subject.wait_for_request(request)
91
- end
92
- end
93
-
94
- context 'when the request is completed on the first loop' do
95
- it 'only refreshes the request 1 time' do
96
- request = double('request')
97
- allow(request).to receive(:status)
98
- allow(request).to receive(:completed?).once.and_return(true)
99
- expect(request).to receive(:refresh).once
100
-
101
- subject.wait_for_request(request)
102
- end
103
- end
104
-
105
- context 'when the timeout is exceeded' do
106
- it 'prints a warning and exits' do
107
- request = double('request')
108
- allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
109
- expect(subject.ui).to receive(:msg).with('')
110
- expect(subject.ui).to receive(:error)
111
- .with('Request did not complete in 600 seconds. Check the Requests tab in the vRA UI for more information.')
112
- expect { subject.wait_for_request(request) }.to raise_error(SystemExit)
113
- end
114
- end
115
-
116
- context 'when a non-timeout exception is raised' do
117
- it 'raises the original exception' do
118
- request = double('request')
119
- allow(request).to receive(:refresh).and_raise(RuntimeError)
120
- expect { subject.wait_for_request(request) }.to raise_error(RuntimeError)
121
- end
122
- end
123
- end
124
-
125
- describe '#validate!' do
126
- it 'calls checks for empty VRA connection configuration values' do
127
- expect(subject).to receive(:check_for_missing_config_values!)
128
- .with(:vra_username, :vra_password, :vra_base_url, :vra_tenant)
129
-
130
- subject.validate!
131
- end
132
- end
133
-
134
- describe '#check_for_missing_config_values!' do
135
- context 'when all values exist' do
136
- it 'does not raise an error' do
137
- allow(subject).to receive(:locate_config_value).with(:key1).and_return('value')
138
- allow(subject).to receive(:locate_config_value).with(:key2).and_return('value')
139
- expect(subject.ui).not_to receive(:error)
140
- expect { subject.check_for_missing_config_values!(:key1, :key2) }.not_to raise_error
141
- end
142
- end
143
-
144
- context 'when a value does not exist' do
145
- it 'prints an error and exits' do
146
- allow(subject).to receive(:locate_config_value).with(:key1).and_return('value')
147
- allow(subject).to receive(:locate_config_value).with(:key2).and_return(nil)
148
- expect(subject.ui).to receive(:error)
149
- expect { subject.check_for_missing_config_values!(:key1, :key2) }.to raise_error(SystemExit)
150
- end
151
- end
152
- end
153
- end
@@ -1,251 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
- # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require 'spec_helper'
21
- require 'chef/knife/cloud/exceptions'
22
- require 'chef/knife/cloud/vra_service'
23
- require 'support/shared_examples_for_service'
24
-
25
- describe Chef::Knife::Cloud::VraService do
26
- subject do
27
- Chef::Knife::Cloud::VraService.new(username: 'myuser',
28
- password: 'mypassword',
29
- base_url: 'https://vra.corp.local',
30
- tenant: 'mytenant',
31
- verify_ssl: true)
32
- end
33
-
34
- before(:each) do
35
- subject.ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
36
- allow(subject.ui).to receive(:msg).with('')
37
- end
38
-
39
- describe '#connection' do
40
- it 'creates a Vra::Client object' do
41
- expect(subject.connection).to be_an_instance_of(Vra::Client)
42
- end
43
- end
44
-
45
- describe '#create_server' do
46
- before(:each) do
47
- allow(subject.ui).to receive(:msg).with('Catalog request 1 submitted.')
48
- allow(subject.ui).to receive(:msg).with("Catalog request complete.\n")
49
- end
50
-
51
- context 'when the request is successful' do
52
- it 'calls all the appropriate methods' do
53
- submitted_request = double('submitted_request', id: 1, failed?: false)
54
- resource = double('resource', vm?: true)
55
- allow(submitted_request).to receive(:resources).and_return([resource])
56
- expect(subject).to receive_message_chain(:catalog_request, :submit).and_return(submitted_request)
57
- expect(subject).to receive(:wait_for_request)
58
- expect(subject).to receive(:request_summary)
59
-
60
- server = subject.create_server
61
- expect(server).to eq resource
62
- end
63
- end
64
-
65
- context 'when the request failed' do
66
- it 'raises an exception' do
67
- submitted_request = double('submitted_request', id: 1, failed?: true, completion_details: 'it failed')
68
- expect(subject).to receive_message_chain(:catalog_request, :submit).and_return(submitted_request)
69
- expect(subject).to receive(:wait_for_request)
70
- expect(subject).to receive(:request_summary)
71
-
72
- expect { subject.create_server }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerCreateError)
73
- end
74
- end
75
-
76
- context 'when the request returns no resources' do
77
- it 'raises an exception' do
78
- submitted_request = double('submitted_request', id: 1, failed?: false)
79
- allow(submitted_request).to receive(:resources).and_return([])
80
- expect(subject).to receive_message_chain(:catalog_request, :submit).and_return(submitted_request)
81
- expect(subject).to receive(:wait_for_request)
82
- expect(subject).to receive(:request_summary)
83
-
84
- expect { subject.create_server }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerCreateError)
85
- end
86
- end
87
-
88
- context 'when the request returns more than one VM resource' do
89
- it 'raises an exception' do
90
- submitted_request = double('submitted_request', id: 1, failed?: false)
91
- resource1 = double('resource1', vm?: true)
92
- resource2 = double('resource2', vm?: true)
93
- allow(submitted_request).to receive(:resources).and_return([resource1, resource2])
94
- expect(subject).to receive_message_chain(:catalog_request, :submit).and_return(submitted_request)
95
- expect(subject).to receive(:wait_for_request)
96
- expect(subject).to receive(:request_summary)
97
-
98
- expect { subject.create_server }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerCreateError)
99
- end
100
- end
101
-
102
- context 'when the request returns multiple resources, but only 1 VM' do
103
- it 'happily returns the server resource' do
104
- submitted_request = double('submitted_request', id: 1, failed?: false)
105
- resource1 = double('resource1', vm?: true)
106
- resource2 = double('resource2', vm?: false)
107
- allow(submitted_request).to receive(:resources).and_return([resource1, resource2])
108
- expect(subject).to receive_message_chain(:catalog_request, :submit).and_return(submitted_request)
109
- expect(subject).to receive(:wait_for_request)
110
- expect(subject).to receive(:request_summary)
111
-
112
- server = subject.create_server
113
- expect(server).to eq resource1
114
- end
115
- end
116
- end
117
-
118
- describe '#delete_server' do
119
- context 'when the server exists' do
120
- it 'calls the appropriate methods' do
121
- server = double('server', status: 'ACTIVE')
122
- destroy_request = double('destroy_request', id: 1)
123
- expect(subject).to receive(:get_server).with('12345').and_return(server)
124
- expect(subject).to receive(:server_summary).with(server)
125
- expect(subject.ui).to receive(:confirm)
126
- expect(server).to receive(:destroy).and_return(destroy_request)
127
- expect(subject.ui).to receive(:msg).with('Destroy request 1 submitted.')
128
- expect(subject).to receive(:wait_for_request)
129
- expect(subject.ui).to receive(:msg).with('Destroy request complete.')
130
- expect(subject).to receive(:request_summary)
131
-
132
- subject.delete_server('12345')
133
- end
134
- end
135
-
136
- context 'when the server is already deleted' do
137
- it 'does not call #destroy on the server object' do
138
- server = double('server', status: 'DELETED')
139
- expect(subject).to receive(:get_server).with('12345').and_return(server)
140
- expect(subject).to receive(:server_summary).with(server)
141
- expect(subject.ui).to receive(:warn).with("Server is already deleted.\n")
142
- expect(server).not_to receive(:destroy)
143
-
144
- subject.delete_server('12345')
145
- end
146
- end
147
- end
148
-
149
- describe '#list_servers' do
150
- it 'calls all_resources' do
151
- expect(subject).to receive_message_chain(:connection, :resources, :all_resources)
152
- .and_return([])
153
-
154
- subject.list_servers
155
- end
156
- end
157
-
158
- describe '#list_catalog_items' do
159
- context 'when requesting entitled items only' do
160
- it 'calls entitled_items' do
161
- expect(subject).to receive_message_chain(:connection, :catalog, :entitled_items)
162
-
163
- subject.list_catalog_items(true)
164
- end
165
- end
166
-
167
- context 'when requesting all items' do
168
- it 'calls all_items' do
169
- expect(subject).to receive_message_chain(:connection, :catalog, :all_items)
170
-
171
- subject.list_catalog_items(false)
172
- end
173
- end
174
- end
175
-
176
- describe '#get_server' do
177
- it 'calls resources.by_id' do
178
- expect(subject).to receive_message_chain(:connection, :resources, :by_id).with('12345')
179
-
180
- subject.get_server('12345')
181
- end
182
- end
183
-
184
- describe '#catalog_request' do
185
- context 'when handling a proper request' do
186
- it 'calls the appropriate methods' do
187
- catalog_request = double('catalog_request')
188
- expect(catalog_request).to receive(:cpus=).with(1)
189
- expect(catalog_request).to receive(:memory=).with(512)
190
- expect(catalog_request).to receive(:requested_for=).with('myuser@corp.local')
191
- expect(catalog_request).to receive(:lease_days=).with(5)
192
- expect(catalog_request).to receive(:notes=).with('my notes')
193
- expect(catalog_request).to receive(:subtenant_id=).with('tenant1')
194
- expect(subject).to receive_message_chain(:connection, :catalog, :request)
195
- .with('12345')
196
- .and_return(catalog_request)
197
-
198
- subject.catalog_request(catalog_id: '12345',
199
- cpus: 1,
200
- memory: 512,
201
- requested_for: 'myuser@corp.local',
202
- lease_days: 5,
203
- notes: 'my notes',
204
- subtenant_id: 'tenant1')
205
- end
206
- end
207
-
208
- context 'when optional arguments are missing' do
209
- it 'does not call the attr setters for the missing attributes' do
210
- catalog_request = double('catalog_request')
211
- expect(catalog_request).to receive(:cpus=).with(1)
212
- expect(catalog_request).to receive(:memory=).with(512)
213
- expect(catalog_request).to receive(:requested_for=).with('myuser@corp.local')
214
- expect(catalog_request).to_not receive(:lease_days=)
215
- expect(catalog_request).to_not receive(:notes=)
216
- expect(catalog_request).to_not receive(:subtenant_id=)
217
- expect(subject).to receive_message_chain(:connection, :catalog, :request)
218
- .with('12345')
219
- .and_return(catalog_request)
220
-
221
- subject.catalog_request(catalog_id: '12345',
222
- cpus: 1,
223
- memory: 512,
224
- requested_for: 'myuser@corp.local')
225
- end
226
- end
227
-
228
- context 'when extra parameters are supplied' do
229
- it 'calls set_parameter on the catalog_request' do
230
- catalog_request = double('catalog_request')
231
- expect(catalog_request).to receive(:cpus=).with(1)
232
- expect(catalog_request).to receive(:memory=).with(512)
233
- expect(catalog_request).to receive(:requested_for=).with('myuser@corp.local')
234
- expect(catalog_request).to receive(:set_parameter).with('key1', 'string', 'value1')
235
- expect(catalog_request).to receive(:set_parameter).with('key2', 'integer', '2')
236
- expect(subject).to receive_message_chain(:connection, :catalog, :request)
237
- .with('12345')
238
- .and_return(catalog_request)
239
-
240
- subject.catalog_request(catalog_id: '12345',
241
- cpus: 1,
242
- memory: 512,
243
- requested_for: 'myuser@corp.local',
244
- extra_params: [
245
- { key: 'key1', type: 'string', value: 'value1' },
246
- { key: 'key2', type: 'integer', value: '2' }
247
- ])
248
- end
249
- end
250
- end
251
- end