Skip to content

Commit

Permalink
Merge pull request #155 from PierreRambaud/fix-travis
Browse files Browse the repository at this point in the history
Fix rspec tests for travis CI
  • Loading branch information
JJ Asghar committed Mar 5, 2015
2 parents ea6afff + a574d52 commit aedc58c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ gemspec
group :development do
gem 'guard-rspec'
gem 'mixlib-shellout'
gem 'knife-windows', :git => 'https://github.com/opscode/knife-windows.git'
gem 'knife-windows'
end
2 changes: 1 addition & 1 deletion lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def after_exec_command

floating_ip_id = get_floating_ip_id(floating_address)
# Associate the floating ip via the neutron/network api
@service.network.associate_floating_ip(floating_ip_id, port_id, options = {:fixed_ip_address => fixed_ip_address })
@service.network.associate_floating_ip(floating_ip_id, port_id, {:fixed_ip_address => fixed_ip_address })

#a bit of a hack, but server.reload takes a long time
(server.addresses['public'] ||= []) << {"version"=>4,"addr"=>floating_address}
Expand Down
2 changes: 0 additions & 2 deletions spec/unit/validate_spec.rb → spec/spec_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'

shared_context "#validate!" do |instance|
before(:each) do
Chef::Config[:knife][:openstack_username] = "testuser"
Expand Down
7 changes: 4 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
require 'resource_spec_helper'
require 'server_command_common_spec_helper'
require 'tempfile'
require 'spec_context'

def find_instance_id(instance_name, file)
file.lines.each do |line|
Expand Down Expand Up @@ -61,7 +62,7 @@ def is_config_present
err_msg = "\nPlease set #{unset_env_var.join(', ')} environment"
err_msg = err_msg + ( unset_env_var.length > 1 ? " variables " : " variable " ) + "for integration tests."
puts err_msg unless unset_env_var.empty?

%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|
option_value = ENV[os_config_opt] || (openstack_config[os_config_opt] if openstack_config)
if option_value.nil?
Expand All @@ -73,7 +74,7 @@ def is_config_present
config_err_msg = "\nPlease set #{unset_config_options.join(', ')} config"
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."
puts config_err_msg unless unset_config_options.empty?

is_config
end

Expand Down Expand Up @@ -127,4 +128,4 @@ def create_sh_user_data_file
def delete_sh_user_data_file(file)
file.close
file.unlink
end
end
1 change: 0 additions & 1 deletion spec/unit/openstack_flavor_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require 'chef/knife/openstack_flavor_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackFlavorList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFlavorList.new
Expand Down
1 change: 0 additions & 1 deletion spec/unit/openstack_group_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require 'chef/knife/openstack_group_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackGroupList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackGroupList.new
Expand Down
1 change: 0 additions & 1 deletion spec/unit/openstack_image_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require 'chef/knife/openstack_image_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackImageList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackImageList.new
Expand Down
1 change: 0 additions & 1 deletion spec/unit/openstack_network_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
require 'chef/knife/openstack_network_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackNetworkList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new
Expand Down
30 changes: 18 additions & 12 deletions spec/unit/openstack_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
allow(Chef::Config[:knife][:network_ids]).to receive(:map).and_return(Chef::Config[:knife][:network_ids].split(","))
expect(@instance).to receive(:post_connection_validations)
end

it "creates the server_def with multiple nic_ids." do
@instance.before_exec_command
expect(@instance.create_options[:server_def][:nics]).to be == ["test_network_id1", "test_network_id2"]
Expand Down Expand Up @@ -165,7 +165,6 @@
Chef::Config[:knife][:openstack_floating_ip] = "-1"
@instance.service = Chef::Knife::Cloud::Service.new
@instance.server = double
expect(@instance.server).to_not receive(:associate_address)
allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
expect(@instance).to receive(:bootstrap)
@instance.after_exec_command
Expand All @@ -175,15 +174,24 @@
Chef::Config[:knife][:openstack_floating_ip] = nil
@instance.service = Chef::Knife::Cloud::Service.new
@instance.server = double

@network = double
@ports = ['id' => 'test',
'fixed_ips' => ['ip_address' => '127.0.1.1']]
allow(@network).to receive(:list_ports).and_return(body: {'ports' => @ports})
@floating_ips = ['id' => 'test',
'fixed_ips' => ['ip_address' => '127.0.1.1']]
allow(@network).to receive(:list_floating_ips).and_return(body: {'floatingips' => @floating_ips})
allow(@network).to receive(:associate_floating_ip)
allow(@instance.service).to receive(:network).and_return(@network)

allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
expect(@instance).to receive(:bootstrap)
connection = double
allow(@instance.service).to receive(:connection).and_return(double)
free_floating = Object.new
free_floating.define_singleton_method(:fixed_ip) { return nil }
free_floating.define_singleton_method(:ip) { return "127.0.0.1" }
expect(@instance.service.connection).to receive(:addresses).and_return([free_floating])
expect(@instance.server).to receive(:associate_address).with(free_floating.ip)
@instance.after_exec_command
end

Expand All @@ -194,14 +202,12 @@
@instance.server = double
allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>"127.0.1.1"}]})
expect(@instance).to_not receive(:bootstrap)
connection = double
allow(@instance.service).to receive(:connection).and_return(double)
free_floating = Object.new
free_floating.define_singleton_method(:fixed_ip) { return "127.0.0.1" }
expect(@instance.service.connection).to receive(:addresses).and_return([free_floating])
expect(@instance.server).to_not receive(:associate_address)
expect { @instance.after_exec_command }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ServerSetupError, "Unable to assign a Floating IP from allocated IPs.")
end
end
end

describe "#before_bootstrap" do
Expand Down Expand Up @@ -260,7 +266,7 @@
allow(@instance.server).to receive(:addresses).and_return({"public"=>[{"version"=>4, "addr"=>nil}]})
expect { @instance.before_bootstrap }.to raise_error(Chef::Knife::Cloud::CloudExceptions::BootstrapError, "No IP address available for bootstrapping.")
end

it "set public ip as default bootstrap network is public" do
allow(@instance.server).to receive(:addresses).and_return({"private"=>[{"version"=>4, "addr"=>"127.0.0.1"}], "public"=>[{"version"=>4, "addr"=>"127.0.0.2"}]})
@instance.before_bootstrap
Expand Down Expand Up @@ -290,7 +296,7 @@
expect(@instance.server).to_not receive(:password)
@instance.before_bootstrap
expect(@instance.config[:ssh_password]).to be == server_password
end
end
end

describe "#post_connection_validations" do
Expand All @@ -315,7 +321,7 @@

it "raise error on invalid floating IP" do
allow(@instance).to receive(:is_flavor_valid?).and_return(true)
allow(@instance).to receive(:is_image_valid?).and_return(true)
allow(@instance).to receive(:is_image_valid?).and_return(true)
expect(@instance).to receive(:is_floating_ip_valid?).and_return(false)
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..")
end
Expand All @@ -342,7 +348,7 @@
expect(@instance.service).to receive_message_chain(:connection, :addresses).and_return([])
expect(@instance.is_floating_ip_valid?).to be false
end

context "when floating ip requested without value" do
it "returns true if fixed_ip is nil" do
Chef::Config[:knife][:openstack_floating_ip] = nil
Expand Down Expand Up @@ -405,7 +411,7 @@
after(:each) do
Chef::Config[:knife].delete(:flavor)
end

it "returns false on invalid flavor" do
expect(@instance.service).to receive_message_chain(:get_flavor).and_return(nil)
expect(@instance.is_flavor_valid?).to be false
Expand Down
1 change: 0 additions & 1 deletion spec/unit/openstack_server_delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
require 'chef/knife/openstack_server_delete'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_serverdeletecommand'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerDelete do
it_behaves_like Chef::Knife::Cloud::ServerDeleteCommand, Chef::Knife::Cloud::OpenstackServerDelete.new
Expand Down
1 change: 0 additions & 1 deletion spec/unit/openstack_server_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
require 'chef/knife/openstack_server_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerList.new
Expand Down
3 changes: 1 addition & 2 deletions spec/unit/openstack_server_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
require 'chef/knife/openstack_server_show'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerShow do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerShow.new

include_context "#validate!", Chef::Knife::Cloud::OpenstackServerShow.new

let (:instance) {Chef::Knife::Cloud::OpenstackServerShow.new}

context "#validate_params!" do
Expand Down

0 comments on commit aedc58c

Please sign in to comment.