Skip to content

Commit

Permalink
Merge pull request #110 from opscode/pd-network-list
Browse files Browse the repository at this point in the history
Network list implementation
  • Loading branch information
kaustubh-d committed May 29, 2014
2 parents 701fe77 + cfa8db1 commit ad4f91c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/chef/knife/openstack_network_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Author:: Prabhu Das (<[email protected]>)
# Copyright:: Copyright (c) 2014 Chef Software, Inc.

require 'chef/knife/cloud/list_resource_command'
require 'chef/knife/openstack_helpers'
require 'chef/knife/cloud/openstack_service_options'

class Chef
class Knife
class Cloud
class OpenstackNetworkList < ResourceListCommand
include OpenstackHelpers
include OpenstackServiceOptions

banner "knife openstack network list (options)"

def before_exec_command
#set columns_with_info map
@columns_with_info = [
{:label => 'Name', :key => 'name'},
{:label => 'ID', :key => 'id'},
{:label => 'Tenant', :key => 'tenant_id'},
{:label => 'Shared', :key => 'shared'}
]
end

def query_resource
@service.list_networks
end

end
end
end
end
49 changes: 49 additions & 0 deletions spec/unit/openstack_network_list_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'spec_helper'
require 'chef/knife/openstack_network_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'

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

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

context "#validate!" do
before(:each) do
Chef::Config[:knife][:openstack_username] = "testuser"
Chef::Config[:knife][:openstack_password] = "testpassword"
Chef::Config[:knife][:openstack_auth_url] = "tsturl"
instance.stub(:exit)
end

it "validate openstack mandatory options" do
expect {instance.validate!}.to_not raise_error
end

it "raise error on openstack_username missing" do
Chef::Config[:knife].delete(:openstack_username)
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Username' value.")
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
end

it "raise error on openstack_password missing" do
Chef::Config[:knife].delete(:openstack_password)
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Password' value.")
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
end

it "raise error on openstack_auth_url missing" do
Chef::Config[:knife].delete(:openstack_auth_url)
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Auth Url' value.")
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError)
end
end

context "query_resource" do
it "returns the networks using the fog service." do
instance.service = double
instance.service.should_receive(:list_networks)
instance.query_resource
end
end
end

0 comments on commit ad4f91c

Please sign in to comment.