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.
- checksums.yaml +5 -5
- data/{LICENSE.txt → LICENSE} +0 -0
- data/lib/chef/knife/cloud/vra_service.rb +28 -28
- data/lib/chef/knife/cloud/vra_service_helpers.rb +15 -15
- data/lib/chef/knife/cloud/vra_service_options.rb +16 -16
- data/lib/chef/knife/vra_catalog_list.rb +25 -20
- data/lib/chef/knife/vra_server_create.rb +52 -49
- data/lib/chef/knife/vra_server_delete.rb +13 -10
- data/lib/chef/knife/vra_server_list.rb +19 -16
- data/lib/chef/knife/vra_server_show.rb +14 -11
- data/lib/chef/knife/vro_workflow_execute.rb +34 -35
- data/lib/knife-vrealize/version.rb +2 -2
- metadata +19 -113
- data/.github/ISSUE_TEMPLATE.md +0 -23
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -19
- data/.travis.yml +0 -27
- data/CHANGELOG.md +0 -118
- data/Gemfile +0 -4
- data/Jenkinsfile +0 -28
- data/README.md +0 -217
- data/Rakefile +0 -21
- data/knife-vrealize.gemspec +0 -34
- data/spec/spec_helper.rb +0 -18
- data/spec/unit/cloud/vra_service_helpers_spec.rb +0 -153
- data/spec/unit/cloud/vra_service_spec.rb +0 -251
- data/spec/unit/vra_catalog_list_spec.rb +0 -44
- data/spec/unit/vra_server_create_spec.rb +0 -171
- data/spec/unit/vra_server_delete_spec.rb +0 -64
- data/spec/unit/vra_server_list_spec.rb +0 -51
- data/spec/unit/vra_server_show_spec.rb +0 -44
- data/spec/unit/vro_workflow_execute_spec.rb +0 -366
@@ -1,44 +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/vra_catalog_list'
|
22
|
-
require 'support/shared_examples_for_command'
|
23
|
-
|
24
|
-
describe Chef::Knife::Cloud::VraCatalogList do
|
25
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::VraCatalogList.new
|
26
|
-
|
27
|
-
subject { described_class.new }
|
28
|
-
|
29
|
-
describe '#format_status_value' do
|
30
|
-
context 'when the status is "published"' do
|
31
|
-
it 'displays with green' do
|
32
|
-
expect(subject.ui).to receive(:color).with('published', :green)
|
33
|
-
subject.format_status_value('published')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when the status it not "published"' do
|
38
|
-
it 'displays with red' do
|
39
|
-
expect(subject.ui).to receive(:color).with('unpublished', :red)
|
40
|
-
subject.format_status_value('unpublished')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,171 +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/vra_server_create'
|
22
|
-
require 'support/shared_examples_for_command'
|
23
|
-
require 'support/shared_examples_for_servercreatecommand'
|
24
|
-
|
25
|
-
describe Chef::Knife::Cloud::VraServerCreate do
|
26
|
-
before(:each) do
|
27
|
-
Chef::Config.reset
|
28
|
-
end
|
29
|
-
|
30
|
-
argv = []
|
31
|
-
argv += %w(--cpus 1)
|
32
|
-
argv += %w(--memory 512)
|
33
|
-
argv += %w(--requested-for myuser@corp.local)
|
34
|
-
argv += %w(--bootstrap-protocol ssh)
|
35
|
-
argv += %w(--ssh-password password)
|
36
|
-
argv += %w(--extra-param key1=string:value1)
|
37
|
-
argv += %w(--extra-param key2=integer:2)
|
38
|
-
argv += %w(d5ba201a-449f-47a4-9d02-39196224bf01)
|
39
|
-
|
40
|
-
subject { Chef::Knife::Cloud::VraServerCreate.new(argv) }
|
41
|
-
|
42
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::VraServerCreate.new(argv)
|
43
|
-
it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, Chef::Knife::Cloud::VraServerCreate.new(argv)
|
44
|
-
|
45
|
-
describe '#validate_params!' do
|
46
|
-
context 'when no catalog ID is supplied' do
|
47
|
-
it 'raises an error' do
|
48
|
-
argv = []
|
49
|
-
argv += %w(--cpus 1)
|
50
|
-
argv += %w(--memory 512)
|
51
|
-
argv += %w(--requested-for myuser@corp.local)
|
52
|
-
argv += %w(--bootstrap-protocol ssh)
|
53
|
-
argv += %w(--ssh-password password)
|
54
|
-
|
55
|
-
command = Chef::Knife::Cloud::VraServerCreate.new(argv)
|
56
|
-
expect(command.ui).to receive(:error)
|
57
|
-
expect { command.validate_params! }.to raise_error(SystemExit)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'validates extra parameters' do
|
62
|
-
expect(subject).to receive(:validate_extra_params!)
|
63
|
-
subject.validate_params!
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#extra_params' do
|
68
|
-
context 'when there are no extra params' do
|
69
|
-
before do
|
70
|
-
Chef::Config[:knife][:vra_extra_params] = {}
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns nil' do
|
74
|
-
expect(subject.extra_params).to eq(nil)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'when extra params are provided' do
|
79
|
-
before do
|
80
|
-
Chef::Config[:knife][:vra_extra_params] = {
|
81
|
-
'key1' => 'string:value1',
|
82
|
-
'key2' => 'integer:2'
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'parses extra parameters properly' do
|
87
|
-
params = subject.extra_params
|
88
|
-
expect(params[0][:key]).to eq 'key1'
|
89
|
-
expect(params[0][:type]).to eq 'string'
|
90
|
-
expect(params[0][:value]).to eq 'value1'
|
91
|
-
expect(params[1][:key]).to eq 'key2'
|
92
|
-
expect(params[1][:type]).to eq 'integer'
|
93
|
-
expect(params[1][:value]).to eq '2'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#validate_extra_params!' do
|
99
|
-
context 'when no extra parameters are supplied' do
|
100
|
-
it 'does not raise an exception' do
|
101
|
-
argv = []
|
102
|
-
argv += %w(--cpus 1)
|
103
|
-
argv += %w(--memory 512)
|
104
|
-
argv += %w(--requested-for myuser@corp.local)
|
105
|
-
argv += %w(--bootstrap-protocol ssh)
|
106
|
-
argv += %w(--ssh-password password)
|
107
|
-
command = Chef::Knife::Cloud::VraServerCreate.new(argv)
|
108
|
-
|
109
|
-
expect { command.validate_extra_params! }.not_to raise_error
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when correct parameters are supplied' do
|
114
|
-
it 'does not raise an exception' do
|
115
|
-
expect { subject.validate_extra_params! }.not_to raise_error
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when a type or value is missing' do
|
120
|
-
it 'raises an exception' do
|
121
|
-
argv = []
|
122
|
-
argv += %w(--cpus 1)
|
123
|
-
argv += %w(--memory 512)
|
124
|
-
argv += %w(--requested-for myuser@corp.local)
|
125
|
-
argv += %w(--bootstrap-protocol ssh)
|
126
|
-
argv += %w(--ssh-password password)
|
127
|
-
argv += %w(d5ba201a-449f-47a4-9d02-39196224bf01)
|
128
|
-
argv += %w(--extra-param key1=value1)
|
129
|
-
command = Chef::Knife::Cloud::VraServerCreate.new(argv)
|
130
|
-
|
131
|
-
expect { command.validate_extra_params! }.to raise_error(ArgumentError)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'when an invalid parameter type is provided' do
|
136
|
-
it 'raises an exception' do
|
137
|
-
argv = []
|
138
|
-
argv += %w(--cpus 1)
|
139
|
-
argv += %w(--memory 512)
|
140
|
-
argv += %w(--requested-for myuser@corp.local)
|
141
|
-
argv += %w(--bootstrap-protocol ssh)
|
142
|
-
argv += %w(--ssh-password password)
|
143
|
-
argv += %w(d5ba201a-449f-47a4-9d02-39196224bf01)
|
144
|
-
argv += %w(--extra-param key1=faketype:value1)
|
145
|
-
command = Chef::Knife::Cloud::VraServerCreate.new(argv)
|
146
|
-
|
147
|
-
expect { command.validate_extra_params! }.to raise_error(ArgumentError)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#hostname_for_server' do
|
153
|
-
let(:server) { double('server') }
|
154
|
-
let(:ip_addresses) { [ '1.2.3.4' ] }
|
155
|
-
|
156
|
-
it 'returns the IP address if it exists' do
|
157
|
-
allow(subject).to receive(:server).and_return(server)
|
158
|
-
allow(server).to receive(:ip_addresses).and_return(ip_addresses)
|
159
|
-
|
160
|
-
expect(subject.hostname_for_server).to eq('1.2.3.4')
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'returns the hostname if the IP address is missing' do
|
164
|
-
allow(subject).to receive(:server).and_return(server)
|
165
|
-
allow(server).to receive(:ip_addresses).and_return([])
|
166
|
-
allow(server).to receive(:name).and_return('test_name')
|
167
|
-
|
168
|
-
expect(subject.hostname_for_server).to eq('test_name')
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
@@ -1,64 +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/vra_server_delete'
|
22
|
-
require 'support/shared_examples_for_command'
|
23
|
-
require 'support/shared_examples_for_serverdeletecommand'
|
24
|
-
|
25
|
-
describe Chef::Knife::Cloud::VraServerDelete do
|
26
|
-
subject { Chef::Knife::Cloud::VraServerDelete.new(%w(12345 54321)) }
|
27
|
-
|
28
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::VraServerDelete.new(%w(12345 54321))
|
29
|
-
|
30
|
-
describe '#validate_params!' do
|
31
|
-
context 'when no resource IDs are supplied' do
|
32
|
-
let(:command) { Chef::Knife::Cloud::VraServerDelete.new }
|
33
|
-
it 'prints an error and exits' do
|
34
|
-
expect(command.ui).to receive(:error)
|
35
|
-
expect { command.validate_params! }.to raise_error(SystemExit)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#execute_command' do
|
41
|
-
before(:each) do
|
42
|
-
server1 = double('server1', name: 'server1')
|
43
|
-
server2 = double('server2', name: 'server2')
|
44
|
-
allow(subject).to receive_message_chain(:service, :get_server).with('12345').and_return(server1)
|
45
|
-
allow(subject).to receive_message_chain(:service, :get_server).with('54321').and_return(server2)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'calls delete_server for each server' do
|
49
|
-
allow(subject).to receive(:delete_from_chef).with('server1')
|
50
|
-
allow(subject).to receive(:delete_from_chef).with('server2')
|
51
|
-
expect(subject).to receive_message_chain(:service, :delete_server).with('12345')
|
52
|
-
expect(subject).to receive_message_chain(:service, :delete_server).with('54321')
|
53
|
-
subject.execute_command
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'calls delete_from_chef using the server names for each server' do
|
57
|
-
allow(subject).to receive_message_chain(:service, :delete_server).with('12345')
|
58
|
-
allow(subject).to receive_message_chain(:service, :delete_server).with('54321')
|
59
|
-
expect(subject).to receive(:delete_from_chef).with('server1')
|
60
|
-
expect(subject).to receive(:delete_from_chef).with('server2')
|
61
|
-
subject.execute_command
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,51 +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/vra_server_list'
|
22
|
-
require 'support/shared_examples_for_command'
|
23
|
-
|
24
|
-
describe Chef::Knife::Cloud::VraServerList do
|
25
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::VraServerList.new
|
26
|
-
|
27
|
-
subject { described_class.new }
|
28
|
-
|
29
|
-
describe '#format_status_value' do
|
30
|
-
context 'when the status is "active"' do
|
31
|
-
it 'displays with green' do
|
32
|
-
expect(subject.ui).to receive(:color).with('active', :green)
|
33
|
-
subject.format_status_value('active')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when the status is "deleted"' do
|
38
|
-
it 'displays with red' do
|
39
|
-
expect(subject.ui).to receive(:color).with('deleted', :red)
|
40
|
-
subject.format_status_value('deleted')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when the status is anything else' do
|
45
|
-
it 'displays with yellow' do
|
46
|
-
expect(subject.ui).to receive(:color).with('unknown', :yellow)
|
47
|
-
subject.format_status_value('unknown')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,44 +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/vra_server_show'
|
22
|
-
require 'support/shared_examples_for_command'
|
23
|
-
|
24
|
-
describe Chef::Knife::Cloud::VraServerShow do
|
25
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::VraServerShow.new
|
26
|
-
|
27
|
-
describe '#validate_params!' do
|
28
|
-
context 'when no resources are supplied' do
|
29
|
-
let(:command) { Chef::Knife::Cloud::VraServerShow.new }
|
30
|
-
it 'prints an error and exits' do
|
31
|
-
expect(command.ui).to receive(:error)
|
32
|
-
expect { command.validate_params! }.to raise_error(SystemExit)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when more than one resource is supplied' do
|
37
|
-
let(:command) { Chef::Knife::Cloud::VraServerShow.new(%w(12345 54321)) }
|
38
|
-
it 'prints an error and exits' do
|
39
|
-
expect(command.ui).to receive(:error)
|
40
|
-
expect { command.validate_params! }.to raise_error(SystemExit)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,366 +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/vro_workflow_execute'
|
22
|
-
|
23
|
-
describe Chef::Knife::VroWorkflowExecute do
|
24
|
-
let(:workflow_name) { 'test workflow' }
|
25
|
-
let(:workflow_id) { '1d335f85-5328-42fc-a842-a956d1ccdf08' }
|
26
|
-
let(:vro_username) { 'myuser' }
|
27
|
-
let(:vro_password) { 'mypassword' }
|
28
|
-
let(:vro_base_url) { 'https://vro.corp.local' }
|
29
|
-
let(:vro_disable_ssl_verify) { true }
|
30
|
-
let(:key1) { 'value1' }
|
31
|
-
let(:key2) { '2' }
|
32
|
-
|
33
|
-
let(:argv) do
|
34
|
-
[ workflow_name,
|
35
|
-
"key1=#{key1}",
|
36
|
-
"key2=#{key2}",
|
37
|
-
'--vro-workflow-id', workflow_id]
|
38
|
-
end
|
39
|
-
|
40
|
-
subject { described_class.new(argv) }
|
41
|
-
|
42
|
-
before(:each) do
|
43
|
-
Chef::Config[:knife][:vro_username] = vro_username
|
44
|
-
Chef::Config[:knife][:vro_password] = vro_password
|
45
|
-
Chef::Config[:knife][:vro_base_url] = vro_base_url
|
46
|
-
Chef::Config[:knife][:vro_disable_ssl_verify] = vro_disable_ssl_verify
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#verify_ssl?' do
|
50
|
-
context 'when vro_disable_ssl_verify is set to true' do
|
51
|
-
let(:vro_disable_ssl_verify) { true }
|
52
|
-
it 'returns false' do
|
53
|
-
expect(subject.verify_ssl?).to eq(false)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when vro_disable_ssl_verify is set to false' do
|
58
|
-
let(:vro_disable_ssl_verify) { false }
|
59
|
-
it 'returns true' do
|
60
|
-
expect(subject.verify_ssl?).to eq(true)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#vro_config' do
|
66
|
-
it 'creates a config object' do
|
67
|
-
expect(VcoWorkflows::Config).to receive(:new).with(url: vro_base_url,
|
68
|
-
username: vro_username,
|
69
|
-
password: vro_password,
|
70
|
-
verify_ssl: false)
|
71
|
-
subject.vro_config
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#vro_client' do
|
76
|
-
it 'creates a client object' do
|
77
|
-
config = double('config')
|
78
|
-
allow(subject).to receive(:vro_config).and_return(config)
|
79
|
-
expect(VcoWorkflows::Workflow).to receive(:new).with(workflow_name,
|
80
|
-
id: workflow_id,
|
81
|
-
config: config)
|
82
|
-
|
83
|
-
subject.set_parameters
|
84
|
-
subject.vro_client
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#parse_and_validate_params' do
|
89
|
-
context 'when proper parameters are supplied' do
|
90
|
-
let(:args) { %w(key1=value1 key2=value2) }
|
91
|
-
it 'returns a hash of parameters' do
|
92
|
-
expect(subject.parse_and_validate_params!(args)).to eq('key1' => 'value1',
|
93
|
-
'key2' => 'value2')
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when a parameter is malformed' do
|
98
|
-
let(:args) { %w(key1=value1 key2) }
|
99
|
-
it 'raises an exception' do
|
100
|
-
expect { subject.parse_and_validate_params!(args) }.to raise_error(RuntimeError)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'execute_workflow' do
|
106
|
-
before do
|
107
|
-
config = double('config')
|
108
|
-
client = double('client')
|
109
|
-
allow(subject).to receive(:vro_config).and_return(config)
|
110
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
111
|
-
allow(client).to receive(:parameter)
|
112
|
-
allow(client).to receive(:execute)
|
113
|
-
subject.set_parameters
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'sets the workflow parameters' do
|
117
|
-
expect(subject.vro_client).to receive(:parameter).with('key1', key1)
|
118
|
-
expect(subject.vro_client).to receive(:parameter).with('key2', key2)
|
119
|
-
|
120
|
-
subject.execute_workflow
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'executes the workflow' do
|
124
|
-
expect(subject.vro_client).to receive(:execute)
|
125
|
-
subject.execute_workflow
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when execute fails with a RestClient::BadRequest' do
|
129
|
-
it 'prints an error with the HTTP response' do
|
130
|
-
HTTPResponse = Struct.new(:code, :to_s)
|
131
|
-
response = HTTPResponse.new(400, 'an HTTP error occurred')
|
132
|
-
exception = RestClient::BadRequest.new
|
133
|
-
exception.response = response
|
134
|
-
allow(subject.vro_client).to receive(:execute).and_raise(exception)
|
135
|
-
expect(subject.ui).to receive(:error).with('The workflow execution request failed: an HTTP error occurred')
|
136
|
-
expect { subject.execute_workflow }.to raise_error(RestClient::BadRequest)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context 'when execute fails with any other exception' do
|
141
|
-
it 'prints an error with the exception message' do
|
142
|
-
allow(subject.vro_client).to receive(:execute).and_raise(RuntimeError, 'a non-HTTP error occurred')
|
143
|
-
expect(subject.ui).to receive(:error).with('The workflow execution request failed: a non-HTTP error occurred')
|
144
|
-
expect { subject.execute_workflow }.to raise_error(RuntimeError)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe '#wait_for_workflow' do
|
150
|
-
before(:each) do
|
151
|
-
# don't actually sleep
|
152
|
-
allow(subject).to receive(:sleep)
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'when the requests completes normally, 3 loops' do
|
156
|
-
it 'only fetches the token 3 times' do
|
157
|
-
client = double('client')
|
158
|
-
token = double('token')
|
159
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
160
|
-
allow(client).to receive(:token).and_return(token)
|
161
|
-
allow(token).to receive(:alive?).exactly(3).times.and_return(true, true, false)
|
162
|
-
|
163
|
-
expect(subject.vro_client).to receive(:token).exactly(3).times
|
164
|
-
subject.wait_for_workflow
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'when the request is completed on the first loop' do
|
169
|
-
it 'only refreshes the request 1 time' do
|
170
|
-
client = double('client')
|
171
|
-
token = double('token')
|
172
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
173
|
-
allow(client).to receive(:token).and_return(token)
|
174
|
-
expect(token).to receive(:alive?).once.and_return(false)
|
175
|
-
|
176
|
-
subject.wait_for_workflow
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'when the timeout is exceeded' do
|
181
|
-
before do
|
182
|
-
Chef::Config[:knife][:request_timeout] = 600
|
183
|
-
end
|
184
|
-
it 'raises a Timeout exception' do
|
185
|
-
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
|
186
|
-
expect { subject.wait_for_workflow }.to raise_error(
|
187
|
-
Timeout::Error, 'Workflow did not complete in 600 seconds. ' \
|
188
|
-
'Please check the vRO UI for more information.' \
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'when a non-timeout exception is raised' do
|
194
|
-
it 'raises the original exception' do
|
195
|
-
client = double('client')
|
196
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
197
|
-
allow(client).to receive(:token).and_raise(RuntimeError, 'an error occurred')
|
198
|
-
expect { subject.wait_for_workflow }.to raise_error(RuntimeError, 'an error occurred')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#missing_config_parameters' do
|
204
|
-
context 'when all parameters are supplied' do
|
205
|
-
it 'returns an empty array' do
|
206
|
-
expect(subject.missing_config_parameters).to eq([])
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'when a parameter is missing' do
|
211
|
-
before do
|
212
|
-
Chef::Config[:knife][:vro_username] = nil
|
213
|
-
end
|
214
|
-
it 'returns an array with that parameter' do
|
215
|
-
expect(subject.missing_config_parameters).to eq([ :vro_username ])
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe '#validate!' do
|
221
|
-
context 'when a config parameter is missing' do
|
222
|
-
it 'calls #print_error_and_exit' do
|
223
|
-
allow(subject).to receive(:missing_config_parameters).and_return([ :parameter ])
|
224
|
-
expect(subject).to receive(:print_error_and_exit)
|
225
|
-
|
226
|
-
subject.validate!
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
context 'when no workflow name is provided' do
|
231
|
-
let(:knife) { Chef::Knife::VroWorkflowExecute.new }
|
232
|
-
it 'calls #print_error_and_exit' do
|
233
|
-
expect(knife).to receive(:print_error_and_exit)
|
234
|
-
|
235
|
-
knife.validate!
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe '#print_error_and_exit' do
|
241
|
-
it 'prints an error and exits' do
|
242
|
-
expect(subject.ui).to receive(:error).with('an error occurred')
|
243
|
-
expect { subject.print_error_and_exit('an error occurred') }.to raise_error(SystemExit)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe '#print_results' do
|
248
|
-
it 'prints a blank line and calls the other print methods' do
|
249
|
-
expect(subject.ui).to receive(:msg).with('')
|
250
|
-
expect(subject).to receive(:print_output_parameters)
|
251
|
-
expect(subject).to receive(:print_execution_log)
|
252
|
-
|
253
|
-
subject.print_results
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
describe '#print_output_parameters' do
|
258
|
-
context 'when there are no output parameters' do
|
259
|
-
before do
|
260
|
-
client = double('client')
|
261
|
-
token = double('token')
|
262
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
263
|
-
allow(client).to receive(:token).and_return(token)
|
264
|
-
allow(token).to receive(:output_parameters).and_return({})
|
265
|
-
end
|
266
|
-
|
267
|
-
it 'does not print any output' do
|
268
|
-
expect(subject.ui).not_to receive(:msg)
|
269
|
-
|
270
|
-
subject.print_output_parameters
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context 'when output parameters exist' do
|
275
|
-
before do
|
276
|
-
client = double('client')
|
277
|
-
token = double('token')
|
278
|
-
param1 = double('param1', value: 'value1', type: 'string')
|
279
|
-
param2 = double('param2', value: 2.0, type: 'number')
|
280
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
281
|
-
allow(client).to receive(:token).and_return(token)
|
282
|
-
allow(token).to receive(:output_parameters).and_return(
|
283
|
-
'key1' => param1,
|
284
|
-
'key2' => param2
|
285
|
-
)
|
286
|
-
|
287
|
-
# squelch output during testing
|
288
|
-
allow(subject.ui).to receive(:msg)
|
289
|
-
allow(subject).to receive(:msg_pair)
|
290
|
-
end
|
291
|
-
|
292
|
-
it 'prints a header and a blank line' do
|
293
|
-
header = subject.ui.color('Output Parameters:', :bold)
|
294
|
-
expect(subject.ui).to receive(:msg).with(header)
|
295
|
-
expect(subject.ui).to receive(:msg).with('')
|
296
|
-
|
297
|
-
subject.print_output_parameters
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'prints out the output parameters' do
|
301
|
-
expect(subject).to receive(:msg_pair).with('key1', 'value1 (string)')
|
302
|
-
expect(subject).to receive(:msg_pair).with('key2', '2.0 (number)')
|
303
|
-
|
304
|
-
subject.print_output_parameters
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe '#print_execution_log' do
|
310
|
-
context 'when the log is empty' do
|
311
|
-
before do
|
312
|
-
client = double('client', log: nil)
|
313
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'does not print any information' do
|
317
|
-
expect(subject.ui).not_to receive(:msg)
|
318
|
-
|
319
|
-
subject.print_execution_log
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
context 'when the log exists' do
|
324
|
-
before do
|
325
|
-
client = double('client', log: 'log entries go here')
|
326
|
-
allow(subject).to receive(:vro_client).and_return(client)
|
327
|
-
end
|
328
|
-
|
329
|
-
it 'prints a header and the log entry' do
|
330
|
-
header = subject.ui.color('Workflow Execution Log:', :bold)
|
331
|
-
expect(subject.ui).to receive(:msg).with(header)
|
332
|
-
expect(subject.ui).to receive(:msg).with('log entries go here')
|
333
|
-
|
334
|
-
subject.print_execution_log
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe '#set_parameters' do
|
340
|
-
it 'sets the instance variables correctly' do
|
341
|
-
subject.set_parameters
|
342
|
-
|
343
|
-
expect(subject.workflow_name).to eq(workflow_name)
|
344
|
-
expect(subject.workflow_id).to eq(workflow_id)
|
345
|
-
expect(subject.parameters).to eq(
|
346
|
-
'key1' => 'value1',
|
347
|
-
'key2' => '2'
|
348
|
-
)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe '#run' do
|
353
|
-
it 'calls the correct methods' do
|
354
|
-
expect(subject).to receive(:validate!)
|
355
|
-
expect(subject).to receive(:set_parameters)
|
356
|
-
expect(subject.ui).to receive(:msg).with('Starting workflow execution...')
|
357
|
-
expect(subject).to receive(:execute_workflow).and_return('12345')
|
358
|
-
expect(subject.ui).to receive(:msg).with('Workflow execution 12345 started. Waiting for it to complete...')
|
359
|
-
expect(subject).to receive(:wait_for_workflow)
|
360
|
-
expect(subject.ui).to receive(:msg).with('Workflow execution complete.')
|
361
|
-
expect(subject).to receive(:print_results)
|
362
|
-
|
363
|
-
subject.run
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|