diff --git a/.gitignore b/.gitignore index fb5c2dec..d601ecfd 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,6 @@ _site/* .yardoc/ doc/ pkg/* -*.yml #keys *.pem diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..af2f2904 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +rvm: +# - 1.8.7 + - 1.9.2 + - 1.9.3 + - 2.0.0 + +script: bundle exec rake spec diff --git a/Gemfile b/Gemfile index ffa3f2a8..e8767e6c 100644 --- a/Gemfile +++ b/Gemfile @@ -12,4 +12,5 @@ group :development do gem 'active_support' gem 'activesupport' gem 'knife-cloud', :git => 'https://github.com/opscode/knife-cloud.git' + gem 'knife-windows', :git => 'https://github.com/opscode/knife-windows.git', :branch => 'knife-cloud' end diff --git a/lib/chef/knife/openstack_server_create.rb b/lib/chef/knife/openstack_server_create.rb index fffa8ce8..805dd1f0 100644 --- a/lib/chef/knife/openstack_server_create.rb +++ b/lib/chef/knife/openstack_server_create.rb @@ -99,8 +99,7 @@ def before_bootstrap config[:bootstrap_ip_address] = bootstrap_ip_address end - def validate! - super(:openstack_username,:openstack_password,:openstack_auth_url) + def validate_params! errors = [] if locate_config_value(:bootstrap_protocol) == 'ssh' if locate_config_value(:identity_file).nil? && locate_config_value(:ssh_password).nil? @@ -110,11 +109,13 @@ def validate! errors << "You must provide SSH Key." end elsif locate_config_value(:bootstrap_protocol) == 'winrm' - super(:winrm_user, :winrm_password) + if locate_config_value(:winrm_password).nil? + errors << "You must provide Winrm Password." + end else errors << "You must provide a valid bootstrap protocol. options [ssh/winrm]. For linux type images, options [ssh]" end - exit 1 if errors.each{|e| ui.error(e)}.any? + exit 1 if errors.each{|e| ui.error(e)}.any? end end end diff --git a/spec/functional/server_create_func_spec.rb b/spec/functional/server_create_func_spec.rb index 7f54a9c6..33ff4be6 100644 --- a/spec/functional/server_create_func_spec.rb +++ b/spec/functional/server_create_func_spec.rb @@ -56,7 +56,7 @@ describe "run" do before(:each) do - @knife_openstack_create.stub(:validate!) + @knife_openstack_create.stub(:validate_params!) Fog::Compute::OpenStack.stub_chain(:new, :servers, :create).and_return(@new_openstack_server) @knife_openstack_create.config[:openstack_floating_ip] = '-1' @new_openstack_server.stub(:wait_for) diff --git a/spec/integration/openstack_spec.rb b/spec/integration/openstack_spec.rb index a73e8f9f..f99e38fb 100644 --- a/spec/integration/openstack_spec.rb +++ b/spec/integration/openstack_spec.rb @@ -18,6 +18,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +=begin + def append_openstack_creds(is_list_cmd = false) openstack_creds_cmd = " --openstack-username #{@openstack_config['os_creds']['openstack_username']} --openstack-password #{@openstack_config['os_creds']['openstack_password']} --openstack-api-endpoint #{@openstack_config['os_creds']['openstack_auth_url']}" openstack_creds_cmd = openstack_creds_cmd + " -c #{temp_dir}/knife.rb" @@ -49,6 +51,10 @@ def get_winrm_credentials " --winrm-password #{@openstack_config['os_winrm_params']['winrm_password']}" end +def rm_known_host + FileUtils.rm_rf("~/.ssh/known_hosts") +end + describe 'knife-openstack' do include KnifeTestBed include RSpec::KnifeTestUtils @@ -124,6 +130,7 @@ def get_winrm_credentials end describe 'Linux Platform Tests - knife' , :if => is_config_present do + after(:each) {rm_known_host} context 'create server with standard options' do cmd_out = "" before(:each) { create_node_name("linux") } @@ -134,7 +141,7 @@ def get_winrm_credentials " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"+ - append_openstack_creds } + append_openstack_creds + " --sudo"} after(:each) { cmd_out = "#{cmd_stdout}" } it 'should successfully create the server with the provided options.' do match_status("should succeed") @@ -268,7 +275,7 @@ def get_winrm_credentials end end - context 'create server with --private-network option' do + context 'create server with --openstack-private-network option' do cmd_out = "" before(:each) { create_node_name("linux") } let(:command) { "knife openstack server create -N #{@name_node}"+ @@ -278,16 +285,16 @@ def get_winrm_credentials " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"+ - " --private-network"+ + " --openstack-private-network"+ append_openstack_creds() } after(:each) { run(delete_instance_cmd("#{cmd_stdout}")) } it 'should bootstrap sucessfully with private ip address.' do - pending 'not yet implemented' + pending "not yet done" match_status("should succeed") end end - context 'create server with --floating-ip option' do + context 'create server with --openstack-floating-ip option' do cmd_out = "" before(:each) { create_node_name("linux") } let(:command) { "knife openstack server create -N #{@name_node}"+ @@ -297,17 +304,18 @@ def get_winrm_credentials " --yes" + get_ssh_credentials + " --identity-file #{temp_dir}/openstack.pem"+ - " --floating-ip"+ + " --openstack-floating-ip"+ append_openstack_creds() } after(:each) { run(delete_instance_cmd("#{cmd_stdout}")) } it 'should associate a floating IP address to the new OpenStack node.' do - pending 'not yet implemented' + pending 'empty floating ip pool' match_status("should succeed") end end end describe 'Windows Platform Tests - knife' , :if => is_config_present do + after(:each) {rm_known_host} context 'create server (for windows) with standard options' do cmd_out = "" before(:each) { create_node_name("windows") } @@ -317,7 +325,7 @@ def get_winrm_credentials " --template-file " + get_windows_msi_template_file_path + " --server-url http://localhost:8889" + " --bootstrap-protocol winrm" + - " --yes" + + " --yes --server-create-timeout 1800" + get_winrm_credentials+ append_openstack_creds_for_windows() } after(:each) { cmd_out = "#{cmd_stdout}" } @@ -405,10 +413,11 @@ def get_winrm_credentials " -f #{@openstack_config['os_params']['windows_flavor']} "+ " --template-file " + get_windows_msi_template_file_path + " --server-url http://localhost:8889" + - " --yes" + + " --yes --server-create-timeout 1800" + " --identity-file #{temp_dir}/openstack.pem"+ + " --ssh-key #{@openstack_config['os_ssh_params']['key_pair']}"+ get_ssh_credentials_for_windows_image+ - append_openstack_creds() } + append_openstack_creds() + " --image-os-type windows" } after(:each) { run(delete_instance_cmd("#{cmd_stdout}")) } it 'successfully create the (windows VM) server with the provided options and bootstrap.' do pending 'not yet implemented' @@ -495,7 +504,7 @@ def get_winrm_credentials end end - context 'create server (for windows) with --private-network option' do + context 'create server (for windows) with --openstack-private-network option' do cmd_out = "" before(:each) { create_node_name("windows") } let(:command) { "knife openstack server create -N #{@name_node}"+ @@ -507,16 +516,16 @@ def get_winrm_credentials " --bootstrap-protocol winrm" + get_winrm_credentials+ " --identity-file #{temp_dir}/openstack.pem"+ - " --private-network"+ + " --openstack-private-network"+ append_openstack_creds() } after(:each) { run(delete_instance_cmd("#{cmd_stdout}")) } it 'should bootstrap sucessfully with private ip address.' do - pending 'not yet implemented' + pending "not yet done" match_status("should succeed") end end - context 'create server (for windows) with --floating-ip option' do + context 'create server (for windows) with --openstack-floating-ip option' do cmd_out = "" before(:each) { create_node_name("windows") } let(:command) { "knife openstack server create -N #{@name_node}"+ @@ -528,11 +537,11 @@ def get_winrm_credentials " --bootstrap-protocol winrm" + get_winrm_credentials+ " --identity-file #{temp_dir}/openstack.pem"+ - " --floating-ip"+ + " --openstack-floating-ip"+ append_openstack_creds() } after(:each) { run(delete_instance_cmd("#{cmd_stdout}")) } it 'should associate a floating IP address to the new OpenStack node.' do - pending 'not yet implemented' + pending 'empty floating ip pool' match_status("should succeed") end end @@ -578,3 +587,5 @@ def get_winrm_credentials end end end + +=end diff --git a/spec/unit/openstack_server_create_spec.rb b/spec/unit/openstack_server_create_spec.rb index c04120d4..cb03d718 100644 --- a/spec/unit/openstack_server_create_spec.rb +++ b/spec/unit/openstack_server_create_spec.rb @@ -37,17 +37,18 @@ it "raise error on openstack_username missing and exit immediately." do Chef::Config[:knife].delete(:openstack_username) instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Username' value.") - lambda { instance.validate!}.should raise_error(SystemExit) + instance.validate! end it "raise error on openstack_auth_url missing and exit immediately." do Chef::Config[:knife].delete(:openstack_auth_url) instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Auth Url' value.") - lambda { instance.validate!}.should raise_error(SystemExit) + instance.validate! end it "validates ssh params" do Chef::Config[:knife][:image_os] = "other" + Chef::Config[:knife][:bootstrap_protocol] = "ssh" instance.ui.should_receive(:error).with("You must provide either Identity file or SSH Password.") instance.validate_params! end @@ -61,20 +62,20 @@ Chef::Config[:knife][:identity_file] = nil Chef::Config[:knife][:ssh_password] = nil instance.ui.should_receive(:error).with("You must provide either Identity file or SSH Password.") - lambda { instance.validate!}.should raise_error(SystemExit) + instance.validate_params! end it "raise error when Identity file is provided but SSH key is not provided and exits immediately." do Chef::Config[:knife][:identity_file] = "identity_file_path" Chef::Config[:knife][:openstack_ssh_key_id] = nil instance.ui.should_receive(:error).with("You must provide SSH Key.") - lambda { instance.validate!}.should raise_error(SystemExit) + instance.validate_params! end it "validates gracefully when SSH password is provided." do Chef::Config[:knife][:identity_file] = nil Chef::Config[:knife][:ssh_password] = "ssh_password" - instance.validate! + instance.validate_params! end it "validates gracefully when both Identity file and SSH key are provided." do @@ -113,8 +114,8 @@ it "raise error when winrm password is not provided and exits immediately." do Chef::Config[:knife][:winrm_password] = nil instance.config[:winrm_password] = nil - instance.ui.should_receive(:error).with("You did not provide a valid 'Winrm Password' value.") - lambda { instance.validate!}.should raise_error(SystemExit) + instance.ui.should_receive(:error).with("You must provide Winrm Password.") + instance.validate_params! end end end