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

making destination_cidr_block a required parameter for replace_route

This commit is contained in:
Eric Herot 2014-02-06 15:04:08 -05:00
parent 151a8ad04a
commit e3aa031a9f
2 changed files with 32 additions and 28 deletions

View file

@ -22,7 +22,9 @@ module Fog
# * 'return'<~Boolean> - Returns true if the request succeeds. Otherwise, returns an error.
#
# {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ReplaceRoute.html]
def replace_route(route_table_id, options = {})
def replace_route(route_table_id, destination_cidr_block, options = {})
options['DestinationCidrBlock'] = destination_cidr_block
request({
'Action' => 'ReplaceRoute',
'RouteTableId' => route_table_id,
@ -35,10 +37,12 @@ module Fog
class Mock
def replace_route(route_table_id, options = {})
def replace_route(route_table_id, destination_cidr_block, options = {})
options['instanceOwnerId'] = nil
options['DestinationCidrBlock'] = destination_cidr_block
route_table = self.data[:route_tables].find { |routetable| routetable["routeTableId"].eql? route_table_id }
if !route_table.nil? && options['destinationCidrBlock']
if !route_table.nil? && destination_cidr_block
if !options['gatewayId'].nil? || !options['instanceId'].nil? || !options['networkInterfaceId'].nil?
if !options['gatewayId'].nil? && self.internet_gateways.all('internet-gateway-id'=>options['gatewayId']).first.nil?
raise Fog::Compute::AWS::NotFound.new("The gateway ID '#{options['gatewayId']}' does not exist")
@ -46,11 +50,11 @@ module Fog
raise Fog::Compute::AWS::NotFound.new("The instance ID '#{options['instanceId']}' does not exist")
elsif !options['networkInterfaceId'].nil? && self.network_interfaces.all('networkInterfaceId'=>options['networkInterfaceId']).first.nil?
raise Fog::Compute::AWS::NotFound.new("The networkInterface ID '#{options['networkInterfaceId']}' does not exist")
elsif route_table['routeSet'].find { |route| route['destinationCidrBlock'].eql? options['destinationCidrBlock'] }.nil?
raise Fog::Compute::AWS::Error, "RouteAlreadyExists => The route identified by #{options['destinationCidrBlock']} doesn't exist."
elsif route_table['routeSet'].find { |route| route['destinationCidrBlock'].eql? destination_cidr_block }.nil?
raise Fog::Compute::AWS::Error, "RouteAlreadyExists => The route identified by #{destination_cidr_block} doesn't exist."
else
response = Excon::Response.new
route_set = route_table['routeSet'].find { |routeset| routeset['destinationCidrBlock'].eql? options['destinationCidrBlock'] }
route_set = route_table['routeSet'].find { |routeset| routeset['destinationCidrBlock'].eql? destination_cidr_block }
route_set.merge!(options)
route_set['state'] = 'pending'
route_set['origin'] = 'ReplaceRoute'
@ -69,7 +73,7 @@ module Fog
end
elsif route_table.nil?
raise Fog::Compute::AWS::NotFound.new("The routeTable ID '#{route_table_id}' does not exist")
elsif options['destinationCidrBlock'].empty?
elsif destination_cidr_block.empty?
raise Fog::Compute::AWS::InvalidParameterValue.new("Value () for parameter destinationCidrBlock is invalid. This is not a valid CIDR block.")
end
end

View file

@ -98,18 +98,18 @@ Shindo.tests('Fog::Compute[:aws] | route table requests', ['aws']) do
# - using network interface
#
Fog::Compute[:aws].attach_internet_gateway(@alt_internet_gateway_id, vpc.id).body
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'gatewayId' => '#{@alt_internet_gateway_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => @destination_cidr_block, 'gatewayId' => @alt_internet_gateway_id}).body
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'gatewayId' => '#{@alt_internet_gateway_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => @alt_internet_gateway_id}).body
end
instance = Fog::Compute[:aws].servers.create(:image_id => @ami, :flavor_id => 't1.micro', :key_name => 'fog-test-key', :subnet_id => @subnet_id)
instance.wait_for { state.eql? "running" }
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '10.0.10.0/22', 'instanceId' => '#{instance.id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => '10.0.10.0/22', 'instanceId' => instance.id}).body
tests("#replace_route('#{@route_table_id}', '10.0.10.0/22', {'instanceId' => '#{instance.id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/22', {'instanceId' => instance.id}).body
end
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '10.0.10.0/21', 'networkInterfaceId' => '#{@network_interface_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => '10.0.10.0/21', 'networkInterfaceId' => @network_interface_id}).body
tests("#replace_route('#{@route_table_id}', '10.0.10.0/21', {'networkInterfaceId' => '#{@network_interface_id}'})").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/21', {'networkInterfaceId' => @network_interface_id}).body
end
# Tests describe_route_tables
@ -246,30 +246,30 @@ Shindo.tests('Fog::Compute[:aws] | route table requests', ['aws']) do
tests('#replace_route').raises(ArgumentError) do
Fog::Compute[:aws].replace_route
end
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'internetGatewayId' => '#{@internet_gateway_id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', {'destinationCidrBlock' => @destination_cidr_block, 'internetGatewayId' => @internet_gateway_id})
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'internetGatewayId' => '#{@internet_gateway_id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'internetGatewayId' => @internet_gateway_id})
end
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', {'destinationCidrBlock' => @destination_cidr_block})
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}')").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block)
end
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'gatewayId' => 'igw-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => @destination_cidr_block, 'gatewayId' => 'igw-00000000'})
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'gatewayId' => 'igw-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => 'igw-00000000'})
end
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'instanceId' => '#{instance.id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', {'destinationCidrBlock' => @destination_cidr_block, 'instanceId' => instance.id})
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'instanceId' => '#{instance.id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'instanceId' => instance.id})
end
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'instanceId' => 'i-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => @destination_cidr_block, 'instanceId' => 'i-00000000'})
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'instanceId' => 'i-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'instanceId' => 'i-00000000'})
end
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destinationCidrBlock}', 'networkInterfaceId' => 'eni-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => @destination_cidr_block, 'networkInterfaceId' => 'eni-00000000'})
tests("#replace_route('#{@route_table_id}', '#{@destination_cidr_block}', {'networkInterfaceId' => 'eni-00000000'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'networkInterfaceId' => 'eni-00000000'})
end
tests("#replace_route('#rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'networkInterfaceId' => '#{@network_interface_id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', {'destinationCidrBlock' => @destination_cidr_block, 'networkInterfaceId' => @network_interface_id})
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}', {'networkInterfaceId' => '#{@network_interface_id}'})").raises(Fog::Compute::AWS::NotFound) do
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'networkInterfaceId' => @network_interface_id})
end
if !Fog.mocking?
tests("#replace_route less specific destination_cidr_block").raises(Fog::Compute::AWS::Error) do
Fog::Compute[:aws].replace_route(@route_table_id, {'destinationCidrBlock' => '10.0.10.0/25', 'gatewayId' => @internet_gateway_id})
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/25', {'gatewayId' => @internet_gateway_id})
end
end