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:
parent
e99450ec1f
commit
62e73549e6
6 changed files with 133 additions and 24 deletions
|
@ -9,8 +9,8 @@ module Fog
|
|||
|
||||
model Fog::Compute::OpenStack::Address
|
||||
|
||||
def all
|
||||
load(connection.list_addresses.body['floating_ips'])
|
||||
def all(server_id)
|
||||
load(connection.list_all_addresses(server_id).body['floating_ips'])
|
||||
end
|
||||
|
||||
def get(address_id)
|
||||
|
|
|
@ -16,10 +16,27 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
def allocate_address
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
|
||||
"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
|
||||
|
|
|
@ -20,9 +20,16 @@ module Fog
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -15,10 +15,27 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_address(address_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
|
||||
"Content-Type" => "application/json",
|
||||
"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
|
||||
|
|
|
@ -15,9 +15,50 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def list_all_addresses(server_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.headers = {
|
||||
"X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26",
|
||||
"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
|
||||
|
|
27
tests/openstack/requests/compute/address_tests.rb
Normal file
27
tests/openstack/requests/compute/address_tests.rb
Normal 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
|
Loading…
Add table
Reference in a new issue