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

[knife-cloud] Fix rspec deprecation warnings #121

Merged
merged 2 commits into from
Jun 13, 2014
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
28 changes: 23 additions & 5 deletions spec/functional/flavor_list_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#
# Author:: Mukta Aphale (<[email protected]>)
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'chef/knife/openstack_flavor_list'
require 'chef/knife/cloud/openstack_service'
Expand All @@ -11,14 +29,14 @@
resources = [ TestResource.new({:id => "resource-1", :name => "m1.tiny", :vcpus => "1", :ram => 512, :disk => 0}),
TestResource.new({:id => "resource-2", :name => "m1-xlarge-bigdisk", :vcpus => "8", :ram => 16384, :disk => 50})
]
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!)
allow(instance).to receive(:query_resource).and_return(resources)
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
end

it "lists formatted list of resources" do
instance.ui.should_receive(:list).with(["Name", "ID", "Virtual CPUs", "RAM", "Disk",
expect(instance.ui).to receive(:list).with(["Name", "ID", "Virtual CPUs", "RAM", "Disk",
"m1-xlarge-bigdisk", "resource-2", "8", "16384 MB", "50 GB",
"m1.tiny", "resource-1", "1", "512 MB", "0 GB"], :uneven_columns_across, 5)
instance.run
Expand Down
29 changes: 24 additions & 5 deletions spec/functional/group_list_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#
# Author:: Mukta Aphale (<[email protected]>)
# Author:: Prabhu Das (<[email protected]>)
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'chef/knife/openstack_group_list'
require 'chef/knife/cloud/openstack_service'
Expand Down Expand Up @@ -32,14 +51,14 @@
]
})
]
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!)
allow(instance).to receive(:query_resource).and_return(resources)
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
end

it "lists formatted list of resources" do
instance.ui.should_receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description",
expect(instance.ui).to receive(:list).with(["Name", "Protocol", "From", "To", "CIDR", "Description",
"Unrestricted", "tcp", "1", "636", "0.0.0.0/0", "All ports open",
"WindowsDomain", "tcp", "22", "636", "0.0.0.0/0", "Allows common protocols useful in a Windows domain"], :uneven_columns_across, 6)
instance.run
Expand Down
30 changes: 24 additions & 6 deletions spec/functional/image_list_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#
# Author:: Mukta Aphale (<[email protected]>)
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'chef/knife/openstack_image_list'
require 'chef/knife/cloud/openstack_service'
Expand All @@ -10,21 +28,21 @@
resources = [ TestResource.new({:id => "resource-1", :name => "image01", :metadata => {} }),
TestResource.new({:id => "resource-2", :name => "initrd", :metadata => {} })
]
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!)
allow(instance).to receive(:query_resource).and_return(resources)
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
end

it "displays formatted list of images, filtered by default" do
instance.ui.should_receive(:list).with(["Name", "ID", "Snapshot",
expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
"image01", "resource-1", "no"], :uneven_columns_across, 3)
instance.run
end

it "lists all images when disable_filter = true" do
instance.config[:disable_filter] = true
instance.ui.should_receive(:list).with(["Name", "ID", "Snapshot",
expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
"image01", "resource-1", "no",
"initrd", "resource-2", "no"], :uneven_columns_across, 3)
instance.run
Expand Down
27 changes: 22 additions & 5 deletions spec/functional/network_list_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'chef/knife/openstack_network_list'
require 'chef/knife/cloud/openstack_service'
Expand All @@ -11,14 +28,14 @@
resources = [ TestResource.new({:id => "resource-1", :name => "external", :tenant_id => "1", :shared => true}),
TestResource.new({:id => "resource-2", :name => "internal", :tenant_id => "2", :shared => false})
]
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!)
allow(instance).to receive(:query_resource).and_return(resources)
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
end

it "lists formatted list of network resources" do
instance.ui.should_receive(:list).with(["Name", "ID", "Tenant", "Shared",
expect(instance.ui).to receive(:list).with(["Name", "ID", "Tenant", "Shared",
"external", "resource-1", "1", "true",
"internal", "resource-2", "2", "false"], :uneven_columns_across, 4)
instance.run
Expand Down
48 changes: 26 additions & 22 deletions spec/functional/server_create_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#
# Author:: Mukta Aphale (<[email protected]>)
# Author:: Kaustubh Deorukhkar (<[email protected]>)
# Author:: Siddheshwar More (<[email protected]>)
# Author:: Prabhu Das (<[email protected]>)
# Copyright:: Copyright (c) 2013 Chef Software, Inc.
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,6 +18,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require File.expand_path('../../spec_helper', __FILE__)

describe Chef::Knife::Cloud::OpenstackServerCreate do
Expand All @@ -31,17 +36,17 @@
end

@openstack_service = Chef::Knife::Cloud::OpenstackService.new
@openstack_service.stub(:msg_pair)
@openstack_service.stub(:print)
allow(@openstack_service).to receive(:msg_pair)
allow(@openstack_service).to receive(:print)
image = Object.new
allow(image).to receive(:id).and_return('image_id')
allow(@openstack_service).to receive(:get_image).and_return(image)
flavor = Object.new
allow(flavor).to receive(:id).and_return('flavor_id')
allow(@openstack_service).to receive(:get_flavor).and_return(flavor)

@knife_openstack_create.stub(:create_service_instance).and_return(@openstack_service)
@knife_openstack_create.stub(:puts)
allow(@knife_openstack_create).to receive(:create_service_instance).and_return(@openstack_service)
allow(@knife_openstack_create).to receive(:puts)
@new_openstack_server = double()

@openstack_server_attribs = { :name => 'Mock Server',
Expand All @@ -57,16 +62,16 @@
}

@openstack_server_attribs.each_pair do |attrib, value|
@new_openstack_server.stub(attrib).and_return(value)
allow(@new_openstack_server).to receive(attrib).and_return(value)
end
end

describe "run" do
before(:each) do
@knife_openstack_create.stub(:validate_params!)
Fog::Compute::OpenStack.stub_chain(:new, :servers, :create).and_return(@new_openstack_server)
allow(@knife_openstack_create).to receive(:validate_params!)
allow(Fog::Compute::OpenStack).to receive_message_chain(:new, :servers, :create).and_return(@new_openstack_server)
@knife_openstack_create.config[:openstack_floating_ip] = '-1'
@new_openstack_server.stub(:wait_for)
allow(@new_openstack_server).to receive(:wait_for)
end

context "for Linux" do
Expand All @@ -76,15 +81,15 @@
@bootstrapper = Chef::Knife::Cloud::Bootstrapper.new(@config)
@ssh_bootstrap_protocol = Chef::Knife::Cloud::SshBootstrapProtocol.new(@config)
@unix_distribution = Chef::Knife::Cloud::UnixDistribution.new(@config)
@ssh_bootstrap_protocol.stub(:send_bootstrap_command)
allow(@ssh_bootstrap_protocol).to receive(:send_bootstrap_command)
end

it "Creates an OpenStack instance and bootstraps it" do
Chef::Knife::Cloud::Bootstrapper.should_receive(:new).with(@config).and_return(@bootstrapper)
@bootstrapper.stub(:bootstrap).and_call_original
@bootstrapper.should_receive(:create_bootstrap_protocol).and_return(@ssh_bootstrap_protocol)
@bootstrapper.should_receive(:create_bootstrap_distribution).and_return(@unix_distribution)
@openstack_service.should_receive(:server_summary).exactly(2).times
expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper)
allow(@bootstrapper).to receive(:bootstrap).and_call_original
expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@ssh_bootstrap_protocol)
expect(@bootstrapper).to receive(:create_bootstrap_distribution).and_return(@unix_distribution)
expect(@openstack_service).to receive(:server_summary).exactly(2).times
@knife_openstack_create.run
end
end
Expand All @@ -100,15 +105,14 @@
@windows_distribution = Chef::Knife::Cloud::WindowsDistribution.new(@config)
end
it "Creates an OpenStack instance for Windows and bootstraps it" do
Chef::Knife::Cloud::Bootstrapper.should_receive(:new).with(@config).and_return(@bootstrapper)
@bootstrapper.stub(:bootstrap).and_call_original
@bootstrapper.should_receive(:create_bootstrap_protocol).and_return(@winrm_bootstrap_protocol)
@bootstrapper.should_receive(:create_bootstrap_distribution).and_return(@windows_distribution)
@winrm_bootstrap_protocol.stub(:send_bootstrap_command)
@openstack_service.should_receive(:server_summary).exactly(2).times
expect(Chef::Knife::Cloud::Bootstrapper).to receive(:new).with(@config).and_return(@bootstrapper)
allow(@bootstrapper).to receive(:bootstrap).and_call_original
expect(@bootstrapper).to receive(:create_bootstrap_protocol).and_return(@winrm_bootstrap_protocol)
expect(@bootstrapper).to receive(:create_bootstrap_distribution).and_return(@windows_distribution)
allow(@winrm_bootstrap_protocol).to receive(:send_bootstrap_command)
expect(@openstack_service).to receive(:server_summary).exactly(2).times
@knife_openstack_create.run
end
end

end
end
39 changes: 21 additions & 18 deletions spec/functional/server_delete_func_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#
# Author:: Siddheshwar More (<[email protected]>)
# Author:: Prabhu Das (<[email protected]>)
# Copyright:: Copyright (c) 2013 Chef Software, Inc.
# Author:: Ameya Varade (<[email protected]>)
# Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,6 +16,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require File.expand_path('../../spec_helper', __FILE__)
require 'chef/knife/openstack_server_delete'
require 'chef/knife/cloud/openstack_service'
Expand All @@ -34,10 +37,10 @@
end

@openstack_service = Chef::Knife::Cloud::OpenstackService.new
@openstack_service.stub(:msg_pair)
@knife_openstack_delete.stub(:create_service_instance).and_return(@openstack_service)
@knife_openstack_delete.ui.stub(:warn)
@knife_openstack_delete.ui.stub(:confirm)
allow(@openstack_service).to receive(:msg_pair)
allow(@knife_openstack_delete).to receive(:create_service_instance).and_return(@openstack_service)
allow(@knife_openstack_delete.ui).to receive(:warn)
allow(@knife_openstack_delete.ui).to receive(:confirm)
@openstack_servers = double()
@running_openstack_server = double()
@openstack_server_attribs = { :name => 'Mock Server',
Expand All @@ -51,30 +54,30 @@
}

@openstack_server_attribs.each_pair do |attrib, value|
@running_openstack_server.stub(attrib).and_return(value)
allow(@running_openstack_server).to receive(attrib).and_return(value)
end
@knife_openstack_delete.name_args = ['test001']
end

describe "run" do
it "deletes an OpenStack instance." do
@openstack_servers.should_receive(:get).and_return(@running_openstack_server)
@openstack_connection.should_receive(:servers).and_return(@openstack_servers)
Fog::Compute::OpenStack.should_receive(:new).and_return(@openstack_connection)
@running_openstack_server.should_receive(:destroy)
expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server)
expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers)
expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection)
expect(@running_openstack_server).to receive(:destroy)
@knife_openstack_delete.run
end

it "deletes the instance along with the node and client on the chef-server when --purge is given as an option." do
@knife_openstack_delete.config[:purge] = true
Chef::Node.should_receive(:load).and_return(@chef_node)
@chef_node.should_receive(:destroy)
Chef::ApiClient.should_receive(:load).and_return(@chef_client)
@chef_client.should_receive(:destroy)
@openstack_servers.should_receive(:get).and_return(@running_openstack_server)
@openstack_connection.should_receive(:servers).and_return(@openstack_servers)
Fog::Compute::OpenStack.should_receive(:new).and_return(@openstack_connection)
@running_openstack_server.should_receive(:destroy)
expect(Chef::Node).to receive(:load).and_return(@chef_node)
expect(@chef_node).to receive(:destroy)
expect(Chef::ApiClient).to receive(:load).and_return(@chef_client)
expect(@chef_client).to receive(:destroy)
expect(@openstack_servers).to receive(:get).and_return(@running_openstack_server)
expect(@openstack_connection).to receive(:servers).and_return(@openstack_servers)
expect(Fog::Compute::OpenStack).to receive(:new).and_return(@openstack_connection)
expect(@running_openstack_server).to receive(:destroy)
@knife_openstack_delete.run
end
end
Expand Down
Loading