EC2 - search_transit_gateway_routes -search by CIDR (#5020)

This commit is contained in:
Bert Blommers 2022-04-11 19:43:33 +00:00 committed by GitHub
parent f8f6f6f1ee
commit 48e3cbec99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -138,13 +138,20 @@ class TransitGatewayRouteTableBackend(object):
def search_transit_gateway_routes(
self, transit_gateway_route_table_id, filters, max_results=None
):
"""
The following filters are currently supported: type, state, route-search.exact-match
"""
transit_gateway_route_table = self.transit_gateways_route_tables.get(
transit_gateway_route_table_id
)
if not transit_gateway_route_table:
return []
attr_pairs = (("type", "type"), ("state", "state"))
attr_pairs = (
("type", "type"),
("state", "state"),
("route-search.exact-match", "destinationCidrBlock"),
)
routes = transit_gateway_route_table.routes.copy()
for key in transit_gateway_route_table.routes:

View File

@ -446,6 +446,43 @@ def test_search_transit_gateway_routes_by_state():
routes.should.equal([])
@mock_ec2
def test_search_transit_gateway_routes_by_routesearch():
client = boto3.client("ec2", region_name="us-west-2")
vpc = client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"]
subnet = client.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")["Subnet"]
tgw = client.create_transit_gateway(Description="description")
tgw_id = tgw["TransitGateway"]["TransitGatewayId"]
route_table = client.create_transit_gateway_route_table(TransitGatewayId=tgw_id)
transit_gateway_route_id = route_table["TransitGatewayRouteTable"][
"TransitGatewayRouteTableId"
]
attachment = client.create_transit_gateway_vpc_attachment(
TransitGatewayId=tgw_id, VpcId=vpc["VpcId"], SubnetIds=[subnet["SubnetId"]]
)
transit_gateway_attachment_id = attachment["TransitGatewayVpcAttachment"][
"TransitGatewayAttachmentId"
]
exported_cidr_ranges = ["172.17.0.0/24", "192.160.0.0/24"]
for route in exported_cidr_ranges:
client.create_transit_gateway_route(
DestinationCidrBlock=route,
TransitGatewayRouteTableId=transit_gateway_route_id,
TransitGatewayAttachmentId=transit_gateway_attachment_id,
)
for route in exported_cidr_ranges:
expected_route = client.search_transit_gateway_routes(
TransitGatewayRouteTableId=transit_gateway_route_id,
Filters=[{"Name": "route-search.exact-match", "Values": [route]}],
)
expected_route["Routes"][0]["DestinationCidrBlock"].should.equal(route)
@mock_ec2
def test_delete_transit_gateway_route():
ec2 = boto3.client("ec2", region_name="us-west-1")