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

OC-9613: os_image_type should be inferred from bootstrap protocol if not specified to knife cloud #63

Merged
merged 6 commits into from
Sep 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ class OpenstackServerCreate < ServerCreateCommand

banner "knife openstack server create (options)"

def set_image_os_type
# Openstack does not provide a way to identify image os type, So image_os_type is taken from user.
end

def before_exec_command
# setup the create options
@create_options = {
:server_def => {
#servers require a name, generate one if not passed
:name => get_node_name(locate_config_value(:chef_node_name)),
#servers require a name, knife-cloud generates the chef_node_name
:name => config[:chef_node_name],
:image_ref => locate_config_value(:image),
:flavor_ref => locate_config_value(:flavor),
:security_groups => locate_config_value(:openstack_security_groups),
Expand Down
3 changes: 3 additions & 0 deletions lib/chef/knife/openstack_server_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
require 'chef/knife/cloud/server/list_command'
require 'chef/knife/openstack_helpers'
require 'chef/knife/cloud/openstack_service_options'
require 'chef/knife/cloud/server/list_options'

class Chef
class Knife
class Cloud
class OpenstackServerList < ServerListCommand
include OpenstackHelpers
include OpenstackServiceOptions
include ServerListOptions

banner "knife openstack server list (options)"

Expand All @@ -43,6 +45,7 @@ def before_exec_command
{:label => 'Keypair', :key => 'key_name'},
{:label => 'State', :key => 'state'}
]
super
end

def get_public_ip_address (addresses)
Expand Down
52 changes: 47 additions & 5 deletions spec/functional/server_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,62 @@

context "functionality" do
before do
resources = [ TestResource.new({:id => "resource-1", :name => "ubuntu01", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}),
@resources = [ TestResource.new({:id => "resource-1", :name => "ubuntu01", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}),
TestResource.new({:id => "resource-2", :name => "windows2008", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}]}, :flavor => {"id" => "id2"}, :image => {"id" => "image2"}, :key_name => "keypair", :state => "ACTIVE"})
]
instance.stub(:query_resource).and_return(resources)
instance.stub(:query_resource).and_return(@resources)
instance.stub(:puts)
instance.stub(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
instance.stub(:validate!)
end

it "lists formatted list of resources" do
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State",
"resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1","keypair", "ACTIVE",
"resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE"], :uneven_columns_across, 8)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1","keypair", "ACTIVE", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE"], :uneven_columns_across, 8)
instance.run
end

context "when chef-data and chef-node-attribute set" do
before(:each) do
@resources.push(TestResource.new({:id => "server-4", :name => "server-4", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}))

@node = TestResource.new({:id => "server-4", :name => "server-4", :chef_environment => "_default", :fqdn => "testfqdnnode.us", :run_list => [], :tags => [], :platform => "ubuntu", :platform_family => "debian"})

Chef::Node.stub(:list).and_return({"server-4" => @node})
instance.config[:chef_data] = true
end

it "lists formatted list of resources on chef data option set" do
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 14)

instance.run
end

it "lists formatted list of resources on chef-data and chef-node-attribute option set" do
instance.config[:chef_node_attribute] = "platform_family"
@node.should_receive(:attribute?).with("platform_family").and_return(true)

instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "platform_family", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", "debian"], :uneven_columns_across, 15)

instance.run
end

it "raise error on invalid chef-node-attribute set" do
instance.config[:chef_node_attribute] = "invalid_attribute"
@node.should_receive(:attribute?).with("invalid_attribute").and_return(false)
instance.ui.should_receive(:error).with("The Node does not have a invalid_attribute attribute.")
expect { instance.run }.to raise_error
end

it "not display chef-data on chef-node-attribute set but chef-data option missing" do
instance.config[:chef_data] = false
instance.config[:chef_node_attribute] = "platform_family"

instance.ui.should_not_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 14)

instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE"], :uneven_columns_across, 8)

instance.run
end
end
end
end
Loading