Best Python code snippet using localstack_python
test_transit_gateway.py
Source:test_transit_gateway.py
...166 return att167@mock_ec2168def test_create_and_describe_transit_gateway_vpc_attachment():169 ec2 = boto3.client("ec2", region_name="us-west-1")170 response = ec2.create_transit_gateway_vpc_attachment(171 TransitGatewayId="gateway_id", VpcId="some-vpc-id", SubnetIds=["sub1"]172 )173 attachment = response["TransitGatewayVpcAttachment"]174 attachment.should.have.key("TransitGatewayAttachmentId").match("tgw-attach-*")175 attachment.should.have.key("TransitGatewayId").equal("gateway_id")176 attachment.should.have.key("VpcId").equal("some-vpc-id")177 attachment.should.have.key("VpcOwnerId").equal(ACCOUNT_ID)178 attachment.should.have.key("State").equal("available")179 attachment.should.have.key("SubnetIds").equal(["sub1"])180 attachment.should.have.key("Options").equal(181 {182 "DnsSupport": "enable",183 "Ipv6Support": "disable",184 "ApplianceModeSupport": "disable",185 }186 )187 attachment.should.have.key("Tags").equal([])188 #189 # Verify we can retrieve it as a VPC attachment190 attachments = ec2.describe_transit_gateway_vpc_attachments(191 TransitGatewayAttachmentIds=[attachment["TransitGatewayAttachmentId"]]192 )["TransitGatewayVpcAttachments"]193 attachments.should.have.length_of(1)194 attachments[0].should.have.key("CreationTime")195 del attachments[0]["CreationTime"]196 attachment.should.equal(attachments[0])197 #198 # Verify we can retrieve it as a general attachment199 attachments = ec2.describe_transit_gateway_attachments(200 TransitGatewayAttachmentIds=[attachment["TransitGatewayAttachmentId"]]201 )["TransitGatewayAttachments"]202 attachments.should.have.length_of(1)203 attachments[0].should.have.key("CreationTime")204 attachments[0].should.have.key("TransitGatewayOwnerId").equal(ACCOUNT_ID)205 attachments[0].should.have.key("ResourceOwnerId").equal(ACCOUNT_ID)206 attachments[0].should.have.key("ResourceType").equal("vpc")207 attachments[0].should.have.key("ResourceId").equal("some-vpc-id")208 attachments[0].should.have.key("State").equal("available")209 attachments[0].should.have.key("Tags").equal([])210 attachments[0].should.have.key("TransitGatewayAttachmentId").equal(211 attachment["TransitGatewayAttachmentId"]212 )213 attachments[0].should.have.key("TransitGatewayId").equal("gateway_id")214@mock_ec2215def test_describe_transit_gateway_route_tables():216 if settings.TEST_SERVER_MODE:217 raise SkipTest("ServerMode is not guaranteed to be empty")218 ec2 = boto3.client("ec2", region_name="us-west-1")219 response = ec2.describe_transit_gateway_route_tables()220 response.should.have.key("TransitGatewayRouteTables").equal([])221@mock_ec2222def test_create_transit_gateway_route_table():223 ec2 = boto3.client("ec2", region_name="us-west-1")224 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][225 "TransitGatewayId"226 ]227 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[228 "TransitGatewayRouteTable"229 ]230 table.should.have.key("TransitGatewayRouteTableId").match("tgw-rtb-[0-9a-z]+")231 table.should.have.key("TransitGatewayId").equals(gateway_id)232 table.should.have.key("State").equals("available")233 table.should.have.key("DefaultAssociationRouteTable").equals(False)234 table.should.have.key("DefaultPropagationRouteTable").equals(False)235 table.should.have.key("CreationTime")236 table.should.have.key("Tags").equals([])237 tables = ec2.describe_transit_gateway_route_tables(238 TransitGatewayRouteTableIds=[table["TransitGatewayRouteTableId"]]239 )["TransitGatewayRouteTables"]240 tables.should.have.length_of(1)241@mock_ec2242def test_create_transit_gateway_route_table_with_tags():243 ec2 = boto3.client("ec2", region_name="us-west-1")244 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][245 "TransitGatewayId"246 ]247 response = ec2.create_transit_gateway_route_table(248 TransitGatewayId=gateway_id,249 TagSpecifications=[250 {251 "ResourceType": "transit-gateway-route-table",252 "Tags": [253 {"Key": "tag1", "Value": "val1"},254 {"Key": "tag2", "Value": "val2"},255 ],256 }257 ],258 )259 table = response["TransitGatewayRouteTable"]260 table["Tags"].should.have.length_of(2)261 table["Tags"].should.contain({"Key": "tag1", "Value": "val1"})262 table["Tags"].should.contain({"Key": "tag2", "Value": "val2"})263@mock_ec2264def test_delete_transit_gateway_route_table():265 ec2 = boto3.client("ec2", region_name="us-west-1")266 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][267 "TransitGatewayId"268 ]269 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[270 "TransitGatewayRouteTable"271 ]272 table_id = table["TransitGatewayRouteTableId"]273 tables = ec2.describe_transit_gateway_route_tables(274 TransitGatewayRouteTableIds=[table_id]275 )["TransitGatewayRouteTables"]276 tables.should.have.length_of(1)277 tables[0]["State"].should.equal("available")278 table = ec2.delete_transit_gateway_route_table(TransitGatewayRouteTableId=table_id)279 table["TransitGatewayRouteTable"].should.have.key("State").equals("deleted")280 tables = ec2.describe_transit_gateway_route_tables(281 TransitGatewayRouteTableIds=[table_id]282 )["TransitGatewayRouteTables"]283 tables.should.have.length_of(1)284 tables[0]["State"].should.equal("deleted")285@mock_ec2286def test_search_transit_gateway_routes_empty():287 ec2 = boto3.client("ec2", region_name="us-west-1")288 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][289 "TransitGatewayId"290 ]291 table_id = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[292 "TransitGatewayRouteTable"293 ]["TransitGatewayRouteTableId"]294 response = ec2.search_transit_gateway_routes(295 TransitGatewayRouteTableId=table_id,296 Filters=[{"Name": "state", "Values": ["active"]}],297 )298 response.should.have.key("Routes").equal([])299 response.should.have.key("AdditionalRoutesAvailable").equal(False)300@mock_ec2301def test_create_transit_gateway_route():302 ec2 = boto3.client("ec2", region_name="us-west-1")303 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][304 "TransitGatewayId"305 ]306 table_id = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[307 "TransitGatewayRouteTable"308 ]["TransitGatewayRouteTableId"]309 route = ec2.create_transit_gateway_route(310 DestinationCidrBlock="0.0.0.0", TransitGatewayRouteTableId=table_id311 )["Route"]312 route.should.have.key("DestinationCidrBlock").equal("0.0.0.0")313 route.should.have.key("Type").equal("static")314 route.should.have.key("State").equal("active")315@mock_ec2316def test_create_transit_gateway_route_as_blackhole():317 ec2 = boto3.client("ec2", region_name="us-west-1")318 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][319 "TransitGatewayId"320 ]321 table_id = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[322 "TransitGatewayRouteTable"323 ]["TransitGatewayRouteTableId"]324 route = ec2.create_transit_gateway_route(325 DestinationCidrBlock="192.168.0.1",326 TransitGatewayRouteTableId=table_id,327 Blackhole=True,328 )["Route"]329 route.should.have.key("DestinationCidrBlock").equal("192.168.0.1")330 route.should.have.key("Type").equal("static")331 route.should.have.key("State").equal("blackhole")332@mock_ec2333def test_search_transit_gateway_routes_by_state():334 ec2 = boto3.client("ec2", region_name="us-west-1")335 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][336 "TransitGatewayId"337 ]338 table_id = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[339 "TransitGatewayRouteTable"340 ]["TransitGatewayRouteTableId"]341 ec2.create_transit_gateway_route(342 DestinationCidrBlock="192.168.0.0", TransitGatewayRouteTableId=table_id343 )344 ec2.create_transit_gateway_route(345 DestinationCidrBlock="192.168.0.1",346 TransitGatewayRouteTableId=table_id,347 Blackhole=True,348 )349 routes = ec2.search_transit_gateway_routes(350 TransitGatewayRouteTableId=table_id,351 Filters=[{"Name": "state", "Values": ["active"]}],352 )["Routes"]353 routes.should.equal(354 [{"DestinationCidrBlock": "192.168.0.0", "Type": "static", "State": "active"}]355 )356 routes = ec2.search_transit_gateway_routes(357 TransitGatewayRouteTableId=table_id,358 Filters=[{"Name": "state", "Values": ["blackhole"]}],359 )["Routes"]360 routes.should.equal(361 [362 {363 "DestinationCidrBlock": "192.168.0.1",364 "Type": "static",365 "State": "blackhole",366 }367 ]368 )369 routes = ec2.search_transit_gateway_routes(370 TransitGatewayRouteTableId=table_id,371 Filters=[{"Name": "state", "Values": ["unknown"]}],372 )["Routes"]373 routes.should.equal([])374@mock_ec2375def test_search_transit_gateway_routes_by_routesearch():376 client = boto3.client("ec2", region_name="us-west-2")377 vpc = client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"]378 subnet = client.create_subnet(VpcId=vpc["VpcId"], CidrBlock="10.0.1.0/24")["Subnet"]379 tgw = client.create_transit_gateway(Description="description")380 tgw_id = tgw["TransitGateway"]["TransitGatewayId"]381 route_table = client.create_transit_gateway_route_table(TransitGatewayId=tgw_id)382 transit_gateway_route_id = route_table["TransitGatewayRouteTable"][383 "TransitGatewayRouteTableId"384 ]385 attachment = client.create_transit_gateway_vpc_attachment(386 TransitGatewayId=tgw_id, VpcId=vpc["VpcId"], SubnetIds=[subnet["SubnetId"]]387 )388 transit_gateway_attachment_id = attachment["TransitGatewayVpcAttachment"][389 "TransitGatewayAttachmentId"390 ]391 exported_cidr_ranges = ["172.17.0.0/24", "192.160.0.0/24"]392 for route in exported_cidr_ranges:393 client.create_transit_gateway_route(394 DestinationCidrBlock=route,395 TransitGatewayRouteTableId=transit_gateway_route_id,396 TransitGatewayAttachmentId=transit_gateway_attachment_id,397 )398 for route in exported_cidr_ranges:399 expected_route = client.search_transit_gateway_routes(400 TransitGatewayRouteTableId=transit_gateway_route_id,401 Filters=[{"Name": "route-search.exact-match", "Values": [route]}],402 )403 expected_route["Routes"][0]["DestinationCidrBlock"].should.equal(route)404@mock_ec2405def test_delete_transit_gateway_route():406 ec2 = boto3.client("ec2", region_name="us-west-1")407 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][408 "TransitGatewayId"409 ]410 table_id = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[411 "TransitGatewayRouteTable"412 ]["TransitGatewayRouteTableId"]413 ec2.create_transit_gateway_route(414 DestinationCidrBlock="192.168.0.0", TransitGatewayRouteTableId=table_id415 )416 ec2.create_transit_gateway_route(417 DestinationCidrBlock="192.168.0.1", TransitGatewayRouteTableId=table_id418 )419 response = ec2.delete_transit_gateway_route(420 DestinationCidrBlock="192.168.0.0", TransitGatewayRouteTableId=table_id421 )422 response["Route"].should.equal(423 {"DestinationCidrBlock": "192.168.0.0", "Type": "static", "State": "deleted"}424 )425 routes = ec2.search_transit_gateway_routes(426 TransitGatewayRouteTableId=table_id,427 Filters=[{"Name": "state", "Values": ["active"]}],428 )["Routes"]429 routes.should.equal(430 [{"DestinationCidrBlock": "192.168.0.1", "Type": "static", "State": "active"}]431 )432@mock_ec2433def test_create_transit_gateway_vpc_attachment():434 ec2 = boto3.client("ec2", region_name="us-west-1")435 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][436 "TransitGatewayId"437 ]438 response = ec2.create_transit_gateway_vpc_attachment(439 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]440 )441 response.should.have.key("TransitGatewayVpcAttachment")442 attachment = response["TransitGatewayVpcAttachment"]443 attachment.should.have.key("TransitGatewayAttachmentId").match(444 "tgw-attach-[0-9a-z]+"445 )446 attachment.should.have.key("TransitGatewayId").equal(gateway_id)447 attachment.should.have.key("VpcId").equal("vpc-id")448 attachment.should.have.key("VpcOwnerId").equal(ACCOUNT_ID)449 attachment.should.have.key("SubnetIds").equal(["sub1"])450 attachment.should.have.key("State").equal("available")451 attachment.should.have.key("Tags").equal([])452@mock_ec2453def test_modify_transit_gateway_vpc_attachment_add_subnets():454 ec2 = boto3.client("ec2", region_name="us-west-1")455 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][456 "TransitGatewayId"457 ]458 response = ec2.create_transit_gateway_vpc_attachment(459 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1", "sub3"]460 )461 attchmnt_id = response["TransitGatewayVpcAttachment"]["TransitGatewayAttachmentId"]462 ec2.modify_transit_gateway_vpc_attachment(463 TransitGatewayAttachmentId=attchmnt_id, AddSubnetIds=["sub2"]464 )465 attachment = ec2.describe_transit_gateway_vpc_attachments(466 TransitGatewayAttachmentIds=[attchmnt_id]467 )["TransitGatewayVpcAttachments"][0]468 sorted(attachment["SubnetIds"]).should.equal(["sub1", "sub2", "sub3"])469@mock_ec2470def test_modify_transit_gateway_vpc_attachment_remove_subnets():471 ec2 = boto3.client("ec2", region_name="us-west-1")472 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][473 "TransitGatewayId"474 ]475 response = ec2.create_transit_gateway_vpc_attachment(476 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1", "sub2", "sub3"]477 )478 attchmnt_id = response["TransitGatewayVpcAttachment"]["TransitGatewayAttachmentId"]479 ec2.modify_transit_gateway_vpc_attachment(480 TransitGatewayAttachmentId=attchmnt_id, RemoveSubnetIds=["sub2"]481 )482 attachment = ec2.describe_transit_gateway_vpc_attachments(483 TransitGatewayAttachmentIds=[attchmnt_id]484 )["TransitGatewayVpcAttachments"][0]485 attachment["SubnetIds"].should.equal(["sub1", "sub3"])486@mock_ec2487def test_modify_transit_gateway_vpc_attachment_change_options():488 ec2 = boto3.client("ec2", region_name="us-west-1")489 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][490 "TransitGatewayId"491 ]492 response = ec2.create_transit_gateway_vpc_attachment(493 TransitGatewayId=gateway_id,494 VpcId="vpc-id",495 SubnetIds=["sub1"],496 Options={497 "DnsSupport": "enable",498 "Ipv6Support": "enable",499 "ApplianceModeSupport": "enable",500 },501 )502 attchmnt_id = response["TransitGatewayVpcAttachment"]["TransitGatewayAttachmentId"]503 ec2.modify_transit_gateway_vpc_attachment(504 TransitGatewayAttachmentId=attchmnt_id,505 Options={"ApplianceModeSupport": "disabled"},506 )507 attachment = ec2.describe_transit_gateway_vpc_attachments(508 TransitGatewayAttachmentIds=[attchmnt_id]509 )["TransitGatewayVpcAttachments"][0]510 attachment["Options"]["ApplianceModeSupport"].should.equal("disabled")511 attachment["Options"]["DnsSupport"].should.equal("enable")512 attachment["Options"]["Ipv6Support"].should.equal("enable")513@mock_ec2514def test_delete_transit_gateway_vpc_attachment():515 ec2 = boto3.client("ec2", region_name="us-west-1")516 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][517 "TransitGatewayId"518 ]519 a1 = ec2.create_transit_gateway_vpc_attachment(520 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]521 )["TransitGatewayVpcAttachment"]["TransitGatewayAttachmentId"]522 a2 = ec2.create_transit_gateway_vpc_attachment(523 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]524 )["TransitGatewayVpcAttachment"]["TransitGatewayAttachmentId"]525 available = ec2.describe_transit_gateway_vpc_attachments(526 TransitGatewayAttachmentIds=[a1, a2],527 Filters=[{"Name": "state", "Values": ["available"]}],528 )["TransitGatewayVpcAttachments"]529 available.should.have.length_of(2)530 a1_removed = ec2.delete_transit_gateway_vpc_attachment(531 TransitGatewayAttachmentId=a1532 )["TransitGatewayVpcAttachment"]533 a1_removed.should.have.key("TransitGatewayAttachmentId").equal(a1)534 a1_removed.should.have.key("State").equal("deleted")535 all_attchmnts = ec2.describe_transit_gateway_vpc_attachments(536 TransitGatewayAttachmentIds=[a1, a2]537 )["TransitGatewayVpcAttachments"]538 all_attchmnts.should.have.length_of(1)539 [a["TransitGatewayAttachmentId"] for a in all_attchmnts].should.equal([a2])540@mock_ec2541def test_associate_transit_gateway_route_table():542 ec2 = boto3.client("ec2", region_name="us-west-1")543 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][544 "TransitGatewayId"545 ]546 attchmnt = ec2.create_transit_gateway_vpc_attachment(547 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]548 )["TransitGatewayVpcAttachment"]549 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[550 "TransitGatewayRouteTable"551 ]552 initial = ec2.get_transit_gateway_route_table_associations(553 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]554 )555 initial["Associations"].should.equal(556 [557 {558 "TransitGatewayAttachmentId": "",559 "ResourceId": "",560 "ResourceType": "",561 "State": "",562 }563 ]564 )565 ec2.associate_transit_gateway_route_table(566 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],567 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],568 )569 updated = ec2.get_transit_gateway_route_table_associations(570 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]571 )572 updated["Associations"].should.equal(573 [574 {575 "TransitGatewayAttachmentId": attchmnt["TransitGatewayAttachmentId"],576 "ResourceId": "vpc-id",577 "ResourceType": "vpc",578 "State": "associated",579 }580 ]581 )582@mock_ec2583def test_disassociate_transit_gateway_route_table():584 ec2 = boto3.client("ec2", region_name="us-west-1")585 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][586 "TransitGatewayId"587 ]588 attchmnt = ec2.create_transit_gateway_vpc_attachment(589 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]590 )["TransitGatewayVpcAttachment"]591 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[592 "TransitGatewayRouteTable"593 ]594 initial = ec2.get_transit_gateway_route_table_associations(595 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]596 )["Associations"][0]597 initial["TransitGatewayAttachmentId"].should.equal("")598 ec2.associate_transit_gateway_route_table(599 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],600 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],601 )602 updated = ec2.get_transit_gateway_route_table_associations(603 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]604 )["Associations"][0]605 updated["TransitGatewayAttachmentId"].should.equal(606 attchmnt["TransitGatewayAttachmentId"]607 )608 updated["State"].should.equal("associated")609 dis = ec2.disassociate_transit_gateway_route_table(610 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],611 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],612 )["Association"]613 dis["State"].should.equal("disassociated")614 updated = ec2.get_transit_gateway_route_table_associations(615 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]616 )["Associations"][0]617 updated["TransitGatewayAttachmentId"].should.equal("")618 updated["State"].should.equal("")619@mock_ec2620def test_enable_transit_gateway_route_table_propagation():621 ec2 = boto3.client("ec2", region_name="us-west-1")622 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][623 "TransitGatewayId"624 ]625 attchmnt = ec2.create_transit_gateway_vpc_attachment(626 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]627 )["TransitGatewayVpcAttachment"]628 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[629 "TransitGatewayRouteTable"630 ]631 initial = ec2.get_transit_gateway_route_table_propagations(632 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]633 )634 initial["TransitGatewayRouteTablePropagations"].should.equal(635 [636 {637 "TransitGatewayAttachmentId": "",638 "ResourceId": "",639 "ResourceType": "",640 "State": "",641 }642 ]643 )644 ec2.associate_transit_gateway_route_table(645 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],646 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],647 )648 ec2.enable_transit_gateway_route_table_propagation(649 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],650 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],651 )652 enabled = ec2.get_transit_gateway_route_table_propagations(653 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]654 )655 enabled["TransitGatewayRouteTablePropagations"].should.equal(656 [657 {658 "TransitGatewayAttachmentId": attchmnt["TransitGatewayAttachmentId"],659 "ResourceId": "vpc-id",660 "ResourceType": "vpc",661 "State": "enabled",662 }663 ]664 )665@mock_ec2666def test_disable_transit_gateway_route_table_propagation_without_enabling_first():667 ec2 = boto3.client("ec2", region_name="us-west-1")668 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][669 "TransitGatewayId"670 ]671 attchmnt = ec2.create_transit_gateway_vpc_attachment(672 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]673 )["TransitGatewayVpcAttachment"]674 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[675 "TransitGatewayRouteTable"676 ]677 initial = ec2.get_transit_gateway_route_table_propagations(678 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]679 )680 initial["TransitGatewayRouteTablePropagations"].should.equal(681 [682 {683 "TransitGatewayAttachmentId": "",684 "ResourceId": "",685 "ResourceType": "",686 "State": "",687 }688 ]689 )690 ec2.associate_transit_gateway_route_table(691 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],692 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],693 )694 try:695 ec2.disable_transit_gateway_route_table_propagation(696 TransitGatewayAttachmentId=attchmnt["TransitGatewayAttachmentId"],697 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"],698 )699 assert False, "Should not be able to disable before enabling it"700 except Exception:701 pass702@mock_ec2703def test_disable_transit_gateway_route_table_propagation():704 ec2 = boto3.client("ec2", region_name="us-west-1")705 gateway_id = ec2.create_transit_gateway(Description="g")["TransitGateway"][706 "TransitGatewayId"707 ]708 attchmnt = ec2.create_transit_gateway_vpc_attachment(709 TransitGatewayId=gateway_id, VpcId="vpc-id", SubnetIds=["sub1"]710 )["TransitGatewayVpcAttachment"]711 table = ec2.create_transit_gateway_route_table(TransitGatewayId=gateway_id)[712 "TransitGatewayRouteTable"713 ]714 initial = ec2.get_transit_gateway_route_table_propagations(715 TransitGatewayRouteTableId=table["TransitGatewayRouteTableId"]716 )717 initial["TransitGatewayRouteTablePropagations"].should.equal(718 [719 {720 "TransitGatewayAttachmentId": "",721 "ResourceId": "",722 "ResourceType": "",...
transit-gateway.py
Source:transit-gateway.py
...18 DryRun=False19 )20 return response21#create transit gateway VPC attachment22def create_transit_gateway_vpc_attachment(transit_gateway_id, vpc_id, subnet_id):23 client = boto3.client('ec2', region_name='us-east-1')24 response = client.create_transit_gateway_vpc_attachment(25 TransitGatewayId=transit_gateway_id,26 VpcId=vpc_id,27 SubnetIds=[28 subnet_id,29 ],30 Options={31 'DnsSupport': 'enable',32 'Ipv6Support': 'disable'33 },34 DryRun=False35 )36 return response37#Create transit gateway route-table38def create_transit_gateway_rt(transit_gateway_id):39 client = boto3.client('ec2', region_name='us-east-1')40 response = client.create_transit_gateway_route_table(41 TransitGatewayId=transit_gateway_id,42 DryRun=False43 )44 return response45#Create transit gateway route46def create_transit_gateway_route(transit_gateway_rt_id, destination_ip_block, transit_gateway_attachment_id):47 client = boto3.client('ec2', region_name='us-east-1')48 response = client.create_transit_gateway_route(49 DestinationCidrBlock=destination_ip_block,50 TransitGatewayRouteTableId=transit_gateway_rt_id,51 TransitGatewayAttachmentId=transit_gateway_attachment_id,52 Blackhole=False,53 DryRun=False54 )55 return response56#Create transit gateway multi-cast domain57def create_transit_gateway_multicast_domain(transit_gateway_id):58 client = boto3.client('ec2', region_name='us-east-1')59 response = client.create_transit_gateway_multicast_domain(60 TransitGatewayId=transit_gateway_id,61 DryRun=False62 )63 return response64#Associate transit gateway multi cast domain65def associate_transit_gateway_multicast_domain(tgw_multicast_domain_id, tgw_attachment_id, subnetID):66 client = boto3.client('ec2', region_name='us-east-1')67 response = client.associate_transit_gateway_multicast_domain(68 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,69 TransitGatewayAttachmentId=tgw_attachment_id,70 SubnetIds=[71 subnetID,72 ],73 DryRun=False74 )75 return response76#Delete transit gateway multi-cast domain77def delete_transit_gateway_multicast_domain(tgwy_multicast_domain_id):78 client = boto3.client('ec2', region_name='us-east-1')79 response = client.delete_transit_gateway_multicast_domain(80 TransitGatewayMulticastDomainId=tgwy_multicast_domain_id,81 DryRun=False82 )83 return response84#Delete transit gateway vpc attachment85def delete_transit_gateway_vpc_attachment(transit_gateway_attachment_id):86 client = boto3.client('ec2', region_name='us-east-1')87 response = client.delete_transit_gateway_vpc_attachment(88 TransitGatewayAttachmentId=transit_gateway_attachment_id,89 DryRun=False90 )91 return response92#Delete transit gateway93def delete_transit_gateway(transit_gateway_id):94 client = boto3.client('ec2', region_name='us-east-1')95 response = client.delete_transit_gateway(96 TransitGatewayId=transit_gateway_id,97 DryRun=False98 )99# dissacotiate transit gateway multicast domain100def disassociate_transit_gateway_multicast_domain(tgw_multicast_domain_id, tgw_attachment_id, subnet_id):101 client = boto3.client('ec2', region_name='us-east-1')102 response = client.disassociate_transit_gateway_multicast_domain(103 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,104 TransitGatewayAttachmentId=tgw_attachment_id,105 SubnetIds=[106 subnet_id,107 ],108 DryRun=False109 )110#register transit gateway multi-cast members111def register_transit_gateway_multicast_group_members(tgw_multicast_domain_id, group_address, network_interface2, network_interface3, network_interface4):112 client = boto3.client('ec2', region_name='us-east-1')113 response = client.register_transit_gateway_multicast_group_members(114 TransitGatewayMulticastDomainId = tgw_multicast_domain_id,115 GroupIpAddress = group_address,116 NetworkInterfaceIds = [117 network_interface2, network_interface3, network_interface4118 ],119 DryRun = False120 )121 return response122def register_transit_gateway_multicast_group_sources(tgw_multicast_domain_id, nic1id):123 client = boto3.client('ec2', region_name='us-east-1')124 response = client.register_transit_gateway_multicast_group_sources(125 TransitGatewayMulticastDomainId=tgw_multicast_domain_id,126 GroupIpAddress='224.0.0.0',127 NetworkInterfaceIds=[128 nic1id,129 ],130 DryRun=False131 )132 return response133if __name__ == '__main__':134 action = sys.argv[1]135 if action == "apply":136 #Get variables from cmd line137 vpc_id = sys.argv[2]138 subnet_id = sys.argv[3]139 i1nic = sys.argv[4]140 i2nic = sys.argv[5]141 i3nic = sys.argv[6]142 i4nic = sys.argv[7]143 #Create transit gateway144 tgw_response = create_transit_gateway()145 #Collect transit gateway id from response146 tgw_id = tgw_response['TransitGateway']['TransitGatewayId']147 time.sleep(180)148 #Create transit gateway attachment149 tgw_attachment_response = create_transit_gateway_vpc_attachment(tgw_id, vpc_id, subnet_id)150 #get tgw attachment id response151 tgw_attachment_id = tgw_attachment_response['TransitGatewayVpcAttachment']['TransitGatewayAttachmentId']152 time.sleep(60)153 #Create transit gateway route table and get response154 tgw_rt_response = create_transit_gateway_rt(tgw_id)155 #Get transit gateway route table id from the response156 tgw_rt_id = tgw_rt_response ['TransitGatewayRouteTable']['TransitGatewayRouteTableId']157 time.sleep(90)158 #Create transit gateway route159 create_transit_gateway_route(tgw_rt_id, "10.123.111.0/24", tgw_attachment_id)160 #Create transit gateway multi cast domain161 tgw_multicast_domain_response = create_transit_gateway_multicast_domain(tgw_id)162 #Get transit gateway multi cast domain id163 tgw_multicast_domain_id = tgw_multicast_domain_response['TransitGatewayMulticastDomain']['TransitGatewayMulticastDomainId']...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!