Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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.
  • Loading branch information...
commit 62e73549e67448399dc1fb1fcb3538a3777e15ee 1 parent e99450e
Alfonso Juan Dillera authored Keoven committed
View
4 lib/fog/openstack/models/compute/addresses.rb
@@ -9,8 +9,8 @@ class Addresses < Fog::Collection
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)
View
29 lib/fog/openstack/requests/compute/allocate_address.rb
@@ -16,10 +16,27 @@ def allocate_address
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
View
13 lib/fog/openstack/requests/compute/disassociate_address.rb
@@ -20,9 +20,16 @@ def disassociate_address(server_id, ip_address)
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
View
31 lib/fog/openstack/requests/compute/get_address.rb
@@ -15,10 +15,27 @@ def get_address(address_id)
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
View
53 lib/fog/openstack/requests/compute/list_all_addresses.rb
@@ -15,9 +15,50 @@ def list_all_addresses(server_id)
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
View
27 tests/openstack/requests/compute/address_tests.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.