Best Python code snippet using localstack_python
ec2_vpc_eigw.py
Source:ec2_vpc_eigw.py
...115 while retries > 0:116 retries = retries - 1117 sleep(pause)118 try:119 check_resp = client.describe_egress_only_internet_gateways(EgressOnlyInternetGatewayIds=eigw['EgressOnlyInternetGatewayId'])120 except ClientError as err:121 module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))122 if check_resp['EgressOnlyInternetGateways'][0]['Attachments'][0]['State'] == 'attached':123 return {'changed': True, 'gateway_id': eigw['EgressOnlyInternetGatewayId']}124 pause = pause * 2125 else:126 # EIGW gave back a bad attachment state so we error out127 module.fail_json(msg='Unable to create and attach Egress Only Internet Gateway to VPCId: {0}. Bad Attachment State: {1}'.format(vpc_id, state))128@AWSRetry.backoff()129def describe_eigws(module, client, vpc_id):130 """131 Describe EIGWS132 module : AnsibleModule object133 client : boto3 client connection object134 vpc_id : ID of the VPC we are operating on135 """136 try:137 response = client.describe_egress_only_internet_gateways()138 except ClientError as err:139 module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))140 if len(response['EgressOnlyInternetGateways']) == 0:141 return None142 for eigw in response['EgressOnlyInternetGateways']:143 attached_vpc = eigw['Attachments'][0]['VpcId']144 state = eigw['Attachments'][0]['State']145 if attached_vpc == vpc_id and state in ('attached', 'attaching'):146 return eigw['EgressOnlyInternetGatewayId']147 else:148 return None149def main():150 argument_spec = ec2_argument_spec()151 argument_spec.update(dict(...
egress_only_internet_gateways.py
Source:egress_only_internet_gateways.py
...9 vpc_id=vpc_id, tags=tags10 )11 template = self.response_template(CREATE_EGRESS_ONLY_IGW_RESPONSE)12 return template.render(egress_only_igw=egress_only_igw)13 def describe_egress_only_internet_gateways(self):14 egress_only_igw_ids = self._get_multi_param("EgressOnlyInternetGatewayId")15 filters = filters_from_querystring(self.querystring)16 egress_only_igws = self.ec2_backend.describe_egress_only_internet_gateways(17 egress_only_igw_ids, filters,18 )19 template = self.response_template(DESCRIBE_EGRESS_ONLY_IGW_RESPONSE)20 return template.render(egress_only_igws=egress_only_igws)21 def delete_egress_only_internet_gateway(self):22 egress_only_igw_id = self._get_param("EgressOnlyInternetGatewayId")23 self.ec2_backend.delete_egress_only_internet_gateway(24 gateway_id=egress_only_igw_id25 )26 template = self.response_template(DELETE_EGRESS_ONLY_IGW_RESPONSE)27 return template.render()28CREATE_EGRESS_ONLY_IGW_RESPONSE = """<CreateEgressOnlyInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">29 <requestId>c617595f-6c29-4a00-a941-example</requestId>30 <egressOnlyInternetGateway>...
test_egress_only_internet_gateway.py
Source:test_egress_only_internet_gateway.py
1import unittest2from cloudwanderer import URN3from ..helpers import CloudWandererCalls, ExpectedCall, MultipleResourceScenario, NoMotoMock, SingleResourceScenario4class TestEgressOnlyInternetGateways(NoMotoMock, unittest.TestCase):5 egress_only_internet_gateway_payload = {6 "Attachments": [{"State": "attached", "VpcId": "vpc-11111111"}],7 "EgressOnlyInternetGatewayId": "eigw-11111111111111111",8 "Tags": [{"Key": "Name", "Value": "test-eigw"}],9 }10 mock = {11 "ec2": {12 "describe_egress_only_internet_gateways.return_value": {13 "EgressOnlyInternetGateways": [egress_only_internet_gateway_payload]14 },15 }16 }17 single_resource_scenarios = [18 SingleResourceScenario(19 urn=URN.from_string(20 "urn:aws:123456789012:eu-west-2:ec2:egress_only_internet_gateway:eigw-11111111111111111"21 ),22 expected_results=[egress_only_internet_gateway_payload],23 expected_call=ExpectedCall(24 "ec2",25 "describe_egress_only_internet_gateways",26 [],27 {"EgressOnlyInternetGatewayIds": ["eigw-11111111111111111"]},28 ),29 )30 ]31 multiple_resource_scenarios = [32 MultipleResourceScenario(33 arguments=CloudWandererCalls(34 regions=["eu-west-2"], service_names=["ec2"], resource_types=["egress_only_internet_gateway"]35 ),36 expected_results=[egress_only_internet_gateway_payload],37 )...
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!!