Enhancement: EC2 added create route with networkInterfaceId (#3063)

* Enhancement:EC2- create route with network interfcaeID

* modifying existing test case

* Linting

Co-authored-by: usmankb <usman@krazybee.com>
Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
usmangani1 2020-06-12 20:46:55 +05:30 committed by GitHub
parent 80a3571ff4
commit 475f022b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 15 deletions

View File

@ -3639,12 +3639,16 @@ class RouteBackend(object):
interface_id=None,
vpc_peering_connection_id=None,
):
gateway = None
nat_gateway = None
route_table = self.get_route_table(route_table_id)
if interface_id:
self.raise_not_implemented_error("CreateRoute to NetworkInterfaceId")
# for validating interface Id whether it is valid or not.
self.get_network_interface(interface_id)
gateway = None
else:
if gateway_id:
if EC2_RESOURCE_TO_PREFIX["vpn-gateway"] in gateway_id:
gateway = self.get_vpn_gateway(gateway_id)
@ -3652,11 +3656,12 @@ class RouteBackend(object):
gateway = self.get_internet_gateway(gateway_id)
try:
ipaddress.IPv4Network(six.text_type(destination_cidr_block), strict=False)
ipaddress.IPv4Network(
six.text_type(destination_cidr_block), strict=False
)
except ValueError:
raise InvalidDestinationCIDRBlockParameterError(destination_cidr_block)
nat_gateway = None
if nat_gateway_id is not None:
nat_gateway = self.nat_gateways.get(nat_gateway_id)

View File

@ -462,7 +462,7 @@ def test_routes_not_supported():
# Create
conn.create_route.when.called_with(
main_route_table.id, ROUTE_CIDR, interface_id="eni-1234abcd"
).should.throw(NotImplementedError)
).should.throw("InvalidNetworkInterfaceID.NotFound")
# Replace
igw = conn.create_internet_gateway()
@ -583,6 +583,32 @@ def test_create_route_with_invalid_destination_cidr_block_parameter():
)
@mock_ec2
def test_create_route_with_network_interface_id():
ec2 = boto3.resource("ec2", region_name="us-west-2")
ec2_client = boto3.client("ec2", region_name="us-west-2")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock="10.0.0.0/24", AvailabilityZone="us-west-2a"
)
route_table = ec2_client.create_route_table(VpcId=vpc.id)
route_table_id = route_table["RouteTable"]["RouteTableId"]
eni1 = ec2_client.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress="10.0.10.5"
)
route = ec2_client.create_route(
NetworkInterfaceId=eni1["NetworkInterface"]["NetworkInterfaceId"],
RouteTableId=route_table_id,
)
route["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
@mock_ec2
def test_describe_route_tables_with_nat_gateway():
ec2 = boto3.client("ec2", region_name="us-west-1")