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