From f2b83182117d11b687c90d4a7c3e262538bd0f15 Mon Sep 17 00:00:00 2001 From: Macwan Nevil Date: Thu, 12 Aug 2021 01:53:04 +0530 Subject: [PATCH] fixed owner id and delete rt (#4161) --- moto/ec2/models.py | 15 ++++++++++++--- moto/ec2/responses/route_tables.py | 18 +++++++++++++++--- tests/terraform-tests.success.txt | 8 ++++++++ tests/test_ec2/test_route_tables.py | 1 + 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 9f341f13c..518af809e 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -4375,6 +4375,10 @@ class VPCEndPoint(TaggedEC2Resource): self.dns_entries = dns_entries self.add_tags(tags or {}) + @property + def owner_id(self): + return ACCOUNT_ID + @property def created_at(self): return iso_8601_datetime_with_milliseconds(self._created_at) @@ -4476,12 +4480,17 @@ class RouteBackend(object): route_table = self.get_route_table(route_table_id) return route_table.get(route_id) - def delete_route(self, route_table_id, destination_cidr_block): + def delete_route( + self, route_table_id, destination_cidr_block, destination_ipv6_cidr_block=None + ): + cidr = destination_cidr_block route_table = self.get_route_table(route_table_id) - route_id = generate_route_id(route_table_id, destination_cidr_block) + if destination_ipv6_cidr_block: + cidr = destination_ipv6_cidr_block + route_id = generate_route_id(route_table_id, cidr) deleted = route_table.routes.pop(route_id, None) if not deleted: - raise InvalidRouteError(route_table_id, destination_cidr_block) + raise InvalidRouteError(route_table_id, cidr) return deleted diff --git a/moto/ec2/responses/route_tables.py b/moto/ec2/responses/route_tables.py index af515236f..8944e9d34 100644 --- a/moto/ec2/responses/route_tables.py +++ b/moto/ec2/responses/route_tables.py @@ -50,7 +50,10 @@ class RouteTables(BaseResponse): def delete_route(self): route_table_id = self._get_param("RouteTableId") destination_cidr_block = self._get_param("DestinationCidrBlock") - self.ec2_backend.delete_route(route_table_id, destination_cidr_block) + destination_ipv6_cidr_block = self._get_param("DestinationIpv6CidrBlock") + self.ec2_backend.delete_route( + route_table_id, destination_cidr_block, destination_ipv6_cidr_block + ) template = self.response_template(DELETE_ROUTE_RESPONSE) return template.render() @@ -128,7 +131,11 @@ CREATE_ROUTE_TABLE_RESPONSE = """ {% for route in route_table.routes.values() %} {% if route.local %} - {{ route.destination_cidr_block }} + {% if route.destination_ipv6_cidr_block %} + {{ route.destination_ipv6_cidr_block }} + {% else %} + {{ route.destination_cidr_block }} + {% endif %} local active @@ -158,10 +165,15 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """ {{ route_table.id }} {{ route_table.vpc_id }} - + {{ route_table.owner_id }} + {% for route in route_table.routes.values() %} + {% if route.destination_ipv6_cidr_block %} + {{ route.destination_ipv6_cidr_block }} + {% else %} {{ route.destination_cidr_block }} + {% endif %} {% if route.local %} local CreateRouteTable diff --git a/tests/terraform-tests.success.txt b/tests/terraform-tests.success.txt index 3b2784adc..cb6445899 100644 --- a/tests/terraform-tests.success.txt +++ b/tests/terraform-tests.success.txt @@ -73,3 +73,11 @@ TestAccAWSUserPolicyAttachment TestAccAWSUserSSHKey TestAccAWSVpc_ TestAccAWSRouteTable_disappears +TestAccAWSRouteTable_RequireRouteTarget +TestAccAWSRouteTable_Route_ConfigMode +TestAccAWSRouteTable_tags +TestAccAWSRouteTable_vgwRoutePropagation +TestAccAWSRouteTable_RequireRouteTarget +TestAccAWSRouteTable_disappears_SubnetAssociation +TestAccAWSRouteTable_disappears +TestAccAWSRouteTable_basic \ No newline at end of file diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index f981ea224..1ec4fcf6a 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -588,6 +588,7 @@ def test_create_route_with_invalid_destination_cidr_block_parameter(): route for route in route_table.routes if route.destination_cidr_block != vpc.cidr_block + or route.destination_ipv6_cidr_block != vpc.cidr_block ] new_routes.should.have.length_of(1) new_routes[0].route_table_id.shouldnt.be.equal(None)