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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +21 -0
  3. data/.gitignore +5 -0
  4. data/.travis.yml +9 -7
  5. data/CHANGELOG.md +174 -92
  6. data/Gemfile +15 -3
  7. data/README.md +96 -68
  8. data/Rakefile +19 -6
  9. data/knife-openstack.gemspec +17 -15
  10. data/lib/chef/knife/cloud/openstack_server_create_options.rb +36 -35
  11. data/lib/chef/knife/cloud/openstack_service.rb +7 -6
  12. data/lib/chef/knife/cloud/openstack_service_options.rb +18 -17
  13. data/lib/chef/knife/openstack_flavor_list.rb +11 -10
  14. data/lib/chef/knife/openstack_floating_ip_allocate.rb +13 -12
  15. data/lib/chef/knife/openstack_floating_ip_associate.rb +9 -8
  16. data/lib/chef/knife/openstack_floating_ip_disassociate.rb +9 -8
  17. data/lib/chef/knife/openstack_floating_ip_list.rb +10 -9
  18. data/lib/chef/knife/openstack_floating_ip_release.rb +7 -6
  19. data/lib/chef/knife/openstack_group_list.rb +13 -12
  20. data/lib/chef/knife/openstack_helpers.rb +8 -7
  21. data/lib/chef/knife/openstack_image_list.rb +14 -13
  22. data/lib/chef/knife/openstack_network_list.rb +10 -9
  23. data/lib/chef/knife/openstack_server_create.rb +57 -56
  24. data/lib/chef/knife/openstack_server_delete.rb +7 -6
  25. data/lib/chef/knife/openstack_server_list.rb +16 -15
  26. data/lib/chef/knife/openstack_server_show.rb +17 -16
  27. data/lib/chef/knife/openstack_volume_list.rb +10 -9
  28. data/lib/knife-openstack/version.rb +3 -2
  29. data/spec/functional/flavor_list_func_spec.rb +13 -12
  30. data/spec/functional/floating_ip_list_func_spec.rb +14 -13
  31. data/spec/functional/group_list_func_spec.rb +29 -28
  32. data/spec/functional/image_list_func_spec.rb +15 -14
  33. data/spec/functional/network_list_func_spec.rb +13 -12
  34. data/spec/functional/server_create_func_spec.rb +29 -28
  35. data/spec/functional/server_delete_func_spec.rb +18 -17
  36. data/spec/functional/server_list_func_spec.rb +43 -42
  37. data/spec/functional/server_show_func_spec.rb +7 -6
  38. data/spec/functional/volume_list_func_spec.rb +12 -11
  39. data/spec/integration/cleanup.rb +6 -5
  40. data/spec/integration/openstack_spec.rb +287 -286
  41. data/spec/spec_context.rb +10 -9
  42. data/spec/spec_helper.rb +38 -37
  43. data/spec/unit/openstack_flavor_list_spec.rb +6 -5
  44. data/spec/unit/openstack_floating_ip_allocate_spec.rb +14 -13
  45. data/spec/unit/openstack_floating_ip_associate_spec.rb +11 -10
  46. data/spec/unit/openstack_floating_ip_disassociate_spec.rb +12 -11
  47. data/spec/unit/openstack_floating_ip_list_spec.rb +6 -5
  48. data/spec/unit/openstack_floating_ip_release_spec.rb +13 -12
  49. data/spec/unit/openstack_group_list_spec.rb +11 -10
  50. data/spec/unit/openstack_image_list_spec.rb +6 -5
  51. data/spec/unit/openstack_network_list_spec.rb +8 -7
  52. data/spec/unit/openstack_server_create_spec.rb +131 -130
  53. data/spec/unit/openstack_server_delete_spec.rb +8 -7
  54. data/spec/unit/openstack_server_list_spec.rb +6 -5
  55. data/spec/unit/openstack_server_show_spec.rb +10 -9
  56. data/spec/unit/openstack_service_spec.rb +26 -25
  57. data/spec/unit/openstack_volume_list_spec.rb +6 -5
  58. 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 'spec_helper'
21
- require 'chef/knife/openstack_image_list'
22
- require 'chef/knife/cloud/openstack_service'
23
- require 'support/shared_examples_for_command'
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 '#validate!', Chef::Knife::Cloud::OpenstackImageList.new
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 'spec_helper'
20
- require 'chef/knife/openstack_network_list'
21
- require 'chef/knife/cloud/openstack_service'
22
- require 'support/shared_examples_for_command'
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 '#validate!', Chef::Knife::Cloud::OpenstackNetworkList.new
30
+ include_context "#validate!", Chef::Knife::Cloud::OpenstackNetworkList.new
30
31
 
31
- context 'query_resource' do
32
- it 'returns the networks using the fog service.' do
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('../../spec_helper', __FILE__)
22
- require 'chef/knife/openstack_server_create'
23
- require 'support/shared_examples_for_servercreatecommand'
24
- require 'support/shared_examples_for_command'
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 '#create_service_instance' do
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 'return OpenstackService instance' do
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 'has custom_arguments as its option' do
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 '#validate_params!' do
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] = 'ssh'
52
- Chef::Config[:knife][:identity_file] = 'identity_file'
53
- Chef::Config[:knife][:image_os_type] = 'linux'
54
- Chef::Config[:knife][:openstack_ssh_key_id] = 'openstack_ssh_key'
55
- Chef::Config[:knife][:openstack_region] = 'test-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 'run sucessfully on all params exist' do
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 '#before_exec_command' do
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] = 'chef_node_name'
76
- Chef::Config[:knife][:image] = 'image'
77
- Chef::Config[:knife][:flavor] = 'flavor'
78
- Chef::Config[:knife][:openstack_security_groups] = 'openstack_security_groups'
79
- Chef::Config[:knife][:server_create_timeout] = 'server_create_timeout'
80
- Chef::Config[:knife][:openstack_ssh_key_id] = 'openstack_ssh_key'
81
- Chef::Config[:knife][:network_ids] = 'test_network_id'
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] = 'foo=bar'
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 'set create_options' do
96
+ it "set create_options" do
96
97
  @instance.service = double
97
- allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
98
- allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
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('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil)
114
- allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
115
- allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
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 'sets user data' do
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('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil)
125
- allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
126
- allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
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 'with multiple network_ids specified' do
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('image'))
136
- allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
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] = 'test_network_id1,test_network_id2'
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 'creates the server_def with multiple nic_ids.' do
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(test_network_id1 test_network_id2)
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 'ensures default value for metadata' do
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 '#after_exec_command' do
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] = '-1'
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({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
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 'set openstack_floating_ip on openstack_floating_ip option' do
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 = ['id' => 'test',
182
- 'fixed_ips' => ['ip_address' => '127.0.1.1']]
183
- allow(@network).to receive(:list_ports).and_return(body: { 'ports' => @ports })
184
- @floating_ips = ['id' => 'test',
185
- 'fixed_ips' => ['ip_address' => '127.0.1.1']]
186
- allow(@network).to receive(:list_floating_ips).and_return(body: { 'floatingips' => @floating_ips })
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({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
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 '127.0.0.1' }
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 'raise error on unavailability of free_floating ip' do
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({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
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 '127.0.0.1' }
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, 'Unable to assign a Floating IP from allocated IPs.')
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 '#before_bootstrap' do
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] = 'public'
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] = 'config_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 'when no-network option specified' do
231
+ context "when no-network option specified" do
231
232
  before(:each) { @instance.config[:network] = false }
232
233
 
233
- it 'set public ip as a bootstrap ip if both public and private ip available' do
234
- allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] })
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 == '127.0.0.2'
237
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
237
238
  end
238
239
 
239
- it 'set private-ip as a bootstrap ip if private ip is available' do
240
- allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
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 == '127.0.0.1'
243
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
243
244
  end
244
245
 
245
- it 'set available ip as a bootstrap ip if no public, private ip available' do
246
- allow(@instance.server).to receive(:addresses).and_return({ 1 => [{ 'version' => 4, 'addr' => '127.0.0.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 == '127.0.0.1'
249
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
249
250
  end
250
251
  end
251
252
 
252
- it 'set bootstrap_ip' do
253
- allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
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 == '127.0.0.1'
256
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
256
257
  end
257
258
 
258
- it 'set private-ip as a bootstrap-ip if private-network option set' do
259
- allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] })
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 == '127.0.0.1'
263
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
263
264
  end
264
265
 
265
- it 'raise error on nil bootstrap_ip' do
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({ 'public' => [{ 'version' => 4, 'addr' => nil }] })
269
- expect { @instance.before_bootstrap }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, 'No IP address available for bootstrapping.')
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 'set public ip as default bootstrap network is public' do
273
- allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }], 'public' => [{ 'version' => 4, 'addr' => '127.0.0.2' }] })
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 == '127.0.0.2'
276
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
276
277
  end
277
278
 
278
- it 'configures the bootstrap to use alternate network' do
279
- 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' }] })
280
- @instance.config[:bootstrap_network] = 'foo'
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 == '127.0.0.1'
283
+ expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
283
284
  end
284
285
 
285
- it 'configures the bootstrap to use the server password' do
286
- allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
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 = 'adFRjk1089'
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 'configures the bootstrap to use the config ssh password' do
295
- allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
296
- server_password = 'config_ssh_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({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
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 == 'private'
308
+ expect(@instance.config[:bootstrap_network]).to be == "private"
308
309
  end
309
310
 
310
- it 'configures the bootstrap to use alternate private network' do
311
- allow(@instance.server).to receive(:addresses).and_return({ 'secure' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
312
- @instance.config[:bootstrap_network] = 'secure'
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 == 'secure'
316
+ expect(@instance.config[:bootstrap_network]).to be == "secure"
316
317
  end
317
318
 
318
- it 'set openstack ohai hint' do
319
- allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
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 == { 'openstack' => {} }
322
+ expect(@instance.config[:hints]).to be == { "openstack" => {} }
322
323
  end
323
324
  end
324
325
 
325
- describe '#post_connection_validations' do
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 'raise error on invalid image' do
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, ' You have not provided a valid image ID. Please note the options for this value are -I or --image..')
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 'raise error on invalid flavor' do
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, ' You have not provided a valid flavor ID. Please note the options for this value are -f or --flavor..')
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 'raise error on invalid floating IP' do
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, ' You have either requested an invalid floating IP address or none are available..')
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 '#is_floating_ip_valid?' do
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] = '-1'
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 'returns true for default' do
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 'returns false if no floating IPs' do
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 'when floating ip requested without value' do
376
- it 'returns true if fixed_ip is nil' do
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 'when floating ip requested with value' do
386
- before { Chef::Config[:knife][:openstack_floating_ip] = '127.0.0.1' }
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 'returns true if requested floating IP is exist' do
390
+ it "returns true if requested floating IP is exist" do
390
391
  obj = Object.new
391
- obj.define_singleton_method(:ip) { return '127.0.0.1' }
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 'returns false if requested floating IP does not exist' do
397
+ it "returns false if requested floating IP does not exist" do
397
398
  obj = Object.new
398
- obj.define_singleton_method(:ip) { return '127.0.1.1' }
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 '#is_image_valid?' do
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] = 'image_id'
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 'returns false on invalid image' do
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 'returns true on valid image' do
422
- expect(@instance.service).to receive_message_chain(:get_image).and_return('image')
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 '#is_flavor_valid?' do
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] = '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 'returns false on invalid flavor' do
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 'returns true on valid flavor' do
444
- expect(@instance.service).to receive_message_chain(:get_flavor).and_return('flavor')
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