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:
parent
151a8ad04a
commit
e3aa031a9f
2 changed files with 32 additions and 28 deletions
|
@ -22,7 +22,9 @@ module Fog
|
||||||
# * 'return'<~Boolean> - Returns true if the request succeeds. Otherwise, returns an error.
|
# * '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]
|
# {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({
|
request({
|
||||||
'Action' => 'ReplaceRoute',
|
'Action' => 'ReplaceRoute',
|
||||||
'RouteTableId' => route_table_id,
|
'RouteTableId' => route_table_id,
|
||||||
|
@ -35,10 +37,12 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def replace_route(route_table_id, options = {})
|
def replace_route(route_table_id, destination_cidr_block, options = {})
|
||||||
options['instanceOwnerId'] = nil
|
options['instanceOwnerId'] = nil
|
||||||
|
options['DestinationCidrBlock'] = destination_cidr_block
|
||||||
|
|
||||||
route_table = self.data[:route_tables].find { |routetable| routetable["routeTableId"].eql? route_table_id }
|
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? || !options['instanceId'].nil? || !options['networkInterfaceId'].nil?
|
||||||
if !options['gatewayId'].nil? && self.internet_gateways.all('internet-gateway-id'=>options['gatewayId']).first.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")
|
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")
|
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?
|
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")
|
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?
|
elsif route_table['routeSet'].find { |route| route['destinationCidrBlock'].eql? destination_cidr_block }.nil?
|
||||||
raise Fog::Compute::AWS::Error, "RouteAlreadyExists => The route identified by #{options['destinationCidrBlock']} doesn't exist."
|
raise Fog::Compute::AWS::Error, "RouteAlreadyExists => The route identified by #{destination_cidr_block} doesn't exist."
|
||||||
else
|
else
|
||||||
response = Excon::Response.new
|
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.merge!(options)
|
||||||
route_set['state'] = 'pending'
|
route_set['state'] = 'pending'
|
||||||
route_set['origin'] = 'ReplaceRoute'
|
route_set['origin'] = 'ReplaceRoute'
|
||||||
|
@ -69,7 +73,7 @@ module Fog
|
||||||
end
|
end
|
||||||
elsif route_table.nil?
|
elsif route_table.nil?
|
||||||
raise Fog::Compute::AWS::NotFound.new("The routeTable ID '#{route_table_id}' does not exist")
|
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.")
|
raise Fog::Compute::AWS::InvalidParameterValue.new("Value () for parameter destinationCidrBlock is invalid. This is not a valid CIDR block.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,18 +98,18 @@ Shindo.tests('Fog::Compute[:aws] | route table requests', ['aws']) do
|
||||||
# - using network interface
|
# - using network interface
|
||||||
#
|
#
|
||||||
Fog::Compute[:aws].attach_internet_gateway(@alt_internet_gateway_id, vpc.id).body
|
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
|
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, {'destinationCidrBlock' => @destination_cidr_block, 'gatewayId' => @alt_internet_gateway_id}).body
|
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => @alt_internet_gateway_id}).body
|
||||||
end
|
end
|
||||||
|
|
||||||
instance = Fog::Compute[:aws].servers.create(:image_id => @ami, :flavor_id => 't1.micro', :key_name => 'fog-test-key', :subnet_id => @subnet_id)
|
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" }
|
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
|
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, {'destinationCidrBlock' => '10.0.10.0/22', 'instanceId' => instance.id}).body
|
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/22', {'instanceId' => instance.id}).body
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '10.0.10.0/21', 'networkInterfaceId' => '#{@network_interface_id}'})").formats(AWS::Compute::Formats::BASIC) do
|
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, {'destinationCidrBlock' => '10.0.10.0/21', 'networkInterfaceId' => @network_interface_id}).body
|
Fog::Compute[:aws].replace_route(@route_table_id, '10.0.10.0/21', {'networkInterfaceId' => @network_interface_id}).body
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tests describe_route_tables
|
# Tests describe_route_tables
|
||||||
|
@ -246,30 +246,30 @@ Shindo.tests('Fog::Compute[:aws] | route table requests', ['aws']) do
|
||||||
tests('#replace_route').raises(ArgumentError) do
|
tests('#replace_route').raises(ArgumentError) do
|
||||||
Fog::Compute[:aws].replace_route
|
Fog::Compute[:aws].replace_route
|
||||||
end
|
end
|
||||||
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'internetGatewayId' => '#{@internet_gateway_id}'})").raises(Fog::Compute::AWS::NotFound) do
|
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', {'destinationCidrBlock' => @destination_cidr_block, 'internetGatewayId' => @internet_gateway_id})
|
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'internetGatewayId' => @internet_gateway_id})
|
||||||
end
|
end
|
||||||
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}'})").raises(Fog::Compute::AWS::NotFound) do
|
tests("#replace_route('rtb-00000000', '#{@destination_cidr_block}')").raises(Fog::Compute::AWS::NotFound) do
|
||||||
Fog::Compute[:aws].replace_route('rtb-00000000', {'destinationCidrBlock' => @destination_cidr_block})
|
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block)
|
||||||
end
|
end
|
||||||
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'gatewayId' => 'igw-00000000'})").raises(Fog::Compute::AWS::NotFound) do
|
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, {'destinationCidrBlock' => @destination_cidr_block, 'gatewayId' => 'igw-00000000'})
|
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'gatewayId' => 'igw-00000000'})
|
||||||
end
|
end
|
||||||
tests("#replace_route('rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'instanceId' => '#{instance.id}'})").raises(Fog::Compute::AWS::NotFound) do
|
tests("#replace_route('rtb-00000000', '#{@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})
|
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'instanceId' => instance.id})
|
||||||
end
|
end
|
||||||
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'instanceId' => 'i-00000000'})").raises(Fog::Compute::AWS::NotFound) do
|
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, {'destinationCidrBlock' => @destination_cidr_block, 'instanceId' => 'i-00000000'})
|
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'instanceId' => 'i-00000000'})
|
||||||
end
|
end
|
||||||
tests("#replace_route('#{@route_table_id}', {'destinationCidrBlock' => '#{@destinationCidrBlock}', 'networkInterfaceId' => 'eni-00000000'})").raises(Fog::Compute::AWS::NotFound) do
|
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, {'destinationCidrBlock' => @destination_cidr_block, 'networkInterfaceId' => 'eni-00000000'})
|
Fog::Compute[:aws].replace_route(@route_table_id, @destination_cidr_block, {'networkInterfaceId' => 'eni-00000000'})
|
||||||
end
|
end
|
||||||
tests("#replace_route('#rtb-00000000', {'destinationCidrBlock' => '#{@destination_cidr_block}', 'networkInterfaceId' => '#{@network_interface_id}'})").raises(Fog::Compute::AWS::NotFound) do
|
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', {'destinationCidrBlock' => @destination_cidr_block, 'networkInterfaceId' => @network_interface_id})
|
Fog::Compute[:aws].replace_route('rtb-00000000', @destination_cidr_block, {'networkInterfaceId' => @network_interface_id})
|
||||||
end
|
end
|
||||||
if !Fog.mocking?
|
if !Fog.mocking?
|
||||||
tests("#replace_route less specific destination_cidr_block").raises(Fog::Compute::AWS::Error) do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue