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

[openstack|compute] Add requests, models and tests for address

management

- Added tests to already existing requests.
- Modified the all method in the model as it doesn't have the server id
  when querying.
This commit is contained in:
Alfonso Juan Dillera 2012-02-24 19:24:00 +08:00 committed by Nelvin Driz
parent e99450ec1f
commit 62e73549e6
6 changed files with 133 additions and 24 deletions

View file

@ -9,8 +9,8 @@ module Fog
model Fog::Compute::OpenStack::Address model Fog::Compute::OpenStack::Address
def all def all(server_id)
load(connection.list_addresses.body['floating_ips']) load(connection.list_all_addresses(server_id).body['floating_ips'])
end end
def get(address_id) def get(address_id)

View file

@ -16,10 +16,27 @@ module Fog
end end
class Mock class Mock
def allocate_address
response = Excon::Response.new
response.status = 200
end response.headers = {
end "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
end "Content-Type" => "application/json",
"Content-Length" => "105",
"Date"=> Date.new
}
response.body = {
"floating_ip" => {
"instance_id" => nil,
"ip" => "192.168.27.132",
"fixed_ip" => nil,
"id" => 4,
"pool"=>"nova"
}
}
response
end
end # mock
end # openstack
end #compute
end end

View file

@ -20,9 +20,16 @@ module Fog
end end
class Mock class Mock
def disassociate_address(server_id, ip_address)
response = Excon::Response.new
response.status = 202
response.headers = {
"Content-Type" => "text/html, charset=UTF-8",
"Content-Length" => "0",
"Date"=> Date.new
}
response
end
end end
end end
end end

View file

@ -15,10 +15,27 @@ module Fog
end end
class Mock class Mock
def get_address(address_id)
response = Excon::Response.new
response.status = 200
end response.headers = {
end "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
end "Content-Type" => "application/json",
end "Content-Length" => "105",
"Date"=> Date.new
}
response.body = {
"floating_ip" => {
"instance_id" => nil,
"ip" => "192.168.27.129",
"fixed_ip" => nil,
"id" => 1,
"pool" => "nova"
}
}
response
end
end # mock
end # openstack
end # compute
end # fog

View file

@ -15,9 +15,50 @@ module Fog
end end
class Mock class Mock
def list_all_addresses(server_id)
response = Excon::Response.new
end response.status = 200
end response.headers = {
end "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
end "Content-Type" => "application/json",
"Content-Length" => "378",
"Date"=> Date.new
}
response.body = {
"floating_ips" => [
{
"instance_id" => nil,
"ip" => "192.168.27.129",
"fixed_ip" => nil,
"id" => 1,
"pool" => "nova"
},
{
"instance_id" => nil,
"ip" => "192.168.27.130",
"fixed_ip" => nil,
"id" => 2,
"pool" => "nova"
},
{
"instance_id" => nil,
"ip" => "192.168.27.131",
"fixed_ip" => nil,
"id" => 3,
"pool" => "nova"
},
{
"instance_id" => nil,
"ip" => "192.168.27.132",
"fixed_ip" => nil,
"id" => 4,
"pool" => "nova"
}
]
}
response
end
end # mock
end # openstack
end # Compute
end # fog

View file

@ -0,0 +1,27 @@
Shindo.tests('Fog::Compute[:openstack] | address requests', ['openstack']) do
@address_format = {
"instance_id" => NilClass,
"ip" => String,
"fixed_ip" => NilClass,
"id" => Integer,
"pool" => String
}
tests('success') do
tests('#allocate_address').formats({"floating_ip" => @address_format}) do
Fog::Compute[:openstack].allocate_address.body
end
tests('#list_all_addresses(server_id)').formats({"floating_ips" => [@address_format]}) do
Fog::Compute[:openstack].list_all_addresses("sd34234dvsdasdmlk123cdslfck1").body
end
tests('#get_address(address_id)').formats({"floating_ip" => @address_format}) do
Fog::Compute[:openstack].get_address(1).body
end
tests('#disassociate_address(server_id, ip_address)').succeeds do
Fog::Compute[:openstack].disassociate_address("sd34234dvsdasdmlk123cdslfck1", "192.168.27.129").body
end
end
end