knife-openstack 1.3.2.pre → 1.3.2.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +1 -1
  4. data/Rakefile +7 -28
  5. data/knife-openstack.gemspec +16 -16
  6. data/lib/chef/knife/cloud/openstack_server_create_options.rb +44 -44
  7. data/lib/chef/knife/cloud/openstack_service.rb +27 -31
  8. data/lib/chef/knife/cloud/openstack_service_options.rb +25 -26
  9. data/lib/chef/knife/openstack_flavor_list.rb +9 -10
  10. data/lib/chef/knife/openstack_floating_ip_allocate.rb +4 -4
  11. data/lib/chef/knife/openstack_floating_ip_associate.rb +5 -5
  12. data/lib/chef/knife/openstack_floating_ip_disassociate.rb +4 -4
  13. data/lib/chef/knife/openstack_group_list.rb +9 -11
  14. data/lib/chef/knife/openstack_helpers.rb +14 -2
  15. data/lib/chef/knife/openstack_image_list.rb +14 -15
  16. data/lib/chef/knife/openstack_network_list.rb +8 -9
  17. data/lib/chef/knife/openstack_server_create.rb +81 -84
  18. data/lib/chef/knife/openstack_server_delete.rb +25 -26
  19. data/lib/chef/knife/openstack_server_list.rb +13 -19
  20. data/lib/chef/knife/openstack_server_show.rb +11 -12
  21. data/lib/chef/knife/openstack_volume_list.rb +10 -12
  22. data/lib/knife-openstack/version.rb +1 -1
  23. data/spec/functional/flavor_list_func_spec.rb +11 -11
  24. data/spec/functional/floating_ip_list_func_spec.rb +11 -11
  25. data/spec/functional/group_list_func_spec.rb +27 -31
  26. data/spec/functional/image_list_func_spec.rb +14 -14
  27. data/spec/functional/network_list_func_spec.rb +10 -10
  28. data/spec/functional/server_create_func_spec.rb +23 -24
  29. data/spec/functional/server_delete_func_spec.rb +16 -17
  30. data/spec/functional/server_list_func_spec.rb +39 -39
  31. data/spec/functional/server_show_func_spec.rb +4 -5
  32. data/spec/functional/volume_list_func_spec.rb +9 -9
  33. data/spec/integration/cleanup.rb +8 -11
  34. data/spec/integration/openstack_spec.rb +377 -347
  35. data/spec/spec_context.rb +10 -10
  36. data/spec/spec_helper.rb +23 -27
  37. data/spec/unit/openstack_flavor_list_spec.rb +1 -1
  38. data/spec/unit/openstack_floating_ip_allocate_spec.rb +2 -3
  39. data/spec/unit/openstack_floating_ip_associate_spec.rb +2 -2
  40. data/spec/unit/openstack_floating_ip_disassociate_spec.rb +3 -3
  41. data/spec/unit/openstack_floating_ip_release_spec.rb +1 -1
  42. data/spec/unit/openstack_group_list_spec.rb +7 -7
  43. data/spec/unit/openstack_image_list_spec.rb +2 -2
  44. data/spec/unit/openstack_network_list_spec.rb +4 -4
  45. data/spec/unit/openstack_server_create_spec.rb +117 -118
  46. data/spec/unit/openstack_server_delete_spec.rb +4 -4
  47. data/spec/unit/openstack_server_list_spec.rb +2 -2
  48. data/spec/unit/openstack_server_show_spec.rb +6 -6
  49. data/spec/unit/openstack_service_spec.rb +20 -20
  50. data/spec/unit/openstack_volume_list_spec.rb +1 -1
  51. metadata +30 -2
@@ -15,12 +15,12 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- shared_context "#validate!" do |instance|
18
+ shared_context '#validate!' do |instance|
19
19
  before(:each) do
20
- Chef::Config[:knife][:openstack_username] = "testuser"
21
- Chef::Config[:knife][:openstack_password] = "testpassword"
22
- Chef::Config[:knife][:openstack_auth_url] = "tsturl"
23
- Chef::Config[:knife][:openstack_region] = "test-region"
20
+ Chef::Config[:knife][:openstack_username] = 'testuser'
21
+ Chef::Config[:knife][:openstack_password] = 'testpassword'
22
+ Chef::Config[:knife][:openstack_auth_url] = 'tsturl'
23
+ Chef::Config[:knife][:openstack_region] = 'test-region'
24
24
  allow(instance).to receive(:exit)
25
25
  end
26
26
 
@@ -31,23 +31,23 @@ shared_context "#validate!" do |instance|
31
31
  Chef::Config[:knife].delete(:openstack_region)
32
32
  end
33
33
 
34
- it "validate openstack mandatory options" do
35
- expect {instance.validate!}.to_not raise_error
34
+ it 'validate openstack mandatory options' do
35
+ expect { instance.validate! }.to_not raise_error
36
36
  end
37
37
 
38
- it "raise error on openstack_username missing" do
38
+ it 'raise error on openstack_username missing' do
39
39
  Chef::Config[:knife].delete(:openstack_username)
40
40
  expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Username' value.")
41
41
  expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
42
42
  end
43
43
 
44
- it "raise error on openstack_password missing" do
44
+ it 'raise error on openstack_password missing' do
45
45
  Chef::Config[:knife].delete(:openstack_password)
46
46
  expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Password' value.")
47
47
  expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
48
48
  end
49
49
 
50
- it "raise error on openstack_auth_url missing" do
50
+ it 'raise error on openstack_auth_url missing' do
51
51
  Chef::Config[:knife].delete(:openstack_auth_url)
52
52
  expect(instance.ui).to receive(:error).with("You did not provide a valid 'Openstack Auth Url' value.")
53
53
  expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
@@ -15,8 +15,7 @@
15
15
 
16
16
  # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>)
17
17
 
18
-
19
- $:.unshift File.expand_path('../../lib', __FILE__)
18
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
20
19
  require 'chef/knife/bootstrap'
21
20
  require 'chef/knife/openstack_helpers'
22
21
  require 'fog'
@@ -25,7 +24,7 @@ require 'chef/knife/bootstrap_windows_winrm'
25
24
  require 'chef/knife/openstack_server_create'
26
25
  require 'chef/knife/openstack_server_delete'
27
26
  require 'chef/knife/bootstrap_windows_ssh'
28
- require "securerandom"
27
+ require 'securerandom'
29
28
  require 'knife-openstack/version'
30
29
  require 'test/knife-utils/test_bed'
31
30
  require 'resource_spec_helper'
@@ -35,14 +34,12 @@ require 'spec_context'
35
34
 
36
35
  def find_instance_id(instance_name, file)
37
36
  file.lines.each do |line|
38
- if line.include?("#{instance_name}")
39
- return "#{line}".split(" ")[2].strip
40
- end
37
+ return "#{line}".split(' ')[2].strip if line.include?("#{instance_name}")
41
38
  end
42
39
  end
43
40
 
44
41
  def is_config_present
45
- if ! ENV['RUN_INTEGRATION_TESTS']
42
+ unless ENV['RUN_INTEGRATION_TESTS']
46
43
  puts("\nPlease set RUN_INTEGRATION_TESTS environment variable to run integration tests")
47
44
  return false
48
45
  end
@@ -50,17 +47,17 @@ def is_config_present
50
47
  unset_env_var = []
51
48
  unset_config_options = []
52
49
  is_config = true
53
- config_file_exist = File.exist?(File.expand_path("../integration/config/environment.yml", __FILE__))
54
- openstack_config = YAML.load(File.read(File.expand_path("../integration/config/environment.yml", __FILE__))) if config_file_exist
50
+ config_file_exist = File.exist?(File.expand_path('../integration/config/environment.yml', __FILE__))
51
+ openstack_config = YAML.load(File.read(File.expand_path('../integration/config/environment.yml', __FILE__))) if config_file_exist
55
52
  %w(OPENSTACK_USERNAME OPENSTACK_PASSWORD OPENSTACK_AUTH_URL OPENSTACK_TENANT).each do |os_env_var|
56
- if ENV[os_env_var].nil?
57
- unset_env_var << os_env_var
58
- is_config = false
59
- end
53
+ if ENV[os_env_var].nil?
54
+ unset_env_var << os_env_var
55
+ is_config = false
60
56
  end
57
+ end
61
58
 
62
59
  err_msg = "\nPlease set #{unset_env_var.join(', ')} environment"
63
- err_msg = err_msg + ( unset_env_var.length > 1 ? " variables " : " variable " ) + "for integration tests."
60
+ err_msg = err_msg + (unset_env_var.length > 1 ? ' variables ' : ' variable ') + 'for integration tests.'
64
61
  puts err_msg unless unset_env_var.empty?
65
62
 
66
63
  %w(OS_SSH_USER OPENSTACK_PRI_KEY OPENSTACK_KEY_PAIR OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE).each do |os_config_opt|
@@ -72,38 +69,37 @@ def is_config_present
72
69
  end
73
70
 
74
71
  config_err_msg = "\nPlease set #{unset_config_options.join(', ')} config"
75
- config_err_msg = config_err_msg + ( unset_config_options.length > 1 ? " options in ../spec/integration/config/environment.yml or as environment variables" : " option in ../spec/integration/config/environment.yml or as environment variable" ) + " for integration tests."
72
+ config_err_msg = config_err_msg + (unset_config_options.length > 1 ? ' options in ../spec/integration/config/environment.yml or as environment variables' : ' option in ../spec/integration/config/environment.yml or as environment variable') + ' for integration tests.'
76
73
  puts config_err_msg unless unset_config_options.empty?
77
74
 
78
75
  is_config
79
76
  end
80
77
 
81
78
  def get_gem_file_name
82
- "knife-openstack-" + Knife::OpenStack::VERSION + ".gem"
79
+ 'knife-openstack-' + Knife::OpenStack::VERSION + '.gem'
83
80
  end
84
81
 
85
82
  def delete_instance_cmd(stdout)
86
- "knife openstack server delete " + find_instance_id("Instance ID", stdout) +
87
- append_openstack_creds(is_list_cmd = true) + " --yes"
83
+ 'knife openstack server delete ' + find_instance_id('Instance ID', stdout) +
84
+ append_openstack_creds(is_list_cmd = true) + ' --yes'
88
85
  end
89
86
 
90
87
  def create_node_name(name)
91
- @name_node = (name == "linux") ? "os-integration-test-linux-#{SecureRandom.hex(4)}" : "os-integration-test-win-#{SecureRandom.hex(4)}"
88
+ @name_node = (name == 'linux') ? "os-integration-test-linux-#{SecureRandom.hex(4)}" : "os-integration-test-win-#{SecureRandom.hex(4)}"
92
89
  end
93
90
 
94
-
95
91
  def init_openstack_test
96
92
  init_test
97
93
 
98
94
  begin
99
- data_to_write = File.read(File.expand_path("../integration/config/incorrect_openstack.pem", __FILE__))
100
- File.open("#{temp_dir}/incorrect_openstack.pem", 'w') {|f| f.write(data_to_write)}
95
+ data_to_write = File.read(File.expand_path('../integration/config/incorrect_openstack.pem', __FILE__))
96
+ File.open("#{temp_dir}/incorrect_openstack.pem", 'w') { |f| f.write(data_to_write) }
101
97
  rescue
102
- puts "Error while creating file - incorrect_openstack.pem"
98
+ puts 'Error while creating file - incorrect_openstack.pem'
103
99
  end
104
100
 
105
- config_file_exist = File.exist?(File.expand_path("../integration/config/environment.yml", __FILE__))
106
- openstack_config = YAML.load(File.read(File.expand_path("../integration/config/environment.yml", __FILE__))) if config_file_exist
101
+ config_file_exist = File.exist?(File.expand_path('../integration/config/environment.yml', __FILE__))
102
+ openstack_config = YAML.load(File.read(File.expand_path('../integration/config/environment.yml', __FILE__))) if config_file_exist
107
103
 
108
104
  %w(OS_SSH_USER OPENSTACK_KEY_PAIR OPENSTACK_PRI_KEY OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE).each do |os_config_opt|
109
105
  instance_variable_set("@#{os_config_opt.downcase}", (openstack_config[os_config_opt] if openstack_config) || ENV[os_config_opt])
@@ -112,9 +108,9 @@ def init_openstack_test
112
108
  key_file_path = @openstack_pri_key
113
109
  key_file_exist = File.exist?(File.expand_path(key_file_path, __FILE__))
114
110
  data_to_write = File.read(File.expand_path(key_file_path, __FILE__)) if key_file_exist
115
- File.open("#{temp_dir}/openstack.pem", 'w') {|f| f.write(data_to_write)}
111
+ File.open("#{temp_dir}/openstack.pem", 'w') { |f| f.write(data_to_write) }
116
112
  rescue
117
- puts "Error while creating file - openstack.pem"
113
+ puts 'Error while creating file - openstack.pem'
118
114
  end
119
115
  end
120
116
 
@@ -25,5 +25,5 @@ require 'support/shared_examples_for_command'
25
25
  describe Chef::Knife::Cloud::OpenstackFlavorList do
26
26
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFlavorList.new
27
27
 
28
- include_context "#validate!", Chef::Knife::Cloud::OpenstackFlavorList.new
28
+ include_context '#validate!', Chef::Knife::Cloud::OpenstackFlavorList.new
29
29
  end
@@ -21,7 +21,6 @@ require 'chef/knife/cloud/openstack_service'
21
21
  require 'support/shared_examples_for_command'
22
22
 
23
23
  describe Chef::Knife::Cloud::OpenstackFloatingIpAllocate do
24
-
25
24
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new
26
25
  include_context '#validate!', Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new
27
26
 
@@ -46,9 +45,9 @@ describe Chef::Knife::Cloud::OpenstackFloatingIpAllocate do
46
45
 
47
46
  describe 'when user provides pool option ' do
48
47
  it 'allocates floating ip in user specified pool' do
49
- @instance = Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new(["--pool", "test-pool"])
48
+ @instance = Chef::Knife::Cloud::OpenstackFloatingIpAllocate.new(['--pool', 'test-pool'])
50
49
  @instance.service = Chef::Knife::Cloud::Service.new
51
- response = {:floating_ip => {'id' => 'test-id', 'instance_id' => 'test-instance-id', 'floating_ip' => '127.0.0.1', 'fixed_ip' => 'nil', 'pool' => 'test-pool' }}
50
+ response = { floating_ip: { 'id' => 'test-id', 'instance_id' => 'test-instance-id', 'floating_ip' => '127.0.0.1', 'fixed_ip' => 'nil', 'pool' => 'test-pool' } }
52
51
  expect(@instance.service).to receive(:allocate_address).and_return(response)
53
52
  @instance.execute_command
54
53
  end
@@ -22,8 +22,8 @@ require 'ostruct'
22
22
 
23
23
  describe Chef::Knife::Cloud::OpenstackFloatingIpAssociate do
24
24
  before(:each) do
25
- @instance = Chef::Knife::Cloud::OpenstackFloatingIpAssociate.new(["--instance-id", "23849038438240934n3294839248"])
26
- @instance.name_args = [ '127.0.0.1' ]
25
+ @instance = Chef::Knife::Cloud::OpenstackFloatingIpAssociate.new(['--instance-id', '23849038438240934n3294839248'])
26
+ @instance.name_args = ['127.0.0.1']
27
27
  end
28
28
 
29
29
  describe 'associate floating ip' do
@@ -22,14 +22,14 @@ require 'ostruct'
22
22
 
23
23
  describe Chef::Knife::Cloud::OpenstackFloatingIpDisassociate do
24
24
  before(:each) do
25
- @instance = Chef::Knife::Cloud::OpenstackFloatingIpDisassociate.new(["--instance-id", "23849038438240934n3294839248"])
26
- @instance.name_args = [ '127.0.0.1' ]
25
+ @instance = Chef::Knife::Cloud::OpenstackFloatingIpDisassociate.new(['--instance-id', '23849038438240934n3294839248'])
26
+ @instance.name_args = ['127.0.0.1']
27
27
  end
28
28
 
29
29
  describe 'associate floating ip' do
30
30
  it 'calls associate address' do
31
31
  @instance.service = Chef::Knife::Cloud::Service.new
32
- response = OpenStruct.new(:status => 202)
32
+ response = OpenStruct.new(status: 202)
33
33
  expect(@instance.service).to receive(:disassociate_address).with('23849038438240934n3294839248', '127.0.0.1').and_return(response)
34
34
  expect(@instance.ui).to receive(:info).and_return('Floating IP 127.0.0.1 disassociated with Instance 23849038438240934n3294839248')
35
35
  @instance.execute_command
@@ -26,7 +26,7 @@ describe Chef::Knife::Cloud::OpenstackFloatingIpRelease do
26
26
  before(:each) do
27
27
  @instance = Chef::Knife::Cloud::OpenstackFloatingIpRelease.new
28
28
  allow(@instance.ui).to receive(:error)
29
- @instance.name_args = [ '23849038438240934n3294839248' ]
29
+ @instance.name_args = ['23849038438240934n3294839248']
30
30
  end
31
31
 
32
32
  describe 'create service instance' do
@@ -25,18 +25,18 @@ require 'support/shared_examples_for_command'
25
25
  describe Chef::Knife::Cloud::OpenstackGroupList do
26
26
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackGroupList.new
27
27
 
28
- include_context "#validate!", Chef::Knife::Cloud::OpenstackGroupList.new
28
+ include_context '#validate!', Chef::Knife::Cloud::OpenstackGroupList.new
29
29
 
30
- let (:instance) {Chef::Knife::Cloud::OpenstackGroupList.new}
30
+ let (:instance) { Chef::Knife::Cloud::OpenstackGroupList.new }
31
31
 
32
- context "#list" do
32
+ context '#list' do
33
33
  before(:each) do
34
- @security_groups = [TestResource.new({ "name" => "Unrestricted","description" => "testdescription", "security_group_rules" => [TestResource.new({"from_port"=>636, "group"=>{}, "ip_protocol"=>"tcp", "to_port"=>636, "parent_group_id"=>14, "ip_range"=>{"cidr"=>"0.0.0.0/0"}, "id"=>183})]})]
35
- instance.config[:format] = "summary"
34
+ @security_groups = [TestResource.new('name' => 'Unrestricted', 'description' => 'testdescription', 'security_group_rules' => [TestResource.new('from_port' => 636, 'group' => {}, 'ip_protocol' => 'tcp', 'to_port' => 636, 'parent_group_id' => 14, 'ip_range' => { 'cidr' => '0.0.0.0/0' }, 'id' => 183)])]
35
+ instance.config[:format] = 'summary'
36
36
  end
37
37
 
38
- it "returns group list" do
39
- expect(instance.ui).to receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description", "Unrestricted", "tcp", "636", "636", "0.0.0.0/0", "testdescription"],:uneven_columns_across, 6)
38
+ it 'returns group list' do
39
+ expect(instance.ui).to receive(:list).with(['Name', 'Protocol', 'From', 'To', 'CIDR', 'Description', 'Unrestricted', 'tcp', '636', '636', '0.0.0.0/0', 'testdescription'], :uneven_columns_across, 6)
40
40
  instance.list(@security_groups)
41
41
  end
42
42
  end
@@ -25,7 +25,7 @@ require 'support/shared_examples_for_command'
25
25
  describe Chef::Knife::Cloud::OpenstackImageList do
26
26
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackImageList.new
27
27
 
28
- let (:instance) {Chef::Knife::Cloud::OpenstackImageList.new}
28
+ let (:instance) { Chef::Knife::Cloud::OpenstackImageList.new }
29
29
 
30
- include_context "#validate!", Chef::Knife::Cloud::OpenstackImageList.new
30
+ include_context '#validate!', Chef::Knife::Cloud::OpenstackImageList.new
31
31
  end
@@ -24,12 +24,12 @@ require 'support/shared_examples_for_command'
24
24
  describe Chef::Knife::Cloud::OpenstackNetworkList do
25
25
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new
26
26
 
27
- let (:instance) {Chef::Knife::Cloud::OpenstackNetworkList.new}
27
+ let (:instance) { Chef::Knife::Cloud::OpenstackNetworkList.new }
28
28
 
29
- include_context "#validate!", Chef::Knife::Cloud::OpenstackNetworkList.new
29
+ include_context '#validate!', Chef::Knife::Cloud::OpenstackNetworkList.new
30
30
 
31
- context "query_resource" do
32
- it "returns the networks using the fog service." do
31
+ context 'query_resource' do
32
+ it 'returns the networks using the fog service.' do
33
33
  instance.service = double
34
34
  expect(instance.service).to receive(:list_networks)
35
35
  instance.query_resource
@@ -18,7 +18,6 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
 
21
-
22
21
  require File.expand_path('../../spec_helper', __FILE__)
23
22
  require 'chef/knife/openstack_server_create'
24
23
  require 'support/shared_examples_for_servercreatecommand'
@@ -26,34 +25,34 @@ require 'support/shared_examples_for_command'
26
25
 
27
26
  describe Chef::Knife::Cloud::OpenstackServerCreate do
28
27
  create_instance = Chef::Knife::Cloud::OpenstackServerCreate.new
29
- create_instance.define_singleton_method(:post_connection_validations){}
28
+ create_instance.define_singleton_method(:post_connection_validations) {}
30
29
 
31
30
  it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerCreate.new
32
31
  it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, create_instance
33
32
 
34
- describe "#create_service_instance" do
33
+ describe '#create_service_instance' do
35
34
  before(:each) do
36
35
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
37
36
  end
38
37
 
39
- it "return OpenstackService instance" do
38
+ it 'return OpenstackService instance' do
40
39
  expect(@instance.create_service_instance).to be_an_instance_of(Chef::Knife::Cloud::OpenstackService)
41
40
  end
42
41
 
43
- it "has custom_arguments as its option" do
42
+ it 'has custom_arguments as its option' do
44
43
  expect(@instance.options.include? :custom_attributes).to be true
45
- end
44
+ end
46
45
  end
47
46
 
48
- describe "#validate_params!" do
47
+ describe '#validate_params!' do
49
48
  before(:each) do
50
49
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
51
50
  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"
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'
57
56
  end
58
57
 
59
58
  after(:all) do
@@ -64,24 +63,24 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
64
63
  Chef::Config[:knife].delete(:openstack_region)
65
64
  end
66
65
 
67
- it "run sucessfully on all params exist" do
66
+ it 'run sucessfully on all params exist' do
68
67
  expect { @instance.validate_params! }.to_not raise_error
69
68
  end
70
69
  end
71
70
 
72
- describe "#before_exec_command" do
71
+ describe '#before_exec_command' do
73
72
  before(:each) do
74
73
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
75
74
  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"
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'
83
82
  allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids])
84
- Chef::Config[:knife][:metadata] = "foo=bar"
83
+ Chef::Config[:knife][:metadata] = 'foo=bar'
85
84
  end
86
85
 
87
86
  after(:all) do
@@ -93,7 +92,7 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
93
92
  Chef::Config[:knife].delete(:metadata)
94
93
  end
95
94
 
96
- it "set create_options" do
95
+ it 'set create_options' do
97
96
  @instance.service = double
98
97
  allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
99
98
  allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
@@ -111,7 +110,7 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
111
110
  end
112
111
 
113
112
  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)
113
+ @instance.service = double('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil)
115
114
  allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
116
115
  allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
117
116
  expect(@instance).to receive(:post_connection_validations)
@@ -119,10 +118,10 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
119
118
  expect(@instance.create_options[:server_def]).to_not include(:user_data)
120
119
  end
121
120
 
122
- it "sets user data" do
121
+ it 'sets user data' do
123
122
  user_data = "echo 'hello world' >> /tmp/user_data.txt"
124
123
  Chef::Config[:knife][:user_data] = user_data
125
- @instance.service = double("Chef::Knife::Cloud::OpenstackService", :create_server_dependencies => nil)
124
+ @instance.service = double('Chef::Knife::Cloud::OpenstackService', create_server_dependencies: nil)
126
125
  allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
127
126
  allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
128
127
  expect(@instance).to receive(:post_connection_validations)
@@ -130,30 +129,30 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
130
129
  expect(@instance.create_options[:server_def][:user_data]).to be == user_data
131
130
  end
132
131
 
133
- context "with multiple network_ids specified" do
132
+ context 'with multiple network_ids specified' do
134
133
  before(:each) do
135
134
  @instance.service = double
136
135
  allow(@instance.service).to receive(:get_image).and_return(get_mock_resource('image'))
137
136
  allow(@instance.service).to receive(:get_flavor).and_return(get_mock_resource('flavor'))
138
137
  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(","))
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(','))
141
140
  expect(@instance).to receive(:post_connection_validations)
142
141
  end
143
142
 
144
- it "creates the server_def with multiple nic_ids." do
143
+ it 'creates the server_def with multiple nic_ids.' do
145
144
  @instance.before_exec_command
146
- expect(@instance.create_options[:server_def][:nics]).to be == ["test_network_id1", "test_network_id2"]
145
+ expect(@instance.create_options[:server_def][:nics]).to be == %w(test_network_id1 test_network_id2)
147
146
  end
148
147
  end
149
148
 
150
- it "ensures default value for metadata" do
149
+ it 'ensures default value for metadata' do
151
150
  options = @instance.options
152
- expect(options[:metadata][:default]).to be == nil
151
+ expect(options[:metadata][:default]).to be.nil?
153
152
  end
154
153
  end
155
154
 
156
- describe "#after_exec_command" do
155
+ describe '#after_exec_command' do
157
156
  before(:each) do
158
157
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
159
158
  allow(@instance).to receive(:msg_pair)
@@ -164,16 +163,16 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
164
163
  end
165
164
 
166
165
  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"
166
+ # default openstack_floating_ip is '-1'
167
+ Chef::Config[:knife][:openstack_floating_ip] = '-1'
169
168
  @instance.service = Chef::Knife::Cloud::Service.new
170
169
  @instance.server = double
171
- allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
170
+ allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
172
171
  expect(@instance).to receive(:bootstrap)
173
172
  @instance.after_exec_command
174
173
  end
175
174
 
176
- it "set openstack_floating_ip on openstack_floating_ip option" do
175
+ it 'set openstack_floating_ip on openstack_floating_ip option' do
177
176
  Chef::Config[:knife][:openstack_floating_ip] = nil
178
177
  @instance.service = Chef::Knife::Cloud::Service.new
179
178
  @instance.server = double
@@ -181,120 +180,120 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
181
180
  @network = double
182
181
  @ports = ['id' => 'test',
183
182
  'fixed_ips' => ['ip_address' => '127.0.1.1']]
184
- allow(@network).to receive(:list_ports).and_return(body: {'ports' => @ports})
183
+ allow(@network).to receive(:list_ports).and_return(body: { 'ports' => @ports })
185
184
  @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})
185
+ 'fixed_ips' => ['ip_address' => '127.0.1.1']]
186
+ allow(@network).to receive(:list_floating_ips).and_return(body: { 'floatingips' => @floating_ips })
188
187
  allow(@network).to receive(:associate_floating_ip)
189
188
  allow(@instance.service).to receive(:network).and_return(@network)
190
189
 
191
- allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
190
+ allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
192
191
  expect(@instance).to receive(:bootstrap)
193
192
  allow(@instance.service).to receive(:connection).and_return(double)
194
193
  free_floating = Object.new
195
194
  free_floating.define_singleton_method(:fixed_ip) { return nil }
196
- free_floating.define_singleton_method(:ip) { return "127.0.0.1" }
195
+ free_floating.define_singleton_method(:ip) { return '127.0.0.1' }
197
196
  expect(@instance.service.connection).to receive(:addresses).and_return([free_floating])
198
197
  @instance.after_exec_command
199
198
  end
200
199
 
201
- it "raise error on unavailability of free_floating ip" do
200
+ it 'raise error on unavailability of free_floating ip' do
202
201
  Chef::Config[:knife][:openstack_floating_ip] = nil
203
202
  @instance.service = Chef::Knife::Cloud::Service.new
204
203
  allow(@instance.ui).to receive(:fatal)
205
204
  @instance.server = double
206
- allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
205
+ allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.1.1' }] })
207
206
  expect(@instance).to_not receive(:bootstrap)
208
207
  allow(@instance.service).to receive(:connection).and_return(double)
209
208
  free_floating = Object.new
210
- free_floating.define_singleton_method(:fixed_ip) { return "127.0.0.1" }
209
+ free_floating.define_singleton_method(:fixed_ip) { return '127.0.0.1' }
211
210
  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.")
211
+ expect { @instance.after_exec_command }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerSetupError, 'Unable to assign a Floating IP from allocated IPs.')
213
212
  end
214
213
  end
215
214
 
216
- describe "#before_bootstrap" do
215
+ describe '#before_bootstrap' do
217
216
  before(:each) do
218
217
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
219
218
  @instance.server = double
220
219
  # default bootstrap_network is public
221
- @instance.config[:bootstrap_network] = "public"
220
+ @instance.config[:bootstrap_network] = 'public'
222
221
  # default no network is true
223
222
  @instance.config[:network] = true
224
- Chef::Config[:knife][:ssh_password] = "config_ssh_password"
223
+ Chef::Config[:knife][:ssh_password] = 'config_ssh_password'
225
224
  end
226
225
 
227
226
  after(:each) do
228
227
  Chef::Config[:knife].delete(:ssh_password)
229
228
  end
230
229
 
231
- context "when no-network option specified" do
230
+ context 'when no-network option specified' do
232
231
  before(:each) { @instance.config[:network] = false }
233
232
 
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"}]})
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' }] })
236
235
  @instance.before_bootstrap
237
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
236
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.2'
238
237
  end
239
238
 
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"}]})
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' }] })
242
241
  @instance.before_bootstrap
243
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
242
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1'
244
243
  end
245
244
 
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"}]})
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' }] })
248
247
  @instance.before_bootstrap
249
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
248
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1'
250
249
  end
251
250
  end
252
251
 
253
- it "set bootstrap_ip" do
254
- allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.0.1"}]})
252
+ it 'set bootstrap_ip' do
253
+ allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
255
254
  @instance.before_bootstrap
256
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
255
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1'
257
256
  end
258
257
 
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"}]})
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' }] })
261
260
  @instance.config[:private_network] = true
262
261
  @instance.before_bootstrap
263
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
262
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1'
264
263
  end
265
264
 
266
- it "raise error on nil bootstrap_ip" do
265
+ it 'raise error on nil bootstrap_ip' do
267
266
  allow(@instance.ui).to receive(:error)
268
267
 
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.")
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.')
271
270
  end
272
271
 
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"}]})
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' }] })
275
274
  @instance.before_bootstrap
276
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.2"
275
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.2'
277
276
  end
278
277
 
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"}]})
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' }] })
281
280
  @instance.config[:bootstrap_network] = 'foo'
282
281
  @instance.before_bootstrap
283
- expect(@instance.config[:bootstrap_ip_address]).to be == "127.0.0.1"
282
+ expect(@instance.config[:bootstrap_ip_address]).to be == '127.0.0.1'
284
283
  end
285
284
 
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"}]})
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' }] })
288
287
  Chef::Config[:knife].delete(:ssh_password)
289
- server_password = "adFRjk1089"
288
+ server_password = 'adFRjk1089'
290
289
  allow(@instance.server).to receive(:password).and_return(server_password)
291
290
  @instance.before_bootstrap
292
291
  expect(@instance.config[:ssh_password]).to be == server_password
293
292
  end
294
293
 
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"
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'
298
297
  Chef::Config[:knife][:ssh_password] = server_password
299
298
  expect(@instance.server).to_not receive(:password)
300
299
  @instance.before_bootstrap
@@ -302,60 +301,60 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
302
301
  end
303
302
 
304
303
  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"}]})
304
+ allow(@instance.server).to receive(:addresses).and_return({ 'private' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
306
305
  @instance.config[:private_network] = true
307
306
  @instance.before_bootstrap
308
307
  expect(@instance.config[:bootstrap_network]).to be == 'private'
309
308
  end
310
309
 
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"}]})
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' }] })
313
312
  @instance.config[:bootstrap_network] = 'secure'
314
313
  @instance.config[:private_network] = true
315
314
  @instance.before_bootstrap
316
315
  expect(@instance.config[:bootstrap_network]).to be == 'secure'
317
316
  end
318
317
 
319
- it "set openstack ohai hint" do
320
- allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.0.1"}]})
318
+ it 'set openstack ohai hint' do
319
+ allow(@instance.server).to receive(:addresses).and_return({ 'public' => [{ 'version' => 4, 'addr' => '127.0.0.1' }] })
321
320
  @instance.before_bootstrap
322
- expect(@instance.config[:hints]).to be == {'openstack' => {}}
321
+ expect(@instance.config[:hints]).to be == { 'openstack' => {} }
323
322
  end
324
323
  end
325
324
 
326
- describe "#post_connection_validations" do
325
+ describe '#post_connection_validations' do
327
326
  before(:each) do
328
327
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
329
328
  allow(@instance.ui).to receive(:error)
330
329
  end
331
330
 
332
- it "raise error on invalid image" do
331
+ it 'raise error on invalid image' do
333
332
  allow(@instance).to receive(:is_flavor_valid?).and_return(true)
334
333
  allow(@instance).to receive(:is_floating_ip_valid?).and_return(true)
335
334
  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..")
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..')
337
336
  end
338
337
 
339
- it "raise error on invalid flavor" do
338
+ it 'raise error on invalid flavor' do
340
339
  allow(@instance).to receive(:is_image_valid?).and_return(true)
341
340
  allow(@instance).to receive(:is_floating_ip_valid?).and_return(true)
342
341
  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..")
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..')
344
343
  end
345
344
 
346
- it "raise error on invalid floating IP" do
345
+ it 'raise error on invalid floating IP' do
347
346
  allow(@instance).to receive(:is_flavor_valid?).and_return(true)
348
347
  allow(@instance).to receive(:is_image_valid?).and_return(true)
349
348
  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..")
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..')
351
350
  end
352
351
  end
353
352
 
354
- describe "#is_floating_ip_valid?" do
353
+ describe '#is_floating_ip_valid?' do
355
354
  before(:each) do
356
355
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
357
356
  # Default value
358
- Chef::Config[:knife][:openstack_floating_ip] = "-1"
357
+ Chef::Config[:knife][:openstack_floating_ip] = '-1'
359
358
  @instance.service = double
360
359
  end
361
360
 
@@ -363,86 +362,86 @@ describe Chef::Knife::Cloud::OpenstackServerCreate do
363
362
  Chef::Config[:knife].delete(:openstack_floating_ip)
364
363
  end
365
364
 
366
- it "returns true for default" do
365
+ it 'returns true for default' do
367
366
  expect(@instance.is_floating_ip_valid?).to be true
368
367
  end
369
368
 
370
- it "returns false if no floating IPs" do
369
+ it 'returns false if no floating IPs' do
371
370
  Chef::Config[:knife].delete(:openstack_floating_ip)
372
371
  expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([])
373
372
  expect(@instance.is_floating_ip_valid?).to be false
374
373
  end
375
374
 
376
- context "when floating ip requested without value" do
377
- it "returns true if fixed_ip is nil" do
375
+ context 'when floating ip requested without value' do
376
+ it 'returns true if fixed_ip is nil' do
378
377
  Chef::Config[:knife][:openstack_floating_ip] = nil
379
378
  obj = Object.new
380
- obj.define_singleton_method(:fixed_ip){nil}
379
+ obj.define_singleton_method(:fixed_ip) { nil }
381
380
  expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
382
381
  expect(@instance.is_floating_ip_valid?).to be true
383
382
  end
384
383
  end
385
384
 
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)}
385
+ context 'when floating ip requested with value' do
386
+ before { Chef::Config[:knife][:openstack_floating_ip] = '127.0.0.1' }
387
+ after { Chef::Config[:knife].delete(:openstack_floating_ip) }
389
388
 
390
- it "returns true if requested floating IP is exist" do
389
+ it 'returns true if requested floating IP is exist' do
391
390
  obj = Object.new
392
- obj.define_singleton_method(:ip){return "127.0.0.1"}
391
+ obj.define_singleton_method(:ip) { return '127.0.0.1' }
393
392
  expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
394
393
  expect(@instance.is_floating_ip_valid?).to be true
395
394
  end
396
395
 
397
- it "returns false if requested floating IP does not exist" do
396
+ it 'returns false if requested floating IP does not exist' do
398
397
  obj = Object.new
399
- obj.define_singleton_method(:ip){return "127.0.1.1"}
398
+ obj.define_singleton_method(:ip) { return '127.0.1.1' }
400
399
  expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([obj])
401
400
  expect(@instance.is_floating_ip_valid?).to be false
402
401
  end
403
402
  end
404
403
  end
405
404
 
406
- describe "#is_image_valid?" do
405
+ describe '#is_image_valid?' do
407
406
  before(:each) do
408
407
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
409
408
  @instance.service = double
410
- Chef::Config[:knife][:image] = "image_id"
409
+ Chef::Config[:knife][:image] = 'image_id'
411
410
  end
412
411
 
413
412
  after(:each) do
414
413
  Chef::Config[:knife].delete(:image)
415
414
  end
416
415
 
417
- it "returns false on invalid image" do
416
+ it 'returns false on invalid image' do
418
417
  expect(@instance.service).to receive_message_chain(:get_image).and_return(nil)
419
418
  expect(@instance.is_image_valid?).to be false
420
419
  end
421
420
 
422
- it "returns true on valid image" do
423
- expect(@instance.service).to receive_message_chain(:get_image).and_return("image")
421
+ it 'returns true on valid image' do
422
+ expect(@instance.service).to receive_message_chain(:get_image).and_return('image')
424
423
  expect(@instance.is_image_valid?).to be true
425
424
  end
426
425
  end
427
426
 
428
- describe "#is_flavor_valid?" do
427
+ describe '#is_flavor_valid?' do
429
428
  before(:each) do
430
429
  @instance = Chef::Knife::Cloud::OpenstackServerCreate.new
431
430
  @instance.service = double
432
- Chef::Config[:knife][:flavor] = "flavor"
431
+ Chef::Config[:knife][:flavor] = 'flavor'
433
432
  end
434
433
 
435
434
  after(:each) do
436
435
  Chef::Config[:knife].delete(:flavor)
437
436
  end
438
437
 
439
- it "returns false on invalid flavor" do
438
+ it 'returns false on invalid flavor' do
440
439
  expect(@instance.service).to receive_message_chain(:get_flavor).and_return(nil)
441
440
  expect(@instance.is_flavor_valid?).to be false
442
441
  end
443
442
 
444
- it "returns true on valid flavor" do
445
- expect(@instance.service).to receive_message_chain(:get_flavor).and_return("flavor")
443
+ it 'returns true on valid flavor' do
444
+ expect(@instance.service).to receive_message_chain(:get_flavor).and_return('flavor')
446
445
  expect(@instance.is_flavor_valid?).to be true
447
446
  end
448
447
  end