mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] Address#destroy handles VPC addresses, improve address allocate/release mocking for VPC.
This commit is contained in:
parent
e026c2e3de
commit
f325cbc61b
5 changed files with 39 additions and 13 deletions
|
@ -22,7 +22,7 @@ module Fog
|
|||
def destroy
|
||||
requires :public_ip
|
||||
|
||||
connection.release_address(public_ip)
|
||||
connection.release_address(allocation_id || public_ip)
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ module Fog
|
|||
disassociate
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def server
|
||||
connection.servers.get(server_id)
|
||||
end
|
||||
|
|
|
@ -40,12 +40,11 @@ module Fog
|
|||
'publicIp' => public_ip,
|
||||
'domain' => domain
|
||||
}
|
||||
if domain == 'vpc'
|
||||
data['allocationId'] = "eipalloc-#{Fog::Mock.random_hex(8)}"
|
||||
end
|
||||
self.data[:addresses][public_ip] = data
|
||||
response.body = {
|
||||
'domain' => domain,
|
||||
'publicIp' => public_ip,
|
||||
'requestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response.body = data.reject {|k, v| k == 'instanceId' }.merge('requestId' => Fog::AWS::Mock.request_id)
|
||||
response
|
||||
else
|
||||
response.status = 400
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
# * 'return'<~Boolean> - success?
|
||||
#
|
||||
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ReleaseAddress.html]
|
||||
#
|
||||
#
|
||||
# non-VPC: requires public_ip only
|
||||
# VPC: requires allocation_id only
|
||||
def release_address(ip_or_allocation)
|
||||
|
@ -35,9 +35,17 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def release_address(public_ip)
|
||||
def release_address(public_ip_or_allocation_id)
|
||||
response = Excon::Response.new
|
||||
if (address = self.data[:addresses].delete(public_ip))
|
||||
|
||||
address = self.data[:addresses][public_ip_or_allocation_id] || self.data[:addresses].values.detect {|a| a['allocationId'] == public_ip_or_allocation_id }
|
||||
|
||||
if address
|
||||
if address['allocationId'] && public_ip_or_allocation_id == address['publicIp']
|
||||
raise Fog::Compute::AWS::Error, "InvalidParameterValue => You must specify an allocation id when releasing a VPC elastic IP address"
|
||||
end
|
||||
|
||||
self.data[:addresses].delete(address['publicIp'])
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
|
@ -45,7 +53,7 @@ module Fog
|
|||
}
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::AWS::Error.new("AuthFailure => The address '#{public_ip}' does not belong to you.")
|
||||
raise Fog::Compute::AWS::Error.new("AuthFailure => The address '#{public_ip_or_allocation_id}' does not belong to you.")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,9 +15,10 @@ Shindo.tests("Fog::Compute[:aws] | address", ['aws']) do
|
|||
@instance.server.public_ip_address == @instance.public_ip
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@server.destroy
|
||||
|
||||
end
|
||||
|
||||
model_tests(Fog::Compute[:aws].addresses, { :domain => "vpc" }, true)
|
||||
end
|
||||
|
|
|
@ -17,6 +17,8 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
tests('success') do
|
||||
|
||||
@public_ip = nil
|
||||
@vpc_public_ip = nil
|
||||
@vpc_allocation_id = nil
|
||||
|
||||
tests('#allocate_address').formats({'domain' => String, 'publicIp' => String, 'requestId' => String}) do
|
||||
data = Fog::Compute[:aws].allocate_address.body
|
||||
|
@ -24,6 +26,13 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
data
|
||||
end
|
||||
|
||||
tests("#allocate_address('vpc')").formats({'domain' => String, 'publicIp' => String, 'allocationId' => String, 'requestId' => String}) do
|
||||
data = Fog::Compute[:aws].allocate_address('vpc').body
|
||||
@vpc_public_ip = data['publicIp']
|
||||
@vpc_allocation_id = data['allocationId']
|
||||
data
|
||||
end
|
||||
|
||||
tests('#describe_addresses').formats(@addresses_format) do
|
||||
Fog::Compute[:aws].describe_addresses.body
|
||||
end
|
||||
|
@ -35,7 +44,7 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
tests("#associate_addresses('#{@server.identity}', '#{@public_ip}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].associate_address(@server.identity, @public_ip).body
|
||||
end
|
||||
|
||||
|
||||
tests("#dissassociate_address('#{@public_ip}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].disassociate_address(@public_ip).body
|
||||
end
|
||||
|
@ -44,10 +53,14 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
Fog::Compute[:aws].release_address(@public_ip).body
|
||||
end
|
||||
|
||||
tests("#release_address('#{@vpc_allocation_id}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].release_address(@vpc_allocation_id).body
|
||||
end
|
||||
end
|
||||
tests('failure') do
|
||||
|
||||
@address = Fog::Compute[:aws].addresses.create
|
||||
@vpc_address = Fog::Compute[:aws].addresses.create(:domain => 'vpc')
|
||||
|
||||
tests("#associate_addresses('i-00000000', '#{@address.identity}')").raises(Fog::Compute::AWS::NotFound) do
|
||||
Fog::Compute[:aws].associate_address('i-00000000', @address.identity)
|
||||
|
@ -69,7 +82,12 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
Fog::Compute[:aws].release_address('127.0.0.1')
|
||||
end
|
||||
|
||||
tests("#release_address('#{@vpc_address.identity}')").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].release_address(@vpc_address.identity)
|
||||
end
|
||||
|
||||
@address.destroy
|
||||
@vpc_address.destroy
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue