How to use release_address method in localstack

Best Python code snippet using localstack_python

test_addresses.py

Source:test_addresses.py Github

copy

Full Screen

...30 id = data['AllocationId']31 res_clean = self.addResourceCleanUp(self.client.release_address,32 AllocationId=id)33 self.assertEqual('vpc', data['Domain'])34 data = self.client.release_address(AllocationId=id)35 self.cancelResourceCleanUp(res_clean)36 def test_create_delete_standard_address(self):37 data = self.client.allocate_address()38 ip = data['PublicIp']39 res_clean = self.addResourceCleanUp(self.client.release_address,40 PublicIp=ip)41 data = self.client.release_address(PublicIp=ip)42 self.cancelResourceCleanUp(res_clean)43 @base.skip_without_vpc()44 def test_invalid_delete_vpc_address(self):45 kwargs = {46 'Domain': 'vpc',47 }48 data = self.client.allocate_address(*[], **kwargs)49 ip = data['PublicIp']50 id = data['AllocationId']51 res_clean = self.addResourceCleanUp(self.client.release_address,52 AllocationId=id)53 self.assertEqual('vpc', data['Domain'])54 self.assertRaises('InvalidParameterCombination',55 self.client.release_address,56 PublicIp=ip, AllocationId=id)57 self.assertRaises('InvalidParameterValue',58 self.client.release_address,59 PublicIp=ip)60 data = self.client.release_address(AllocationId=id)61 self.cancelResourceCleanUp(res_clean)62 if CONF.aws.run_incompatible_tests:63 self.assertRaises('AuthFailure',64 self.client.release_address,65 PublicIp=ip)66 self.assertRaises('InvalidAllocationID.NotFound',67 self.client.release_address,68 AllocationId=id)69 kwargs = {70 "AllocationId": 'eipalloc-00000000',71 }72 self.assertRaises('InvalidAllocationID.NotFound',73 self.client.release_address,74 **kwargs)75 if CONF.aws.run_incompatible_tests:76 self.assertRaises('InvalidParameterValue',77 self.client.release_address,78 PublicIp='ip')79 def test_invalid_create_address(self):80 kwargs = {81 'Domain': 'invalid',82 }83 try:84 data = self.client.allocate_address(*[], **kwargs)85 allocation_id = data.get('AllocationId')86 if allocation_id:87 self.client.release_address(AllocationId=allocation_id)88 else:89 public_ip = data.get('PublicIp')90 self.client.release_address(PublicIp=public_ip)91 except botocore.exceptions.ClientError as e:92 self.assertEqual('InvalidParameterValue',93 e.response['Error']['Code'])94 @base.skip_without_vpc()95 def test_describe_vpc_addresses(self):96 kwargs = {97 'Domain': 'vpc',98 }99 data = self.client.allocate_address(*[], **kwargs)100 ip = data['PublicIp']101 id = data['AllocationId']102 res_clean = self.addResourceCleanUp(self.client.release_address,103 AllocationId=id)104 data = self.client.describe_addresses(*[], **{})105 for address in data['Addresses']:106 if address.get('AllocationId') == id:107 self.assertEqual('vpc', address['Domain'])108 self.assertEqual(ip, address['PublicIp'])109 break110 else:111 self.fail('Created address could not be found')112 kwargs = {113 'PublicIps': [ip],114 }115 data = self.client.describe_addresses(*[], **kwargs)116 self.assertEqual(1, len(data['Addresses']))117 self.assertEqual(id, data['Addresses'][0]['AllocationId'])118 kwargs = {119 'AllocationIds': [id],120 }121 data = self.client.describe_addresses(*[], **kwargs)122 self.assertEqual(1, len(data['Addresses']))123 self.assertEqual(ip, data['Addresses'][0]['PublicIp'])124 kwargs = {125 'PublicIps': ['invalidIp'],126 }127 self.assertRaises('InvalidParameterValue',128 self.client.describe_addresses,129 **kwargs)130 kwargs = {131 'AllocationIds': ['eipalloc-00000000'],132 }133 self.assertRaises('InvalidAllocationID.NotFound',134 self.client.describe_addresses,135 **kwargs)136 kwargs = {137 'Domain': 'vpc',138 }139 data = self.client.allocate_address(*[], **kwargs)140 id2 = data['AllocationId']141 res_clean2 = self.addResourceCleanUp(self.client.release_address,142 AllocationId=id2)143 kwargs = {144 'PublicIps': [ip],145 'AllocationIds': [id2],146 }147 data = self.client.describe_addresses(*[], **kwargs)148 self.assertEqual(2, len(data['Addresses']))149 # NOTE(andrey-mp): wait abit before releasing150 time.sleep(3)151 self.client.release_address(AllocationId=id)152 self.cancelResourceCleanUp(res_clean)153 self.client.release_address(AllocationId=id2)154 self.cancelResourceCleanUp(res_clean2)155 def test_describe_standard_addresses(self):156 data = self.client.allocate_address(*[], **{})157 ip = data['PublicIp']158 res_clean = self.addResourceCleanUp(self.client.release_address,159 PublicIp=ip)160 data = self.client.describe_addresses(*[], **{})161 for address in data['Addresses']:162 if address['PublicIp'] == ip:163 self.assertEqual('standard', address['Domain'])164 break165 else:166 self.fail('Created address could not be found')167 kwargs = {168 'PublicIps': [ip],169 }170 data = self.client.describe_addresses(*[], **kwargs)171 self.assertEqual(1, len(data['Addresses']))172 self.assertEqual(ip, data['Addresses'][0]['PublicIp'])173 kwargs = {174 'PublicIps': ['invalidIp'],175 }176 self.assertRaises('InvalidParameterValue',177 self.client.describe_addresses,178 PublicIps=['invalidIp'])179 # NOTE(andrey-mp): wait abit before releasing180 time.sleep(3)181 self.client.release_address(PublicIp=ip)182 self.cancelResourceCleanUp(res_clean)183 @base.skip_without_vpc()184 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")185 def test_associate_disassociate_vpc_addresses(self):186 aws_zone = CONF.aws.aws_zone187 base_net = '10.3.0.0'188 data = self.client.create_vpc(CidrBlock=base_net + '/20')189 vpc_id = data['Vpc']['VpcId']190 clean_vpc = self.addResourceCleanUp(self.client.delete_vpc,191 VpcId=vpc_id)192 self.get_vpc_waiter().wait_available(vpc_id)193 cidr = base_net + '/24'194 data = self.client.create_subnet(VpcId=vpc_id, CidrBlock=cidr,195 AvailabilityZone=aws_zone)196 subnet_id = data['Subnet']['SubnetId']197 clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,198 SubnetId=subnet_id)199 instance_id = self.run_instance(SubnetId=subnet_id)200 data = self.client.allocate_address(Domain='vpc')201 alloc_id = data['AllocationId']202 clean_a = self.addResourceCleanUp(self.client.release_address,203 AllocationId=alloc_id)204 self.assertRaises('Gateway.NotAttached',205 self.client.associate_address,206 InstanceId=instance_id, AllocationId=alloc_id)207 # Create internet gateway and try to associate again208 data = self.client.create_internet_gateway()209 gw_id = data['InternetGateway']['InternetGatewayId']210 clean_ig = self.addResourceCleanUp(self.client.delete_internet_gateway,211 InternetGatewayId=gw_id)212 data = self.client.attach_internet_gateway(VpcId=vpc_id,213 InternetGatewayId=gw_id)214 clean_aig = self.addResourceCleanUp(215 self.client.detach_internet_gateway,216 VpcId=vpc_id,217 InternetGatewayId=gw_id)218 self.prepare_route(vpc_id, gw_id)219 data = self.client.associate_address(InstanceId=instance_id,220 AllocationId=alloc_id)221 assoc_id = data['AssociationId']222 clean_aa = self.addResourceCleanUp(self.client.disassociate_address,223 AssociationId=assoc_id)224 self.get_address_assoc_waiter().wait_available(225 {'AllocationId': alloc_id})226 kwargs = {227 'AllocationIds': [alloc_id],228 }229 data = self.client.describe_addresses(*[], **kwargs)230 self.assertEqual(instance_id, data['Addresses'][0]['InstanceId'])231 data = self.client.disassociate_address(AssociationId=assoc_id)232 self.cancelResourceCleanUp(clean_aa)233 self.get_address_assoc_waiter().wait_delete({'AllocationId': alloc_id})234 # NOTE(andrey-mp): cleanup235 time.sleep(3)236 self.client.detach_internet_gateway(VpcId=vpc_id,237 InternetGatewayId=gw_id)238 self.cancelResourceCleanUp(clean_aig)239 self.client.delete_internet_gateway(InternetGatewayId=gw_id)240 self.cancelResourceCleanUp(clean_ig)241 self.client.release_address(AllocationId=alloc_id)242 self.cancelResourceCleanUp(clean_a)243 self.client.terminate_instances(InstanceIds=[instance_id])244 self.get_instance_waiter().wait_delete(instance_id)245 self.client.delete_subnet(SubnetId=subnet_id)246 self.cancelResourceCleanUp(clean_subnet)247 self.get_subnet_waiter().wait_delete(subnet_id)248 self.client.delete_vpc(VpcId=vpc_id)249 self.cancelResourceCleanUp(clean_vpc)250 self.get_vpc_waiter().wait_delete(vpc_id)251 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")252 def test_associate_disassociate_standard_addresses(self):253 instance_id = self.run_instance()254 data = self.client.allocate_address(*[], **{})255 ip = data['PublicIp']256 clean_a = self.addResourceCleanUp(self.client.release_address,257 PublicIp=ip)258 data = self.client.associate_address(InstanceId=instance_id,259 PublicIp=ip)260 clean_aa = self.addResourceCleanUp(self.client.disassociate_address,261 PublicIp=ip)262 self.get_address_assoc_waiter().wait_available({'PublicIp': ip})263 kwargs = {264 'PublicIps': [ip],265 }266 data = self.client.describe_addresses(*[], **kwargs)267 self.assertEqual(instance_id, data['Addresses'][0]['InstanceId'])268 data = self.client.disassociate_address(PublicIp=ip)269 self.cancelResourceCleanUp(clean_aa)270 self.get_address_assoc_waiter().wait_delete({'PublicIp': ip})271 time.sleep(3)272 data = self.client.release_address(PublicIp=ip)273 self.cancelResourceCleanUp(clean_a)274 data = self.client.terminate_instances(InstanceIds=[instance_id])275 self.get_instance_waiter().wait_delete(instance_id)276 @base.skip_without_vpc()277 def test_disassociate_not_associated_vpc_addresses(self):278 aws_zone = CONF.aws.aws_zone279 base_net = '10.3.0.0'280 data = self.client.create_vpc(CidrBlock=base_net + '/20')281 vpc_id = data['Vpc']['VpcId']282 clean_vpc = self.addResourceCleanUp(self.client.delete_vpc,283 VpcId=vpc_id)284 self.get_vpc_waiter().wait_available(vpc_id)285 cidr = base_net + '/24'286 data = self.client.create_subnet(VpcId=vpc_id, CidrBlock=cidr,287 AvailabilityZone=aws_zone)288 subnet_id = data['Subnet']['SubnetId']289 clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,290 SubnetId=subnet_id)291 data = self.client.allocate_address(Domain='vpc')292 alloc_id = data['AllocationId']293 ip = data['PublicIp']294 clean_a = self.addResourceCleanUp(self.client.release_address,295 AllocationId=alloc_id)296 assoc_id = 'eipassoc-00000001'297 self.assertRaises('InvalidAssociationID.NotFound',298 self.client.disassociate_address,299 AssociationId=assoc_id)300 self.assertRaises('InvalidParameterValue',301 self.client.disassociate_address,302 PublicIp=ip)303 self.client.release_address(AllocationId=alloc_id)304 self.cancelResourceCleanUp(clean_a)305 self.client.delete_subnet(SubnetId=subnet_id)306 self.cancelResourceCleanUp(clean_subnet)307 self.get_subnet_waiter().wait_delete(subnet_id)308 self.client.delete_vpc(VpcId=vpc_id)309 self.cancelResourceCleanUp(clean_vpc)310 self.get_vpc_waiter().wait_delete(vpc_id)311 def test_disassociate_not_associated_standard_addresses(self):312 data = self.client.allocate_address(Domain='standard')313 ip = data['PublicIp']314 clean_a = self.addResourceCleanUp(self.client.release_address,315 PublicIp=ip)316 data = self.client.disassociate_address(PublicIp=ip)317 data = self.client.release_address(PublicIp=ip)318 self.cancelResourceCleanUp(clean_a)319 @base.skip_without_vpc()320 @testtools.skipUnless(CONF.aws.run_incompatible_tests,321 'preliminary address association is not supported')322 def test_preliminary_associate_address(self):323 # NOTE(ft): AWS can associate an address to a subnet IP if the subnet324 # has no internet access325 vpc_id, subnet_id = self.create_vpc_and_subnet('10.3.0.0/20')326 self.create_and_attach_internet_gateway(vpc_id)327 data = self.client.allocate_address(Domain='vpc')328 alloc_id = data['AllocationId']329 self.addResourceCleanUp(self.client.release_address,330 AllocationId=alloc_id)331 data = self.client.create_network_interface(SubnetId=subnet_id)...

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