Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 86: Merge Gem dependencies, Travis support #46

Merged
merged 35 commits into from
Aug 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2fd4b56
Unmarked pending integration tests
Jul 24, 2013
d11cd55
Merge remote-tracking branch 'upstream/knife-cloud' into knife-cloud
Jul 24, 2013
f66ae53
Fixed merge issue: we only call the validate_params from the server c…
Jul 24, 2013
7313912
Updated integration tests to use proper openstack-floating-ip opensta…
Jul 24, 2013
ba9ef79
Updated integration tests to use proper openstack-floating-ip opensta…
Jul 24, 2013
54f45e1
Updated integration tests to add missing ssh-key option
Jul 24, 2013
d5f9b9c
Updated Gemfile to use CT/knife-cloud bootstrap branch
Jul 25, 2013
288636b
Added validation for openstack winrm password
Jul 26, 2013
06381a1
Marked floating ip related integration test as a pending
Jul 29, 2013
1cda189
Updated Gemfile to use refactor knife-windows
Jul 30, 2013
feb01ee
Reverting previous 2 commits
Jul 30, 2013
87a9c0d
Fixed typo in Gemfile
Jul 30, 2013
b923518
Updated Gemfile to use refactor knife-windows
Jul 30, 2013
2eec015
Fixed typo in Gemfile
Jul 30, 2013
aa085fd
Merge branch 'sid-oc-9112-gem-deps' of https://github.com/ClogenyTech…
Jul 30, 2013
4a24562
Updated Gemfile
Jul 30, 2013
400a84d
Added .travis.yml for knife-openstack
Jul 31, 2013
0c99ec7
Fixing gem file dependency
Aug 1, 2013
7170679
Marked openstack-private-network option related integration tests as …
Aug 1, 2013
a1fd236
Fixed unit tests that failed after merge
Aug 1, 2013
00ee397
Merge branch 'knife-cloud-issues' of https://github.com/ClogenyTechno…
Aug 1, 2013
b3ed97b
Fixed merge issue: we only call the validate_params from the server c…
Jul 24, 2013
5941472
Added validation for openstack winrm password
Jul 26, 2013
c013625
Fixing gem file dependency
Aug 1, 2013
cfa5321
Fixed unit tests that failed after merge
Aug 1, 2013
0ce069d
Updated integration tests to add missing ssh-key option
Jul 24, 2013
f56b331
Marked floating ip related integration test as a pending
Aug 1, 2013
295db27
Marked openstack-private-network option related integration tests as …
Aug 1, 2013
a8c3f79
Updated server create functional tests to stub validate_params
Aug 1, 2013
661b478
Updated travis config file to use ruby 1.9.1
Aug 2, 2013
6c0ec5b
Updated travis config file to use ruby 1.9.2 and remove 1.9.1
Aug 2, 2013
d0a0160
Updated integration tests to add image-os-type option
Aug 6, 2013
759221e
Merge branch 'sid-oc-9108-knife-openstack-travis' of https://github.c…
Aug 6, 2013
ad18300
Updated gem file with correct gem dependency for knife-cloud
Aug 6, 2013
cb4c96c
Disable integration tests against internal infrastructure
Aug 6, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ _site/*
.yardoc/
doc/
pkg/*
*.yml

#keys
*.pem
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rvm:
# - 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0

script: bundle exec rake spec
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/functional/server_create_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 27 additions & 16 deletions spec/integration/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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") }
Expand All @@ -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")
Expand Down Expand Up @@ -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}"+
Expand All @@ -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}"+
Expand All @@ -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") }
Expand All @@ -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}" }
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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}"+
Expand All @@ -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}"+
Expand All @@ -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
Expand Down Expand Up @@ -578,3 +587,5 @@ def get_winrm_credentials
end
end
end

=end
15 changes: 8 additions & 7 deletions spec/unit/openstack_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down