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 response = Excon::Response.new
if server = self.data[:servers][server_id] if server = self.data[:servers][server_id]
data = {"version"=>4, "addr"=>"#{ip_address}"} data = {"version"=>4, "addr"=>"#{ip_address}"}
if server['addresses']['private']
server['addresses']['private'] << data server['addresses']['private'] << data
response.status = 202
response
else else
raise Fog::Compute::HP::NotFound server['addresses']['private'] = data
end 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
end end

View file

@ -51,8 +51,8 @@ module Fog
def create_security_group(name, description) def create_security_group(name, description)
# all spaces are removed # all spaces are removed
name = name.strip! name = name.strip
description = description.strip! description = description.strip
response = Excon::Response.new response = Excon::Response.new
if self.data[:security_groups].detect {|_,v| v['name'] == name} 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 self.data[:servers][server_id]['addresses']['private'] = data
response.status = 202 response.status = 202
response
else else
raise Fog::Compute::HP::NotFound #raise Fog::Compute::HP::NotFound
response.status = 500
raise(Excon::Errors.status_error({:expects => 200}, response))
end end
response
end end
end end

View file

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

View file

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

View file

@ -1,8 +1,10 @@
Shindo.tests("Fog::Compute[:hp] | address", ['hp']) do Shindo.tests("Fog::Compute[:hp] | address", ['hp']) do
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
model_tests(Fog::Compute[:hp].addresses, {}, true) do 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? } @server.wait_for { ready? }
tests('#server=').succeeds do tests('#server=').succeeds do

View file

@ -7,6 +7,8 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
'id' => Integer 'id' => Integer
} }
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do tests('success') do
tests("#list_addresses").formats({'floating_ips' => [@floating_ips_format]}) 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'] Fog::Compute[:hp].get_address(@address_id).body['floating_ip']
end 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? } @server.wait_for { ready? }
tests("#associate_address('#{@server.id}', '#{@ip_address}')").succeeds do tests("#associate_address('#{@server.id}', '#{@ip_address}')").succeeds do
Fog::Compute[:hp].associate_address(@server.id, @ip_address) Fog::Compute[:hp].associate_address(@server.id, @ip_address)
tests("#get_address").returns(@server.id, "associated to valid instance id") do tests("#get_address").returns(@server.id, "associated to valid instance id") do
pending if Fog.mocking? 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
end end
@ -53,11 +55,11 @@ Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
Fog::Compute[:hp].get_address('invalidaddress') Fog::Compute[:hp].get_address('invalidaddress')
end 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') Fog::Compute[:hp].associate_address('invalidserver', 'invalidip')
end 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') Fog::Compute[:hp].disassociate_address('invalidserver', 'invalidip')
end end

View file

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

View file

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

View file

@ -1,7 +1,9 @@
Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do Shindo.tests('Fog::Compute[:hp] | address requests', ['hp']) do
@base_image_id = ENV["BASE_IMAGE_ID"] ||= 1242
tests('success') do 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' # the network name is currently named 'private'
tests("#list_server_addresses(#{@server.id})").formats({'addresses' => {"private" => [Hash]}}) do 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 tests('success') do
@server_id = nil @server_id = nil
@server_name = "fogservertests" @server_name = "fogservertests"
tests("#create_server(#{@server_name}, 100, 1242)").formats(@server_format.merge('adminPass' => String)) do 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, 1242).body['server'] data = Fog::Compute[:hp].create_server(@server_name, 100, @base_image_id).body['server']
@server_id = data['id'] @server_id = data['id']
data data
end end
@ -67,14 +69,14 @@ Shindo.tests('Fog::Compute[:hp] | server requests', ['hp']) do
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? } Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
tests("#reboot_server(#{@server_id}, 'HARD')").succeeds do tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'HARD') Fog::Compute[:hp].reboot_server(@server_id, 'SOFT')
end end
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? } Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }
tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do tests("#reboot_server(#{@server_id}, 'HARD')").succeeds do
Fog::Compute[:hp].reboot_server(@server_id, 'SOFT') Fog::Compute[:hp].reboot_server(@server_id, 'HARD')
end end
Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? } Fog::Compute[:hp].servers.get(@server_id).wait_for { ready? }