knife-openstack 2.0.1 → 4.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/lib/chef/knife/cloud/openstack_server_create_options.rb +64 -51
- data/lib/chef/knife/cloud/openstack_service.rb +33 -17
- data/lib/chef/knife/cloud/openstack_service_options.rb +34 -24
- data/lib/chef/knife/openstack_flavor_list.rb +18 -4
- data/lib/chef/knife/openstack_floating_ip_allocate.rb +22 -9
- data/lib/chef/knife/openstack_floating_ip_associate.rb +24 -12
- data/lib/chef/knife/openstack_floating_ip_disassociate.rb +25 -12
- data/lib/chef/knife/openstack_floating_ip_list.rb +18 -4
- data/lib/chef/knife/openstack_floating_ip_release.rb +16 -4
- data/lib/chef/knife/openstack_group_list.rb +21 -4
- data/lib/chef/knife/openstack_helpers.rb +20 -4
- data/lib/chef/knife/openstack_image_list.rb +22 -8
- data/lib/chef/knife/openstack_network_list.rb +18 -4
- data/lib/chef/knife/openstack_server_create.rb +36 -35
- data/lib/chef/knife/openstack_server_delete.rb +17 -5
- data/lib/chef/knife/openstack_server_list.rb +5 -6
- data/lib/chef/knife/openstack_server_show.rb +4 -5
- data/lib/chef/knife/openstack_volume_list.rb +10 -9
- data/lib/knife-openstack/version.rb +2 -2
- metadata +17 -91
- data/.github/ISSUE_TEMPLATE.md +0 -21
- data/.gitignore +0 -32
- data/.travis.yml +0 -10
- data/CHANGELOG.md +0 -335
- data/CONTRIBUTING.MD +0 -164
- data/Gemfile +0 -21
- data/README.md +0 -179
- data/Rakefile +0 -27
- data/knife-openstack.gemspec +0 -30
- data/spec/functional/flavor_list_func_spec.rb +0 -47
- data/spec/functional/floating_ip_list_func_spec.rb +0 -48
- data/spec/functional/group_list_func_spec.rb +0 -65
- data/spec/functional/image_list_func_spec.rb +0 -53
- data/spec/functional/network_list_func_spec.rb +0 -46
- data/spec/functional/server_create_func_spec.rb +0 -118
- data/spec/functional/server_delete_func_spec.rb +0 -84
- data/spec/functional/server_list_func_spec.rb +0 -98
- data/spec/functional/server_show_func_spec.rb +0 -46
- data/spec/functional/volume_list_func_spec.rb +0 -46
- data/spec/integration/cleanup.rb +0 -89
- data/spec/integration/config/environment.yml.sample +0 -13
- data/spec/integration/openstack_spec.rb +0 -649
- data/spec/spec_context.rb +0 -56
- data/spec/spec_helper.rb +0 -128
- data/spec/unit/openstack_flavor_list_spec.rb +0 -30
- data/spec/unit/openstack_floating_ip_allocate_spec.rb +0 -56
- data/spec/unit/openstack_floating_ip_associate_spec.rb +0 -40
- data/spec/unit/openstack_floating_ip_disassociate_spec.rb +0 -39
- data/spec/unit/openstack_floating_ip_list_spec.rb +0 -27
- data/spec/unit/openstack_floating_ip_release_spec.rb +0 -49
- data/spec/unit/openstack_group_list_spec.rb +0 -44
- data/spec/unit/openstack_image_list_spec.rb +0 -32
- data/spec/unit/openstack_network_list_spec.rb +0 -39
- data/spec/unit/openstack_server_create_spec.rb +0 -449
- data/spec/unit/openstack_server_delete_spec.rb +0 -43
- data/spec/unit/openstack_server_list_spec.rb +0 -32
- data/spec/unit/openstack_server_show_spec.rb +0 -42
- data/spec/unit/openstack_service_spec.rb +0 -128
- data/spec/unit/openstack_volume_list_spec.rb +0 -30
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
|
4
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
5
|
-
# Author:: Ameya Varade (<ameya.varade@clogeny.com>)
|
6
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
7
|
-
# License:: Apache License, Version 2.0
|
8
|
-
#
|
9
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
-
# you may not use this file except in compliance with the License.
|
11
|
-
# You may obtain a copy of the License at
|
12
|
-
#
|
13
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
-
#
|
15
|
-
# Unless required by applicable law or agreed to in writing, software
|
16
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
-
# See the License for the specific language governing permissions and
|
19
|
-
# limitations under the License.
|
20
|
-
|
21
|
-
require "spec_helper"
|
22
|
-
require "chef/knife/openstack_image_list"
|
23
|
-
require "chef/knife/cloud/openstack_service"
|
24
|
-
require "support/shared_examples_for_command"
|
25
|
-
|
26
|
-
describe Chef::Knife::Cloud::OpenstackImageList do
|
27
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackImageList.new
|
28
|
-
|
29
|
-
let (:instance) { Chef::Knife::Cloud::OpenstackImageList.new }
|
30
|
-
|
31
|
-
include_context "#validate!", Chef::Knife::Cloud::OpenstackImageList.new
|
32
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
|
-
# Author:: Ameya Varade (<ameya.varade@clogeny.com>)
|
5
|
-
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
6
|
-
# License:: Apache License, Version 2.0
|
7
|
-
#
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
-
# you may not use this file except in compliance with the License.
|
10
|
-
# You may obtain a copy of the License at
|
11
|
-
#
|
12
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
-
#
|
14
|
-
# Unless required by applicable law or agreed to in writing, software
|
15
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
-
# See the License for the specific language governing permissions and
|
18
|
-
# limitations under the License.
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "chef/knife/openstack_network_list"
|
22
|
-
require "chef/knife/cloud/openstack_service"
|
23
|
-
require "support/shared_examples_for_command"
|
24
|
-
|
25
|
-
describe Chef::Knife::Cloud::OpenstackNetworkList do
|
26
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new
|
27
|
-
|
28
|
-
let (:instance) { Chef::Knife::Cloud::OpenstackNetworkList.new }
|
29
|
-
|
30
|
-
include_context "#validate!", Chef::Knife::Cloud::OpenstackNetworkList.new
|
31
|
-
|
32
|
-
context "query_resource" do
|
33
|
-
it "returns the networks using the fog service." do
|
34
|
-
instance.service = double
|
35
|
-
expect(instance.service).to receive(:list_networks)
|
36
|
-
instance.query_resource
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,449 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
|
-
# Author:: Mukta Aphale (<mukta.aphale@clogeny.com>)
|
5
|
-
# Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
|
6
|
-
# Author:: Ameya Varade (<ameya.varade@clogeny.com>)
|
7
|
-
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
|
8
|
-
# License:: Apache License, Version 2.0
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
|
22
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
23
|
-
require "chef/knife/openstack_server_create"
|
24
|
-
require "support/shared_examples_for_servercreatecommand"
|
25
|
-
require "support/shared_examples_for_command"
|
26
|
-
|
27
|
-
describe Chef::Knife::Cloud::OpenstackServerCreate do
|
28
|
-
create_instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
29
|
-
create_instance.define_singleton_method(:post_connection_validations) {}
|
30
|
-
|
31
|
-
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerCreate.new
|
32
|
-
it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, create_instance
|
33
|
-
|
34
|
-
describe "#create_service_instance" do
|
35
|
-
before(:each) do
|
36
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
37
|
-
end
|
38
|
-
|
39
|
-
it "return OpenstackService instance" do
|
40
|
-
expect(@instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "has custom_arguments as its option" do
|
44
|
-
expect(@instance.options.include? :custom_attributes).to be true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#validate_params!" do
|
49
|
-
before(:each) do
|
50
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
51
|
-
allow(@instance.ui).to receive(:error)
|
52
|
-
Chef::Config[:knife][:bootstrap_protocol] = "ssh"
|
53
|
-
Chef::Config[:knife][:identity_file] = "identity_file"
|
54
|
-
Chef::Config[:knife][:image_os_type] = "linux"
|
55
|
-
Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key"
|
56
|
-
Chef::Config[:knife][:openstack_region] = "test-region"
|
57
|
-
end
|
58
|
-
|
59
|
-
after(:all) do
|
60
|
-
Chef::Config[:knife].delete(:bootstrap_protocol)
|
61
|
-
Chef::Config[:knife].delete(:identity_file)
|
62
|
-
Chef::Config[:knife].delete(:image_os_type)
|
63
|
-
Chef::Config[:knife].delete(:openstack_ssh_key_id)
|
64
|
-
Chef::Config[:knife].delete(:openstack_region)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "run sucessfully on all params exist" do
|
68
|
-
expect { @instance.validate_params! }.to_not raise_error
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#before_exec_command" do
|
73
|
-
before(:each) do
|
74
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
75
|
-
allow(@instance.ui).to receive(:error)
|
76
|
-
@instance.config[:chef_node_name] = "chef_node_name"
|
77
|
-
Chef::Config[:knife][:image] = "image"
|
78
|
-
Chef::Config[:knife][:flavor] = "flavor"
|
79
|
-
Chef::Config[:knife][:openstack_security_groups] = "openstack_security_groups"
|
80
|
-
Chef::Config[:knife][:server_create_timeout] = "server_create_timeout"
|
81
|
-
Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key"
|
82
|
-
Chef::Config[:knife][:network_ids] = "test_network_id"
|
83
|
-
allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids])
|
84
|
-
Chef::Config[:knife][:metadata] = "foo=bar"
|
85
|
-
end
|
86
|
-
|
87
|
-
after(:all) do
|
88
|
-
Chef::Config[:knife].delete(:image)
|
89
|
-
Chef::Config[:knife].delete(:flavor)
|
90
|
-
Chef::Config[:knife].delete(:openstack_ssh_key_id)
|
91
|
-
Chef::Config[:knife].delete(:openstack_security_groups)
|
92
|
-
Chef::Config[:knife].delete(:server_create_timeout)
|
93
|
-
Chef::Config[:knife].delete(:metadata)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "set create_options" do
|
97
|
-
@instance.service = double
|
98
|
-
allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image"))
|
99
|
-
allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor"))
|
100
|
-
expect(@instance.service).to receive(:create_server_dependencies)
|
101
|
-
expect(@instance).to receive(:post_connection_validations)
|
102
|
-
@instance.before_exec_command
|
103
|
-
expect(@instance.create_options[:server_def][:name]).to be == @instance.config[:chef_node_name]
|
104
|
-
expect(@instance.create_options[:server_def][:image_ref]).to be == Chef::Config[:knife][:image]
|
105
|
-
expect(@instance.create_options[:server_def][:security_groups]).to be == Chef::Config[:knife][:openstack_security_groups]
|
106
|
-
expect(@instance.create_options[:server_def][:flavor_ref]).to be == Chef::Config[:knife][:flavor]
|
107
|
-
expect(@instance.create_options[:server_def][:nics]).to be == Chef::Config[:knife][:network_ids]
|
108
|
-
expect(@instance.create_options[:server_def][:metadata]).to be == Chef::Config[:knife][:metadata]
|
109
|
-
expect(@instance.create_options[:server_def][:region]).to be == Chef::Config[:knife][:openstack_region]
|
110
|
-
expect(@instance.create_options[:server_create_timeout]).to be == Chef::Config[:knife][:server_create_timeout]
|
111
|
-
end
|
112
|
-
|
113
|
-
it "doesn't set user data in server_def if user_data not specified" do
|
114
|
-
@instance.service = double("Chef::Knife::Cloud::OpenstackService", create_server_dependencies: nil)
|
115
|
-
allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image"))
|
116
|
-
allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor"))
|
117
|
-
expect(@instance).to receive(:post_connection_validations)
|
118
|
-
@instance.before_exec_command
|
119
|
-
expect(@instance.create_options[:server_def]).to_not include(:user_data)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "sets user data" do
|
123
|
-
user_data = "echo 'hello world' >> /tmp/user_data.txt"
|
124
|
-
Chef::Config[:knife][:user_data] = user_data
|
125
|
-
@instance.service = double("Chef::Knife::Cloud::OpenstackService", create_server_dependencies: nil)
|
126
|
-
allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image"))
|
127
|
-
allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor"))
|
128
|
-
expect(@instance).to receive(:post_connection_validations)
|
129
|
-
@instance.before_exec_command
|
130
|
-
expect(@instance.create_options[:server_def][:user_data]).to be == user_data
|
131
|
-
end
|
132
|
-
|
133
|
-
context "with multiple network_ids specified" do
|
134
|
-
before(:each) do
|
135
|
-
@instance.service = double
|
136
|
-
allow(@instance.service).to receive(:get_image).and_return(get_mock_resource("image"))
|
137
|
-
allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource("flavor"))
|
138
|
-
expect(@instance.service).to receive(:create_server_dependencies)
|
139
|
-
Chef::Config[:knife][:network_ids] = "test_network_id1,test_network_id2"
|
140
|
-
allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids].split(","))
|
141
|
-
expect(@instance).to receive(:post_connection_validations)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "creates the server_def with multiple nic_ids." do
|
145
|
-
@instance.before_exec_command
|
146
|
-
expect(@instance.create_options[:server_def][:nics]).to be == %w{test_network_id1 test_network_id2}
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it "ensures default value for metadata" do
|
151
|
-
options = @instance.options
|
152
|
-
expect(options[:metadata][:default]).to be_nil
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe "#after_exec_command" do
|
157
|
-
before(:each) do
|
158
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
159
|
-
allow(@instance).to receive(:msg_pair)
|
160
|
-
end
|
161
|
-
|
162
|
-
after(:all) do
|
163
|
-
Chef::Config[:knife].delete(:openstack_floating_ip)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "don't set openstack_floating_ip on missing openstack_floating_ip option" do
|
167
|
-
# default openstack_floating_ip is '-1'
|
168
|
-
Chef::Config[:knife][:openstack_floating_ip] = "-1"
|
169
|
-
@instance.service = Chef::Knife::Cloud::Service.new
|
170
|
-
@instance.server = double
|
171
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] })
|
172
|
-
expect(@instance).to receive(:bootstrap)
|
173
|
-
@instance.after_exec_command
|
174
|
-
end
|
175
|
-
|
176
|
-
it "set openstack_floating_ip on openstack_floating_ip option" do
|
177
|
-
Chef::Config[:knife][:openstack_floating_ip] = nil
|
178
|
-
@instance.service = Chef::Knife::Cloud::Service.new
|
179
|
-
@instance.server = double
|
180
|
-
|
181
|
-
@network = double
|
182
|
-
@ports = ["id" => "test",
|
183
|
-
"fixed_ips" => ["ip_address" => "127.0.1.1"]]
|
184
|
-
allow(@network).to receive(:list_ports).and_return(body: { "ports" => @ports })
|
185
|
-
@floating_ips = ["id" => "test",
|
186
|
-
"fixed_ips" => ["ip_address" => "127.0.1.1"]]
|
187
|
-
allow(@network).to receive(:list_floating_ips).and_return(body: { "floatingips" => @floating_ips })
|
188
|
-
allow(@network).to receive(:associate_floating_ip)
|
189
|
-
allow(@instance.service).to receive(:network).and_return(@network)
|
190
|
-
|
191
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] })
|
192
|
-
expect(@instance).to receive(:bootstrap)
|
193
|
-
allow(@instance.service).to receive(:connection).and_return(double)
|
194
|
-
free_floating = Object.new
|
195
|
-
free_floating.define_singleton_method(:fixed_ip) { return nil }
|
196
|
-
free_floating.define_singleton_method(:ip) { return "127.0.0.1" }
|
197
|
-
expect(@instance.service.connection).to receive(:addresses).and_return([free_floating])
|
198
|
-
@instance.after_exec_command
|
199
|
-
end
|
200
|
-
|
201
|
-
it "raise error on unavailability of free_floating ip" do
|
202
|
-
Chef::Config[:knife][:openstack_floating_ip] = nil
|
203
|
-
@instance.service = Chef::Knife::Cloud::Service.new
|
204
|
-
allow(@instance.ui).to receive(:fatal)
|
205
|
-
@instance.server = double
|
206
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.1.1" }] })
|
207
|
-
expect(@instance).to_not receive(:bootstrap)
|
208
|
-
allow(@instance.service).to receive(:connection).and_return(double)
|
209
|
-
free_floating = Object.new
|
210
|
-
free_floating.define_singleton_method(:fixed_ip) { return "127.0.0.1" }
|
211
|
-
expect(@instance.service.connection).to receive(:addresses).and_return([free_floating])
|
212
|
-
expect { @instance.after_exec_command }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerSetupError, "Unable to assign a Floating IP from allocated IPs.")
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "#before_bootstrap" do
|
217
|
-
before(:each) do
|
218
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
219
|
-
@instance.server = double
|
220
|
-
# default bootstrap_network is public
|
221
|
-
@instance.config[:bootstrap_network] = "public"
|
222
|
-
# default no network is true
|
223
|
-
@instance.config[:network] = true
|
224
|
-
Chef::Config[:knife][:ssh_password] = "config_ssh_password"
|
225
|
-
end
|
226
|
-
|
227
|
-
after(:each) do
|
228
|
-
Chef::Config[:knife].delete(:ssh_password)
|
229
|
-
end
|
230
|
-
|
231
|
-
context "when no-network option specified" do
|
232
|
-
before(:each) { @instance.config[:network] = false }
|
233
|
-
|
234
|
-
it "set public ip as a bootstrap ip if both public and private ip available" do
|
235
|
-
allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] })
|
236
|
-
@instance.before_bootstrap
|
237
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
|
238
|
-
end
|
239
|
-
|
240
|
-
it "set private-ip as a bootstrap ip if private ip is available" do
|
241
|
-
allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
242
|
-
@instance.before_bootstrap
|
243
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
|
244
|
-
end
|
245
|
-
|
246
|
-
it "set available ip as a bootstrap ip if no public, private ip available" do
|
247
|
-
allow(@instance.server).to receive(:addresses).and_return({ 1 => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
248
|
-
@instance.before_bootstrap
|
249
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
it "set bootstrap_ip" do
|
254
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
255
|
-
@instance.before_bootstrap
|
256
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
|
257
|
-
end
|
258
|
-
|
259
|
-
it "set private-ip as a bootstrap-ip if private-network option set" do
|
260
|
-
allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] })
|
261
|
-
@instance.config[:private_network] = true
|
262
|
-
@instance.before_bootstrap
|
263
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
|
264
|
-
end
|
265
|
-
|
266
|
-
it "raise error on nil bootstrap_ip" do
|
267
|
-
allow(@instance.ui).to receive(:error)
|
268
|
-
|
269
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => nil }] })
|
270
|
-
expect { @instance.before_bootstrap }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, "No IP address available for bootstrapping.")
|
271
|
-
end
|
272
|
-
|
273
|
-
it "set public ip as default bootstrap network is public" do
|
274
|
-
allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }], "public" => [{ "version" => 4, "addr" => "127.0.0.2" }] })
|
275
|
-
@instance.before_bootstrap
|
276
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
|
277
|
-
end
|
278
|
-
|
279
|
-
it "configures the bootstrap to use alternate network" do
|
280
|
-
allow(@instance.server).to receive(:addresses).and_return({ "foo" => [{ "version" => 1, "addr" => "127.0.0.1" }], "private" => [{ "version" => 4, "addr" => "127.0.0.2" }], "public" => [{ "version" => 4, "addr" => "127.0.0.3" }] })
|
281
|
-
@instance.config[:bootstrap_network] = "foo"
|
282
|
-
@instance.before_bootstrap
|
283
|
-
expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
|
284
|
-
end
|
285
|
-
|
286
|
-
it "configures the bootstrap to use the server password" do
|
287
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
288
|
-
Chef::Config[:knife].delete(:ssh_password)
|
289
|
-
server_password = "adFRjk1089"
|
290
|
-
allow(@instance.server).to receive(:password).and_return(server_password)
|
291
|
-
@instance.before_bootstrap
|
292
|
-
expect(@instance.config[:ssh_password]).to be == server_password
|
293
|
-
end
|
294
|
-
|
295
|
-
it "configures the bootstrap to use the config ssh password" do
|
296
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
297
|
-
server_password = "config_ssh_password"
|
298
|
-
Chef::Config[:knife][:ssh_password] = server_password
|
299
|
-
expect(@instance.server).to_not receive(:password)
|
300
|
-
@instance.before_bootstrap
|
301
|
-
expect(@instance.config[:ssh_password]).to be == server_password
|
302
|
-
end
|
303
|
-
|
304
|
-
it "configures the default private bootstrap network to use 'private'" do
|
305
|
-
allow(@instance.server).to receive(:addresses).and_return({ "private" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
306
|
-
@instance.config[:private_network] = true
|
307
|
-
@instance.before_bootstrap
|
308
|
-
expect(@instance.config[:bootstrap_network]).to be == "private"
|
309
|
-
end
|
310
|
-
|
311
|
-
it "configures the bootstrap to use alternate private network" do
|
312
|
-
allow(@instance.server).to receive(:addresses).and_return({ "secure" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
313
|
-
@instance.config[:bootstrap_network] = "secure"
|
314
|
-
@instance.config[:private_network] = true
|
315
|
-
@instance.before_bootstrap
|
316
|
-
expect(@instance.config[:bootstrap_network]).to be == "secure"
|
317
|
-
end
|
318
|
-
|
319
|
-
it "set openstack ohai hint" do
|
320
|
-
allow(@instance.server).to receive(:addresses).and_return({ "public" => [{ "version" => 4, "addr" => "127.0.0.1" }] })
|
321
|
-
@instance.before_bootstrap
|
322
|
-
expect(@instance.config[:hints]).to be == { "openstack" => {} }
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
describe "#post_connection_validations" do
|
327
|
-
before(:each) do
|
328
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
329
|
-
allow(@instance.ui).to receive(:error)
|
330
|
-
end
|
331
|
-
|
332
|
-
it "raise error on invalid image" do
|
333
|
-
allow(@instance).to receive(:is_flavor_valid?).and_return(true)
|
334
|
-
allow(@instance).to receive(:is_floating_ip_valid?).and_return(true)
|
335
|
-
expect(@instance).to receive(:is_image_valid?).and_return(false)
|
336
|
-
expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have not provided a valid image ID. Please note the options for this value are -I or --image..")
|
337
|
-
end
|
338
|
-
|
339
|
-
it "raise error on invalid flavor" do
|
340
|
-
allow(@instance).to receive(:is_image_valid?).and_return(true)
|
341
|
-
allow(@instance).to receive(:is_floating_ip_valid?).and_return(true)
|
342
|
-
expect(@instance).to receive(:is_flavor_valid?).and_return(false)
|
343
|
-
expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor..")
|
344
|
-
end
|
345
|
-
|
346
|
-
it "raise error on invalid floating IP" do
|
347
|
-
allow(@instance).to receive(:is_flavor_valid?).and_return(true)
|
348
|
-
allow(@instance).to receive(:is_image_valid?).and_return(true)
|
349
|
-
expect(@instance).to receive(:is_floating_ip_valid?).and_return(false)
|
350
|
-
expect { @instance.post_connection_validations }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError, " You have either requested an invalid floating IP address or none are available..")
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
describe "#is_floating_ip_valid?" do
|
355
|
-
before(:each) do
|
356
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
357
|
-
# Default value
|
358
|
-
Chef::Config[:knife][:openstack_floating_ip] = "-1"
|
359
|
-
@instance.service = double
|
360
|
-
end
|
361
|
-
|
362
|
-
after(:all) do
|
363
|
-
Chef::Config[:knife].delete(:openstack_floating_ip)
|
364
|
-
end
|
365
|
-
|
366
|
-
it "returns true for default" do
|
367
|
-
expect(@instance.is_floating_ip_valid?).to be true
|
368
|
-
end
|
369
|
-
|
370
|
-
it "returns false if no floating IPs" do
|
371
|
-
Chef::Config[:knife].delete(:openstack_floating_ip)
|
372
|
-
expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([])
|
373
|
-
expect(@instance.is_floating_ip_valid?).to be false
|
374
|
-
end
|
375
|
-
|
376
|
-
context "when floating ip requested without value" do
|
377
|
-
it "returns true if fixed_ip is nil" do
|
378
|
-
Chef::Config[:knife][:openstack_floating_ip] = nil
|
379
|
-
obj = Object.new
|
380
|
-
obj.define_singleton_method(:fixed_ip) { nil }
|
381
|
-
expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
|
382
|
-
expect(@instance.is_floating_ip_valid?).to be true
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
context "when floating ip requested with value" do
|
387
|
-
before { Chef::Config[:knife][:openstack_floating_ip] = "127.0.0.1" }
|
388
|
-
after { Chef::Config[:knife].delete(:openstack_floating_ip) }
|
389
|
-
|
390
|
-
it "returns true if requested floating IP is exist" do
|
391
|
-
obj = Object.new
|
392
|
-
obj.define_singleton_method(:ip) { return "127.0.0.1" }
|
393
|
-
expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
|
394
|
-
expect(@instance.is_floating_ip_valid?).to be true
|
395
|
-
end
|
396
|
-
|
397
|
-
it "returns false if requested floating IP does not exist" do
|
398
|
-
obj = Object.new
|
399
|
-
obj.define_singleton_method(:ip) { return "127.0.1.1" }
|
400
|
-
expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
|
401
|
-
expect(@instance.is_floating_ip_valid?).to be false
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
describe "#is_image_valid?" do
|
407
|
-
before(:each) do
|
408
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
409
|
-
@instance.service = double
|
410
|
-
Chef::Config[:knife][:image] = "image_id"
|
411
|
-
end
|
412
|
-
|
413
|
-
after(:each) do
|
414
|
-
Chef::Config[:knife].delete(:image)
|
415
|
-
end
|
416
|
-
|
417
|
-
it "returns false on invalid image" do
|
418
|
-
expect(@instance.service).to receive_message_chain(:get_image).and_return(nil)
|
419
|
-
expect(@instance.is_image_valid?).to be false
|
420
|
-
end
|
421
|
-
|
422
|
-
it "returns true on valid image" do
|
423
|
-
expect(@instance.service).to receive_message_chain(:get_image).and_return("image")
|
424
|
-
expect(@instance.is_image_valid?).to be true
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
describe "#is_flavor_valid?" do
|
429
|
-
before(:each) do
|
430
|
-
@instance = Chef::Knife::Cloud::OpenstackServerCreate.new
|
431
|
-
@instance.service = double
|
432
|
-
Chef::Config[:knife][:flavor] = "flavor"
|
433
|
-
end
|
434
|
-
|
435
|
-
after(:each) do
|
436
|
-
Chef::Config[:knife].delete(:flavor)
|
437
|
-
end
|
438
|
-
|
439
|
-
it "returns false on invalid flavor" do
|
440
|
-
expect(@instance.service).to receive_message_chain(:get_flavor).and_return(nil)
|
441
|
-
expect(@instance.is_flavor_valid?).to be false
|
442
|
-
end
|
443
|
-
|
444
|
-
it "returns true on valid flavor" do
|
445
|
-
expect(@instance.service).to receive_message_chain(:get_flavor).and_return("flavor")
|
446
|
-
expect(@instance.is_flavor_valid?).to be true
|
447
|
-
end
|
448
|
-
end
|
449
|
-
end
|