mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #131 from engineyard/fix-address-limit-error
raise correct error when exceeding address limit
This commit is contained in:
commit
22a6deb3e6
2 changed files with 55 additions and 40 deletions
|
@ -27,27 +27,29 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def allocate_address(domain = 'standard')
|
||||
domain = domain == 'vpc' ? 'vpc' : 'standard'
|
||||
response = Excon::Response.new
|
||||
if describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses]
|
||||
response.status = 200
|
||||
public_ip = Fog::AWS::Mock.ip_address
|
||||
data = {
|
||||
'instanceId' => nil,
|
||||
'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 = data.reject {|k, v| k == 'instanceId' }.merge('requestId' => Fog::AWS::Mock.request_id)
|
||||
response
|
||||
else
|
||||
response.status = 400
|
||||
response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>AddressLimitExceeded</Code><Message>Too many addresses allocated</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestID></Response>"
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
unless describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses]
|
||||
raise Fog::Compute::AWS::Error, "AddressLimitExceeded => Too many addresses allocated"
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
domain = domain == 'vpc' ? 'vpc' : 'standard'
|
||||
public_ip = Fog::AWS::Mock.ip_address
|
||||
|
||||
data = {
|
||||
'instanceId' => nil,
|
||||
'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 = data.reject {|k, v| k == 'instanceId' }.merge('requestId' => Fog::AWS::Mock.request_id)
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
||||
compute = Fog::Compute[:aws]
|
||||
|
||||
@addresses_format = {
|
||||
'addressesSet' => [{
|
||||
|
@ -10,7 +11,7 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
}],
|
||||
'requestId' => String
|
||||
}
|
||||
@server = Fog::Compute[:aws].servers.create
|
||||
@server = compute.servers.create
|
||||
@server.wait_for { ready? }
|
||||
@ip_address = @server.public_ip_address
|
||||
|
||||
|
@ -21,81 +22,93 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
|
|||
@vpc_allocation_id = nil
|
||||
|
||||
tests('#allocate_address').formats({'domain' => String, 'publicIp' => String, 'requestId' => String}) do
|
||||
data = Fog::Compute[:aws].allocate_address.body
|
||||
data = compute.allocate_address.body
|
||||
@public_ip = data['publicIp']
|
||||
data
|
||||
end
|
||||
|
||||
tests("#allocate_address('vpc')").formats({'domain' => String, 'publicIp' => String, 'allocationId' => String, 'requestId' => String}) do
|
||||
data = Fog::Compute[:aws].allocate_address('vpc').body
|
||||
data = compute.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
|
||||
compute.describe_addresses.body
|
||||
end
|
||||
|
||||
tests("#describe_addresses('public-ip' => #{@public_ip}')").formats(@addresses_format) do
|
||||
Fog::Compute[:aws].describe_addresses('public-ip' => @public_ip).body
|
||||
compute.describe_addresses('public-ip' => @public_ip).body
|
||||
end
|
||||
|
||||
tests("#associate_addresses('#{@server.identity}', '#{@public_ip}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].associate_address(@server.identity, @public_ip).body
|
||||
compute.associate_address(@server.identity, @public_ip).body
|
||||
end
|
||||
|
||||
tests("#associate_addresses({:instance_id=>'#{@server.identity}', :public_ip=>'#{@public_ip}'})").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].associate_address({:instance_id=>@server.identity,:public_ip=> @public_ip}).body
|
||||
compute.associate_address({:instance_id=>@server.identity,:public_ip=> @public_ip}).body
|
||||
end
|
||||
|
||||
tests("#dissassociate_address('#{@public_ip}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].disassociate_address(@public_ip).body
|
||||
compute.disassociate_address(@public_ip).body
|
||||
end
|
||||
|
||||
tests("#associate_addresses('#{@server.id}', nil, nil, '#{@vpc_allocation_id}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].associate_address(@server.id, nil, nil, @vpc_allocation_id).body
|
||||
compute.associate_address(@server.id, nil, nil, @vpc_allocation_id).body
|
||||
end
|
||||
|
||||
tests("#associate_addresses({:instance_id=>'#{@server.id}', :allocation_id=>'#{@vpc_allocation_id}'})").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].associate_address({:instance_id=>@server.id, :allocation_id=>@vpc_allocation_id}).body
|
||||
compute.associate_address({:instance_id=>@server.id, :allocation_id=>@vpc_allocation_id}).body
|
||||
end
|
||||
|
||||
tests("#release_address('#{@public_ip}')").formats(AWS::Compute::Formats::BASIC) do
|
||||
Fog::Compute[:aws].release_address(@public_ip).body
|
||||
compute.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
|
||||
compute.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')
|
||||
@address = compute.addresses.create
|
||||
@vpc_address = compute.addresses.create(:domain => 'vpc')
|
||||
|
||||
tests("#associate_addresses({:instance_id =>'i-00000000', :public_ip => '#{@address.identity}')}").raises(Fog::Compute::AWS::NotFound) do
|
||||
Fog::Compute[:aws].associate_address({:instance_id => 'i-00000000', :public_ip => @address.identity})
|
||||
compute.associate_address({:instance_id => 'i-00000000', :public_ip => @address.identity})
|
||||
end
|
||||
|
||||
tests("#associate_addresses({:instance_id =>'#{@server.identity}', :public_ip => '127.0.0.1'})").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].associate_address({:instance_id => @server.identity, :public_ip => '127.0.0.1'})
|
||||
compute.associate_address({:instance_id => @server.identity, :public_ip => '127.0.0.1'})
|
||||
end
|
||||
|
||||
tests("#associate_addresses({:instance_id =>'i-00000000', :public_ip => '127.0.0.1'})").raises(Fog::Compute::AWS::NotFound) do
|
||||
Fog::Compute[:aws].associate_address({:instance_id =>'i-00000000', :public_ip =>'127.0.0.1'})
|
||||
compute.associate_address({:instance_id =>'i-00000000', :public_ip =>'127.0.0.1'})
|
||||
end
|
||||
|
||||
tests("#disassociate_addresses('127.0.0.1') raises BadRequest error").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].disassociate_address('127.0.0.1')
|
||||
compute.disassociate_address('127.0.0.1')
|
||||
end
|
||||
|
||||
tests("#release_address('127.0.0.1')").raises(Fog::Compute::AWS::Error) do
|
||||
Fog::Compute[:aws].release_address('127.0.0.1')
|
||||
compute.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)
|
||||
compute.release_address(@vpc_address.identity)
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
old_limit = compute.data[:limits][:addresses]
|
||||
|
||||
tests("#allocate_address", "limit exceeded").raises(Fog::Compute::AWS::Error) do
|
||||
compute.data[:limits][:addresses] = 0
|
||||
compute.allocate_address
|
||||
end
|
||||
|
||||
compute.data[:limits][:addresses] = old_limit
|
||||
end
|
||||
|
||||
@address.destroy
|
||||
|
|
Loading…
Add table
Reference in a new issue