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

Update mocks and tests to simulate real calls in pro.

This commit is contained in:
Rupak Ganguly 2012-04-10 18:11:56 -04:00
parent dc42fb5c75
commit 86497010ca
11 changed files with 41 additions and 25 deletions

View file

@ -22,13 +22,18 @@ module Fog
response = Excon::Response.new
if server = self.data[:servers][server_id]
data = {"version"=>4, "addr"=>"#{ip_address}"}
if server['addresses']['private']
server['addresses']['private'] << data
response.status = 202
response
else
raise Fog::Compute::HP::NotFound
server['addresses']['private'] = data
end
response.status = 202
else
#raise Fog::Compute::HP::NotFound
response.status = 500
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end

View file

@ -51,8 +51,8 @@ module Fog
def create_security_group(name, description)
# all spaces are removed
name = name.strip!
description = description.strip!
name = name.strip
description = description.strip
response = Excon::Response.new
if self.data[:security_groups].detect {|_,v| v['name'] == name}

View file

@ -25,10 +25,12 @@ module Fog
self.data[:servers][server_id]['addresses']['private'] = data
response.status = 202
response
else
raise Fog::Compute::HP::NotFound
#raise Fog::Compute::HP::NotFound
response.status = 500
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end

View file

@ -38,7 +38,8 @@ module Fog
response = Excon::Response.new
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
private_address = []
data = server['addresses']["#{network_name}"][0]
data = nil
data = server['addresses']["#{network_name}"][0] if server['addresses']["#{network_name}"]
if data
private_address << data
end

View file

@ -27,10 +27,10 @@ module Fog
self.data[:addresses].delete(address_id)
response.status = 202
response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n "
response
else
raise Fog::Compute::HP::NotFound
end
response
end
end

View file

@ -1,8 +1,10 @@
Shindo.tests("Fog::Compute[:hp] | address", ['hp']) do
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
model_tests(Fog::Compute[:hp].addresses, {}, true) do
@server = Fog::Compute[:hp].servers.create(:name => "fogservertests", :flavor_id => 100, :image_id => 1242)
@server = Fog::Compute[:hp].servers.create(:name => "fogservertests", :flavor_id => 100, :image_id => @base_image_id)
@server.wait_for { ready? }
tests('#server=').succeeds do

View file

@ -7,6 +7,8 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
'id' => Integer
}
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do
tests("#list_addresses").formats({'floating_ips' => [@floating_ips_format]}) do
@ -24,14 +26,14 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
Fog::Compute[:hp].get_address(@address_id).body['floating_ip']
end
@server = Fog::Compute[:hp].servers.create(:name => 'fogaddresstests', :flavor_id => 100, :image_id => 1242)
@server = Fog::Compute[:hp].servers.create(:name => 'fogaddresstests', :flavor_id => 100, :image_id => @base_image_id)
@server.wait_for { ready? }
tests("#associate_address('#{@server.id}', '#{@ip_address}')").succeeds do
Fog::Compute[:hp].associate_address(@server.id, @ip_address)
tests("#get_address").returns(@server.id, "associated to valid instance id") do
pending if Fog.mocking?
Fog::Compute[:hp].get_address(@address_id).body['floating_ip']['instance_id'].to_s
Fog::Compute[:hp].get_address(@address_id).body['floating_ip']['instance_id']
end
end
@ -53,11 +55,11 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
Fog::Compute[:hp].get_address('invalidaddress')
end
tests("#associate_address('invalidserver', 'invalidip')").raises(Fog::Compute::HP::NotFound) do
tests("#associate_address('invalidserver', 'invalidip')").raises(Excon::Errors::InternalServerError) do
Fog::Compute[:hp].associate_address('invalidserver', 'invalidip')
end
tests("#disassociate_address('invalidserver', 'invalidip')").raises(Fog::Compute::HP::NotFound) do
tests("#disassociate_address('invalidserver', 'invalidip')").raises(Excon::Errors::InternalServerError) do
Fog::Compute[:hp].disassociate_address('invalidserver', 'invalidip')
end

View file

@ -36,8 +36,8 @@ Shindo.tests('Fog::Compute[:hp] | flavor requests', ['hp']) do
tests('failure') do
tests('#get_flavor_details(0)').raises(Fog::Compute::HP::NotFound) do
Fog::Compute[:hp].get_flavor_details(0)
tests('#get_flavor_details(9999)').raises(Fog::Compute::HP::NotFound) do
Fog::Compute[:hp].get_flavor_details(9999)
end
end

View file

@ -18,7 +18,7 @@ Shindo.tests('Fog::Compute[:hp] | image requests', ['hp']) do
'name' => String
}
@base_image_id = 128 #1242
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do
@server_name = "fogservertest"

View file

@ -1,7 +1,9 @@
Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do
@server = Fog::Compute[:hp].servers.create(:name => 'fogaddresstests', :flavor_id => 100, :image_id => 1242)
@server = Fog::Compute[:hp].servers.create(:name => 'fogaddresstests', :flavor_id => 100, :image_id => @base_image_id)
# the network name is currently named 'private'
tests("#list_server_addresses(#{@server.id})").formats({'addresses' => {"private" => [Hash]}}) do

View file

@ -34,13 +34,15 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do
}
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do
@server_id = nil
@server_name = "fogservertests"
tests("#create_server(#{@server_name}, 100, 1242)").formats(@server_format.merge('adminPass' => String)) do
data = Fog::Compute[:hp].create_server(@server_name, 100, 1242).body['server']
tests("#create_server(#{@server_name}, 100, #{@base_image_id})").formats(@server_format.merge('adminPass' => String)) do
data = Fog::Compute[:hp].create_server(@server_name, 100, @base_image_id).body['server']
@server_id = data['id']
data
end
@ -67,14 +69,14 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
tests("#reboot_server(#{@server_id}, 'HARD')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'HARD')
tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'SOFT')
end
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'SOFT')
tests("#reboot_server(#{@server_id}, 'HARD')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'HARD')
end
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }