How to use delete_route_table method in localstack

Best Python code snippet using localstack_python

test_routes.py

Source:test_routes.py Github

copy

Full Screen

...32 cls.vpc_id = data['Vpc']['VpcId']33 cls.addResourceCleanUpStatic(cls.client.delete_vpc, VpcId=cls.vpc_id)34 cls.get_vpc_waiter().wait_available(cls.vpc_id)35 @decorators.idempotent_id('69c04d14-5603-4a98-9331-739821b98b10')36 def test_create_delete_route_table(self):37 data = self.client.create_route_table(VpcId=self.vpc_id)38 rt_id = data['RouteTable']['RouteTableId']39 res_clean = self.addResourceCleanUp(self.client.delete_route_table,40 RouteTableId=rt_id)41 rt = data['RouteTable']42 self.assertEqual(self.vpc_id, rt['VpcId'])43 self.assertEqual(1, len(rt['Routes']))44 route = rt['Routes'][0]45 self.assertEqual(self.VPC_CIDR, route['DestinationCidrBlock'])46 self.assertEqual('active', route['State'])47 data = self.client.delete_route_table(RouteTableId=rt_id)48 self.cancelResourceCleanUp(res_clean)49 self.assertRaises('InvalidRouteTableID.NotFound',50 self.client.describe_route_tables,51 RouteTableIds=[rt_id])52 self.assertRaises('InvalidRouteTableID.NotFound',53 self.client.delete_route_table,54 RouteTableId=rt_id)55 @decorators.idempotent_id('d8051b30-eb70-4c4b-988b-56078a125af3')56 def test_describe_route_tables_base(self):57 data = self.client.create_route_table(VpcId=self.vpc_id)58 rt_id = data['RouteTable']['RouteTableId']59 res_clean = self.addResourceCleanUp(self.client.delete_route_table,60 RouteTableId=rt_id)61 # NOTE(andrey-mp): by real id62 data = self.client.describe_route_tables(RouteTableIds=[rt_id])63 self.assertEqual(1, len(data['RouteTables']))64 # NOTE(andrey-mp): by fake id65 self.assertRaises('InvalidRouteTableID.NotFound',66 self.client.describe_route_tables,67 RouteTableIds=['rtb-0'])68 data = self.client.delete_route_table(RouteTableId=rt_id)69 self.cancelResourceCleanUp(res_clean)70 @decorators.idempotent_id('77a53f3e-437a-45ed-b3b5-e6b7ab2c9407')71 def test_describe_route_tables_filters(self):72 data = self.client.create_route_table(VpcId=self.vpc_id)73 rt_id = data['RouteTable']['RouteTableId']74 self.addResourceCleanUp(self.client.delete_route_table,75 RouteTableId=rt_id)76 data = self.client.create_subnet(VpcId=self.vpc_id,77 CidrBlock=self.SUBNET_CIDR)78 subnet_id = data['Subnet']['SubnetId']79 self.addResourceCleanUp(self.client.delete_subnet,80 SubnetId=subnet_id)81 self.get_subnet_waiter().wait_available(subnet_id)82 data = self.client.associate_route_table(RouteTableId=rt_id,83 SubnetId=subnet_id)84 assoc_id = data['AssociationId']85 self.addResourceCleanUp(self.client.disassociate_route_table,86 AssociationId=assoc_id)87 # NOTE(andrey-mp): by association_id88 data = self.client.describe_route_tables(89 Filters=[{'Name': 'association.route-table-association-id',90 'Values': [assoc_id]}])91 self.assertEqual(1, len(data['RouteTables']))92 # NOTE(andrey-mp): by route table id93 data = self.client.describe_route_tables(94 Filters=[{'Name': 'association.route-table-id',95 'Values': [rt_id]}])96 self.assertEqual(1, len(data['RouteTables']))97 # NOTE(andrey-mp): by subnet id98 data = self.client.describe_route_tables(99 Filters=[{'Name': 'association.subnet-id',100 'Values': [subnet_id]}])101 self.assertEqual(1, len(data['RouteTables']))102 # NOTE(andrey-mp): by filter real vpc103 data = self.client.describe_route_tables(104 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])105 self.assertLess(0, len(data['RouteTables']))106 # NOTE(andrey-mp): by filter fake vpc107 data = self.client.describe_route_tables(108 Filters=[{'Name': 'vpc-id', 'Values': ['vpc-0']}])109 self.assertEqual(0, len(data['RouteTables']))110 # NOTE(andrey-mp): by fake filter111 self.assertRaises('InvalidParameterValue',112 self.client.describe_route_tables,113 Filters=[{'Name': 'fake', 'Values': ['fake']}])114 @decorators.idempotent_id('55361f57-331a-43b8-8729-efee2d1c0dc9')115 def test_associate_disassociate_route_table(self):116 data = self.client.create_route_table(VpcId=self.vpc_id)117 rt_id = data['RouteTable']['RouteTableId']118 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,119 RouteTableId=rt_id)120 data = self.client.create_subnet(VpcId=self.vpc_id,121 CidrBlock=self.SUBNET_CIDR)122 subnet_id = data['Subnet']['SubnetId']123 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,124 SubnetId=subnet_id)125 self.get_subnet_waiter().wait_available(subnet_id)126 data = self.client.associate_route_table(RouteTableId=rt_id,127 SubnetId=subnet_id)128 assoc_id = data['AssociationId']129 res_clean = self.addResourceCleanUp(130 self.client.disassociate_route_table, AssociationId=assoc_id)131 data = self.client.disassociate_route_table(AssociationId=assoc_id)132 self.cancelResourceCleanUp(res_clean)133 data = self.client.delete_subnet(SubnetId=subnet_id)134 self.cancelResourceCleanUp(res_clean_subnet)135 self.get_subnet_waiter().wait_delete(subnet_id)136 data = self.client.delete_route_table(RouteTableId=rt_id)137 self.cancelResourceCleanUp(res_clean_rt)138 @decorators.idempotent_id('b1a07211-6e9a-41db-8017-47e7c4b9c043')139 def test_replace_route_table(self):140 data = self.client.create_subnet(VpcId=self.vpc_id,141 CidrBlock=self.SUBNET_CIDR)142 subnet_id = data['Subnet']['SubnetId']143 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,144 SubnetId=subnet_id)145 self.get_subnet_waiter().wait_available(subnet_id)146 # NOTE(andrey-mp): by vpc id147 data = self.client.describe_route_tables(148 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])149 self.assertEqual(1, len(data['RouteTables']))150 self.assertEqual(1, len(data['RouteTables'][0]['Associations']))151 default_rt_id = data['RouteTables'][0]['RouteTableId']152 main_assoc = data['RouteTables'][0]['Associations'][0]153 self.assertTrue(main_assoc['Main'])154 main_assoc_id = main_assoc['RouteTableAssociationId']155 data = self.client.create_route_table(VpcId=self.vpc_id)156 rt_id = data['RouteTable']['RouteTableId']157 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,158 RouteTableId=rt_id)159 data = self.client.replace_route_table_association(160 RouteTableId=rt_id, AssociationId=main_assoc_id)161 assoc_id = data['NewAssociationId']162 res_clean = self.addResourceCleanUp(163 self.client.replace_route_table_association,164 RouteTableId=default_rt_id,165 AssociationId=assoc_id)166 # NOTE(andrey-mp): by vpc id167 data = self.client.describe_route_tables(168 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])169 self.assertEqual(2, len(data['RouteTables']))170 for rt in data['RouteTables']:171 if rt['RouteTableId'] == rt_id:172 self.assertEqual(1, len(rt['Associations']))173 self.assertTrue(rt['Associations'][0]['Main'])174 else:175 self.assertEmpty(rt.get('Associations', []))176 self.assertRaises('DependencyViolation',177 self.client.delete_route_table,178 RouteTableId=rt_id)179 self.assertRaises('InvalidParameterValue',180 self.client.disassociate_route_table,181 AssociationId=assoc_id)182 data = self.client.replace_route_table_association(183 RouteTableId=default_rt_id,184 AssociationId=assoc_id)185 self.cancelResourceCleanUp(res_clean)186 data = self.client.delete_route_table(RouteTableId=rt_id)187 self.cancelResourceCleanUp(res_clean_rt)188 data = self.client.delete_subnet(SubnetId=subnet_id)189 self.cancelResourceCleanUp(res_clean_subnet)190 self.get_subnet_waiter().wait_delete(subnet_id)191 @decorators.idempotent_id('c112ecdb-dce3-4497-b11b-5349a2d89336')192 def test_create_delete_route(self):193 data = self.client.create_subnet(VpcId=self.vpc_id,194 CidrBlock=self.SUBNET_CIDR)195 subnet_id = data['Subnet']['SubnetId']196 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,197 SubnetId=subnet_id)198 self.get_subnet_waiter().wait_available(subnet_id)199 kwargs = {200 'SubnetId': subnet_id,201 }202 data = self.client.create_network_interface(*[], **kwargs)203 ni_id = data['NetworkInterface']['NetworkInterfaceId']204 res_clean_ni = self.addResourceCleanUp(205 self.client.delete_network_interface,206 NetworkInterfaceId=ni_id)207 data = self.client.create_route_table(VpcId=self.vpc_id)208 rt_id = data['RouteTable']['RouteTableId']209 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,210 RouteTableId=rt_id)211 kwargs = {212 'DestinationCidrBlock': self.VPC_CIDR,213 'RouteTableId': rt_id,214 'NetworkInterfaceId': ni_id215 }216 self.assertRaises('InvalidParameterValue',217 self.client.create_route,218 **kwargs)219 # can create wider route220 kwargs = {221 'DestinationCidrBlock': '10.14.0.0/19',222 'RouteTableId': rt_id,223 'NetworkInterfaceId': ni_id224 }225 data = self.client.create_route(*[], **kwargs)226 # can create to another vpc227 kwargs = {228 'DestinationCidrBlock': '10.15.0.0/20',229 'RouteTableId': rt_id,230 'NetworkInterfaceId': ni_id231 }232 data = self.client.create_route(*[], **kwargs)233 data = self.client.describe_route_tables(RouteTableIds=[rt_id])234 self.assertEqual(1, len(data['RouteTables']))235 self.assertEqual(3, len(data['RouteTables'][0]['Routes']))236 kwargs = {237 'DestinationCidrBlock': '10.15.0.0/24',238 'RouteTableId': rt_id,239 }240 self.assertRaises('InvalidRoute.NotFound',241 self.client.delete_route,242 **kwargs)243 kwargs = {244 'DestinationCidrBlock': self.VPC_CIDR,245 'RouteTableId': rt_id,246 }247 self.assertRaises('InvalidParameterValue',248 self.client.delete_route,249 **kwargs)250 kwargs = {251 'DestinationCidrBlock': self.SUBNET_CIDR,252 'RouteTableId': rt_id,253 }254 self.assertRaises('InvalidRoute.NotFound',255 self.client.delete_route,256 **kwargs)257 kwargs = {258 'DestinationCidrBlock': '10.16.0.0/24',259 'RouteTableId': rt_id,260 }261 self.assertRaises('InvalidRoute.NotFound',262 self.client.delete_route,263 **kwargs)264 kwargs = {265 'DestinationCidrBlock': '10.15.0.0/20',266 'RouteTableId': rt_id,267 }268 data = self.client.delete_route(*[], **kwargs)269 kwargs = {270 'DestinationCidrBlock': '10.14.0.0/19',271 'RouteTableId': rt_id,272 }273 data = self.client.delete_route(*[], **kwargs)274 data = self.client.delete_route_table(RouteTableId=rt_id)275 self.cancelResourceCleanUp(res_clean_rt)276 data = self.client.delete_network_interface(277 NetworkInterfaceId=ni_id)278 self.cancelResourceCleanUp(res_clean_ni)279 self.get_network_interface_waiter().wait_delete(ni_id)280 data = self.client.delete_subnet(SubnetId=subnet_id)281 self.cancelResourceCleanUp(res_clean_subnet)...

Full Screen

Full Screen

clear_ch2.py

Source:clear_ch2.py Github

copy

Full Screen

...11def disassociate_route_table(ec2_client, route_table_association_id):12 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.disassociate_route_table13 response = ec2_client.disassociate_route_table(AssociationId=route_table_association_id)14 print(response)15def delete_route_table(ec2_client, route_table_id):16 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_route_table17 response = ec2_client.delete_route_table(RouteTableId=route_table_id)18 print(response)19def detach_internet_gateway_from_vpc(ec2_client, internet_gateway_id, vpc_id):20 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.detach_internet_gateway21 response = ec2_client.detach_internet_gateway(22 InternetGatewayId=internet_gateway_id,23 VpcId=vpc_id,24 )25 print(response)26def delete_internet_gateway(ec2_client, internet_gateway_id):27 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_internet_gateway28 response = ec2_client.delete_internet_gateway(InternetGatewayId=internet_gateway_id)29 print(response)30def delete_subnet(ec2_client, subnet_id):31 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_subnet32 response = ec2_client.delete_subnet(SubnetId=subnet_id)33 print(response)34def delete_vpc(ec2_client, vpc_id):35 # https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.delete_vpc36 response = ec2_client.delete_vpc(VpcId=vpc_id)37 print(response)38def delete_each_vpc_items(ec2_client, aws):39 # 逆順に解放していく40 # デフォルトゲートウェイからインターネットゲートウェイを削除41 delete_route_from_route_table(ec2_client, aws['public_route_table_id'])42 # ルートテーブルとサブネットの関連付けを削除43 disassociate_route_table(ec2_client, aws['public_route_table_association_id'])44 # ルートテーブルの削除45 delete_route_table(ec2_client, aws['public_route_table_id'])46 # インターネットゲートウェイの削除47 # インターネットゲートウェイをVPC領域から削除48 detach_internet_gateway_from_vpc(ec2_client, aws['internet_gateway_id'], aws['vpc_id'])49 # インターネットゲートウェイの削除50 delete_internet_gateway(ec2_client, aws['internet_gateway_id'])51 # サブネットの削除52 delete_subnet(ec2_client, aws['public_subnet_id'])53 # VPC領域の削除54 delete_vpc(ec2_client, aws_keys['vpc_id'])55if __name__ == '__main__':56 # Profileをロード57 session = boto3.Session(profile_name='my-profile')58 # クライアントとリソースを作っておく59 client = create_ec2_client(session)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful