1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

mock configure_network_ip, delete_vapp doesn't do anything if rnat set

This commit is contained in:
Dan Peterson 2010-11-05 11:53:20 -03:00
parent 3d6ee32c15
commit ccbda1a969
5 changed files with 95 additions and 16 deletions

View file

@ -47,17 +47,7 @@ module Fog
end
def inspect
"<#{self.class.name} #{object_id} data=#{super} method_data=#{method_data.inspect}>"
end
private
def unique_methods
(public_methods - self.class.superclass.public_instance_methods).reject {|m| m.to_s =~ /!$/ }
end
def method_data
(unique_methods + [:href]).sort_by(&:to_s).find_all {|m| method(m).arity == 0 }.inject({}) {|md, m| md.update(m => send(m)) }
"<#{self.class.name} #{object_id} data=#{super}>"
end
end
@ -434,6 +424,10 @@ module Fog
def rnat
self[:rnat] || _parent._parent.rnat
end
def rnat_set?
!!self[:rnat]
end
end
class MockNetworkExtensions < Base
@ -495,6 +489,12 @@ module Fog
disks.inject(0) {|s, d| s + d.vcloud_size }
end
def network_ip
if network = _parent.networks.detect {|n| n.ip_collection.items[ip] }
network.ip_collection.items[ip]
end
end
# from fog ecloud server's _compose_vapp_data
def to_configure_vapp_hash
{

View file

@ -2,14 +2,19 @@ module Fog
class Vcloud
module Terremark
class Ecloud
class Real
module Shared
private
def validate_network_ip_data(network_ip_data, configure=false)
def validate_network_ip_data(network_ip_data)
valid_opts = [:id, :href, :name, :status, :server, :rnat]
unless valid_opts.all? { |opt| network_ip_data.keys.include?(opt) }
raise ArgumentError.new("Required data missing: #{(valid_opts - network_ip_data.keys).map(&:inspect).join(", ")}")
end
end
end
class Real
include Shared
def configure_network_ip(network_ip_uri, network_ip_data)
validate_network_ip_data(network_ip_data)
@ -38,13 +43,24 @@ module Fog
builder.RnatAddress(network_ip_data[:rnat])
}
end
end
class Mock
include Shared
def configure_network_ip(network_ip_uri, network_ip_data)
Fog::Mock.not_implemented
validate_network_ip_data(network_ip_data)
if network_ip = mock_data.network_ip_from_href(network_ip_uri)
network_ip[:rnat] = network_ip_data[:rnat]
builder = Builder::XmlMarkup.new
xml = network_ip_response(builder, network_ip, ecloud_xmlns)
mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ip+xml' }
else
mock_error 200, "401 Unauthorized"
end
end
end
end

View file

@ -13,7 +13,8 @@ module Fog
vdc = virtual_machine._parent
if vdc.internet_service_collection.items.detect {|is| is.node_collection.items.any? {|isn| isn.ip_address == virtual_machine.ip } } ||
virtual_machine.status != 2
virtual_machine.status != 2 ||
virtual_machine.network_ip.rnat_set?
mock_it 202, '', {}
else
vdc.virtual_machines.delete(virtual_machine)

View file

@ -0,0 +1,53 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
if Fog.mocking?
describe "Fog::Vcloud, initialized w/ the TMRK Ecloud module", :type => :mock_tmrk_ecloud_request do
subject { @vcloud }
it { should respond_to :configure_network_ip }
describe "#configure_network_ip" do
let(:original_network_ip) { @vcloud.get_network_ip(@mock_network_ip.href).body }
let(:network_ip_data) do
{
:id => original_network_ip[:Id],
:href => original_network_ip[:Href],
:name => original_network_ip[:Name],
:status => original_network_ip[:Status],
:server => original_network_ip[:Server],
:rnat => "1.2.3.4"
}
end
context "with a valid network ip uri" do
subject { @vcloud.configure_network_ip(@mock_network_ip.href, network_ip_data) }
it_should_behave_like "all responses"
describe "#body" do
subject { @vcloud.configure_network_ip(@mock_network_ip.href, network_ip_data).body }
#Stuff that shouldn't change
its(:Href) { should == @mock_network_ip.href }
its(:Id) { should == @mock_network_ip.object_id.to_s }
its(:Name) { should == @mock_network_ip.ip }
its(:Status) { should == @mock_network_ip.status }
#Stuff that should change
it "should change the rnat" do
expect { subject }.to change { @vcloud.get_network_ip(@mock_network_ip.href).body[:RnatAddress] }.to(network_ip_data[:rnat])
end
end
end
context "with a nodes uri that doesn't exist" do
subject { lambda { @vcloud.configure_network_ip(URI.parse('https://www.fakey.c/piv8vc99'), network_ip_data) } }
it_should_behave_like "a request for a resource that doesn't exist"
end
end
end
else
end

View file

@ -69,6 +69,15 @@ if Fog.mocking?
it_should_behave_like "all delete responses"
it_should_behave_like "a failed vapp deletion"
end
context "when the VM's IP has an rnat set" do
before do
@mock_vm.network_ip[:rnat] = "1.2.3.4"
end
it_should_behave_like "all delete responses"
it_should_behave_like "a failed vapp deletion"
end
end
context "with a vapp uri that doesn't exist" do