EC2: create_route() should allow overlapping CIDR's (#6106)

This commit is contained in:
Bert Blommers 2023-03-22 13:07:58 -01:00 committed by GitHub
parent 681db433fd
commit 53603b01c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -514,7 +514,7 @@ class RouteBackend:
for route in route_table.routes.values():
if not route.destination_cidr_block:
continue
if not route.local and ip_v4_network.overlaps(
ipaddress.IPv4Network(str(route.destination_cidr_block))
if not route.local and ip_v4_network == ipaddress.IPv4Network(
str(route.destination_cidr_block)
):
raise RouteAlreadyExistsError(destination_cidr_block)

View File

@ -664,16 +664,18 @@ def test_routes_already_exist():
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("RouteAlreadyExists")
with pytest.raises(ClientError) as ex:
# We can create a sub cidr
client.create_route(
RouteTableId=main_route_table.id,
DestinationCidrBlock=ROUTE_SUB_CIDR,
GatewayId=igw.id,
)
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["ResponseMetadata"].should.have.key("RequestId")
ex.value.response["Error"]["Code"].should.equal("RouteAlreadyExists")
# Or even a catch-all
client.create_route(
RouteTableId=main_route_table.id,
DestinationCidrBlock="0.0.0.0/0",
GatewayId=igw.id,
)
@mock_ec2