How to use enable_vpc_classic_link method in localstack

Best Python code snippet using localstack_python

test_vpcs.py

Source:test_vpcs.py Github

copy

Full Screen

...555 ],556 )557 assert vpc.tags == [{"Key": "name", "Value": "some-vpc"}]558@mock_ec2559def test_enable_vpc_classic_link():560 ec2 = boto3.resource("ec2", region_name="us-west-1")561 # Create VPC562 vpc = ec2.create_vpc(CidrBlock="10.1.0.0/16")563 response = ec2.meta.client.enable_vpc_classic_link(VpcId=vpc.id)564 assert response.get("Return").should.be.true565@mock_ec2566def test_enable_vpc_classic_link_failure():567 ec2 = boto3.resource("ec2", region_name="us-west-1")568 # Create VPC569 vpc = ec2.create_vpc(CidrBlock="10.90.0.0/16")570 response = ec2.meta.client.enable_vpc_classic_link(VpcId=vpc.id)571 assert response.get("Return").should.be.false572@mock_ec2573def test_disable_vpc_classic_link():574 ec2 = boto3.resource("ec2", region_name="us-west-1")575 # Create VPC576 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")577 ec2.meta.client.enable_vpc_classic_link(VpcId=vpc.id)578 response = ec2.meta.client.disable_vpc_classic_link(VpcId=vpc.id)579 assert response.get("Return").should.be.false580@mock_ec2581def test_describe_classic_link_enabled():582 ec2 = boto3.resource("ec2", region_name="us-west-1")583 # Create VPC584 vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")585 ec2.meta.client.enable_vpc_classic_link(VpcId=vpc.id)586 response = ec2.meta.client.describe_vpc_classic_link(VpcIds=[vpc.id])587 assert response.get("Vpcs")[0].get("ClassicLinkEnabled").should.be.true588@mock_ec2589def test_describe_classic_link_disabled():590 ec2 = boto3.resource("ec2", region_name="us-west-1")591 # Create VPC592 vpc = ec2.create_vpc(CidrBlock="10.90.0.0/16")593 response = ec2.meta.client.describe_vpc_classic_link(VpcIds=[vpc.id])594 assert response.get("Vpcs")[0].get("ClassicLinkEnabled").should.be.false595@mock_ec2596def test_describe_classic_link_multiple():597 ec2 = boto3.resource("ec2", region_name="us-west-1")598 # Create VPC599 vpc1 = ec2.create_vpc(CidrBlock="10.90.0.0/16")600 vpc2 = ec2.create_vpc(CidrBlock="10.0.0.0/16")601 ec2.meta.client.enable_vpc_classic_link(VpcId=vpc2.id)602 response = ec2.meta.client.describe_vpc_classic_link(VpcIds=[vpc1.id, vpc2.id])603 expected = [604 {"VpcId": vpc1.id, "ClassicLinkDnsSupported": False},605 {"VpcId": vpc2.id, "ClassicLinkDnsSupported": True},606 ]607 # Ensure response is sorted, because they can come in random order608 assert response.get("Vpcs").sort(key=lambda x: x["VpcId"]) == expected.sort(609 key=lambda x: x["VpcId"]610 )611@mock_ec2612def test_enable_vpc_classic_link_dns_support():613 ec2 = boto3.resource("ec2", region_name="us-west-1")614 # Create VPC615 vpc = ec2.create_vpc(CidrBlock="10.1.0.0/16")...

Full Screen

Full Screen

vpc_testcase.py

Source:vpc_testcase.py Github

copy

Full Screen

1########2# Copyright (c) 2015 GigaSpaces Technologies Ltd. All rights reserved3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# * See the License for the specific language governing permissions and14# * limitations under the License.15# Built-in Imports16import os17import testtools18# Third-party Imports19from boto.vpc import VPCConnection20from cloudify_aws import constants21from cloudify.mocks import MockCloudifyContext22VPC_TYPE = 'cloudify.aws.nodes.VPC'23SUBNET_TYPE = 'cloudify.aws.nodes.Subnet'24INTERNET_GATEWAY_TYPE = 'cloudify.aws.nodes.InternetGateway'25VPN_GATEWAY_TYPE = 'cloudify.aws.nodes.VPNGateway'26CUSTOMER_GATEWAY_TYPE = 'cloudify.aws.nodes.CustomerGateway'27ACL_TYPE = 'cloudify.aws.nodes.ACL'28DHCP_OPTIONS_TYPE = 'cloudify.aws.nodes.DHCPOptions'29ROUTE_TABLE_TYPE = 'cloudify.aws.nodes.RouteTable'30IGNORED_LOCAL_WORKFLOW_MODULES = (31 'worker_installer.tasks',32 'plugin_installer.tasks',33 'cloudify_agent.operations',34 'cloudify_agent.installer.operations',35)36class VpcTestCase(testtools.TestCase):37 def setUp(self):38 super(VpcTestCase, self).setUp()39 def tearDown(self):40 super(VpcTestCase, self).tearDown()41 def get_blueprint_path(self):42 if 'vpc' not in os.getcwd():43 blueprint_path = os.path.join(44 'cloudify_aws/vpc/tests/blueprint', 'blueprint.yaml')45 else:46 blueprint_path = os.path.join('blueprint', 'blueprint.yaml')47 return blueprint_path48 def get_blueprint_inputs(self, resources):49 inputs = {50 'existing_vpc_id':51 resources[VPC_TYPE].id,52 'existing_subnet_id':53 resources[SUBNET_TYPE].id,54 'existing_internet_gateway_id':55 resources[INTERNET_GATEWAY_TYPE].id,56 'existing_vpn_gateway_id':57 resources[VPN_GATEWAY_TYPE].id,58 'existing_network_acl_id':59 resources[ACL_TYPE].id,60 'existing_dhcp_options_id':61 resources[DHCP_OPTIONS_TYPE].id,62 'existing_customer_gateway_id':63 resources[CUSTOMER_GATEWAY_TYPE].id,64 'existing_route_table_id':65 resources[ROUTE_TABLE_TYPE].id66 }67 return inputs68 def create_client(self):69 return VPCConnection()70 def create_vpc(self, vpc_client, args=None):71 args = dict(cidr_block='11.0.0.0/24') if not args else args72 vpc = vpc_client.create_vpc(**args)73 return vpc74 def create_subnet(self, vpc_client, vpc, args=None):75 actual_args = dict(vpc_id=vpc.id, cidr_block='11.0.0.0/25')76 if args:77 actual_args.update(args)78 subnet = vpc_client.create_subnet(**actual_args)79 return subnet80 def create_internet_gateway(self, vpc_client):81 internet_gateway = vpc_client.create_internet_gateway()82 return internet_gateway83 def create_vpn_gateway(self, vpc_client, args=None):84 args = dict(type='ipsec.1') if not args else args85 vpn_gateway = vpc_client.create_vpn_gateway(**args)86 return vpn_gateway87 def create_network_acl(self, vpc_client, vpc, args=None):88 actual_args = dict(vpc_id=vpc.id)89 if args:90 actual_args.update(args)91 network_acl = vpc_client.create_network_acl(**actual_args)92 return network_acl93 def create_dhcp_options(self, vpc_client, args=None):94 if not args:95 args = dict(96 netbios_name_servers=['biosserver-b.com', 'biosserver-a.com'],97 netbios_node_type=298 )99 dhcp_options = vpc_client.create_dhcp_options(**args)100 return dhcp_options101 def create_customer_gateway(self, vpc_client, args=None):102 args = dict(103 type='ipsec.1', ip_address='11.0.0.7', bgp_asn=65000104 ) if not args else args105 customer_gateway = vpc_client.create_customer_gateway(**args)106 return customer_gateway107 def create_route_table(self, vpc_client, existing_vpc):108 args = dict(vpc_id=existing_vpc.id)109 return vpc_client.create_route_table(**args)110 def gateway_connected_to_vpc(self, vpc_client, source, target):111 if source.get(INTERNET_GATEWAY_TYPE):112 return vpc_client.attach_internet_gateway(113 source.get(INTERNET_GATEWAY_TYPE).id, target.id)114 elif source.get(VPN_GATEWAY_TYPE):115 return vpc_client.attach_vpn_gateway(116 source.get(VPN_GATEWAY_TYPE).id, target.id)117 def customer_gateway_connected_to_vpn_gateway(self,118 vpc_client,119 source,120 target):121 return vpc_client.create_vpn_connection(122 'ipsec.1', source.id, target.id)123 def network_acl_associated_with_subnet(self, vpc_client, source, target):124 return vpc_client.associate_network_acl(source.id, target.id)125 def dhcp_options_associated_with_vpc(self, vpc_client, source, target):126 return vpc_client.associate_dhcp_options(source.id, target.id)127 def route_table_associated_with_subnet(self, vpc_client, source, target):128 return vpc_client.associate_route_table(source.id, target.id)129 def route_to_gateway(self, vpc_client, source, target):130 actual_args = dict(131 route_table_id=source.id,132 destination_cidr_block='0.0.0.0/0',133 gateway_id=target.id134 )135 return vpc_client.create_route(**actual_args)136 def perform_relationships_on_all_existing_resources(self,137 vpc_client,138 existing):139 relationships = [140 self.gateway_connected_to_vpc(141 vpc_client,142 {143 INTERNET_GATEWAY_TYPE: existing[INTERNET_GATEWAY_TYPE]144 },145 existing[VPC_TYPE]),146 self.gateway_connected_to_vpc(147 vpc_client,148 {149 VPN_GATEWAY_TYPE: existing[VPN_GATEWAY_TYPE]150 },151 existing[VPC_TYPE]),152 self.customer_gateway_connected_to_vpn_gateway(153 vpc_client,154 existing[CUSTOMER_GATEWAY_TYPE],155 existing[VPN_GATEWAY_TYPE]),156 self.network_acl_associated_with_subnet(157 vpc_client,158 existing[ACL_TYPE],159 existing[SUBNET_TYPE]),160 self.dhcp_options_associated_with_vpc(161 vpc_client,162 existing[DHCP_OPTIONS_TYPE],163 existing[VPC_TYPE]),164 self.route_table_associated_with_subnet(165 vpc_client,166 existing[ROUTE_TABLE_TYPE],167 existing[SUBNET_TYPE]),168 self.route_to_gateway(169 vpc_client,170 existing[ROUTE_TABLE_TYPE],171 existing[INTERNET_GATEWAY_TYPE]172 )173 ]174 return relationships175 def create_all_existing_resources(self, vpc_client):176 existing_vpc = self.create_vpc(vpc_client)177 existing_subnet = self.create_subnet(vpc_client, existing_vpc)178 existing_internet_gateway = self.create_internet_gateway(vpc_client)179 existing_vpn_gateway = self.create_vpn_gateway(vpc_client)180 existing_acl = self.create_network_acl(vpc_client, existing_vpc)181 existing_dhcp_options = self.create_dhcp_options(vpc_client)182 existing_customer_gateway = self.create_customer_gateway(vpc_client)183 existing_route_table = \184 self.create_route_table(vpc_client, existing_vpc)185 resources = {186 VPC_TYPE: existing_vpc,187 SUBNET_TYPE: existing_subnet,188 INTERNET_GATEWAY_TYPE: existing_internet_gateway,189 VPN_GATEWAY_TYPE: existing_vpn_gateway,190 ACL_TYPE: existing_acl,191 DHCP_OPTIONS_TYPE: existing_dhcp_options,192 CUSTOMER_GATEWAY_TYPE: existing_customer_gateway,193 ROUTE_TABLE_TYPE: existing_route_table194 }195 return resources196 def get_current_list_of_used_resources(self, vpc_client):197 resources = {198 VPC_TYPE: vpc_client.get_all_vpcs(),199 SUBNET_TYPE: vpc_client.get_all_subnets(),200 INTERNET_GATEWAY_TYPE: vpc_client.get_all_internet_gateways(),201 VPN_GATEWAY_TYPE: vpc_client.get_all_vpn_gateways(),202 ACL_TYPE: vpc_client.get_all_network_acls(),203 DHCP_OPTIONS_TYPE: vpc_client.get_all_dhcp_options(),204 CUSTOMER_GATEWAY_TYPE: vpc_client.get_all_customer_gateways(),205 ROUTE_TABLE_TYPE: vpc_client.get_all_route_tables()206 }207 return resources208 def mock_node_context(self, test_name,209 node_properties=None, relationships=None):210 ctx = MockCloudifyContext(211 node_id=test_name,212 properties=node_properties,213 deployment_id='d1'214 )215 ctx.instance.relationship = [] if not relationships else relationships216 return ctx217 def get_mock_node_properties(self, node_template_properties=None):218 test_properties = {219 constants.AWS_CONFIG_PROPERTY: {},220 'use_external_resource': False,221 'resource_id': 'test_security_group',222 }223 if node_template_properties:224 test_properties.update(node_template_properties)225 return test_properties226 def vpc_node_template_properties(self, inputs):227 return {228 'cidr_block':229 inputs.get('cidr_block')230 if 'cidr_block' in inputs.keys() else '10.0.0.0/24',231 'instance_tenancy':232 inputs.get('instance_tenancy')233 if 'instance_tenancy' in inputs.keys() else 'default',234 'enable_vpc_classic_link':235 inputs.get('enable_vpc_classic_link')236 if 'enable_vpc_classic_link' in inputs.keys() else False237 }238 def subnet_node_template_properties(self, inputs):239 return {240 'cidr_block':241 inputs.get('cidr_block')242 if 'cidr_block' in inputs.keys() else '10.0.0.0/25',243 'availability_zone':244 inputs.get('availability_zone')245 if 'availability_zone' in inputs.keys() else ''246 }247 def network_acl_node_template_properties(self, inputs):248 return {249 'acl_network_entries':250 [entry for entry in inputs.get('entries')]251 if 'entries' in inputs.keys() else []252 }253 def vpn_gateway_node_template_properties(self, inputs):254 return {255 'type': 'ipsec.1',256 'availability_zone':257 inputs.get('availability_zone')258 if 'availability_zone' in inputs.keys() else ''259 }260 def customer_gateway_node_template_properties(self, inputs):261 return {262 'type': 'ipsec.1',263 'ip_address':264 inputs.get('ip_address')265 if 'ip_address' in inputs.keys() else '10.0.0.7',266 'bgp_asn': '35000'267 }268 def dhcp_options_node_template_properties(self, inputs):269 return {270 'domain_name':271 inputs.get('domain_name')272 if 'domain_name' in inputs.keys() else 'example.com',273 'domain_name_servers':274 [dns for dns in inputs.get('domain_name_servers')]275 if 'domain_name_servers' in inputs.keys() else [],276 'ntp_servers':277 [ntp for ntp in inputs.get('ntp_servers')]278 if 'ntp_servers' in inputs.keys() else [],279 'netbios_name_servers':280 [nbns for nbns in inputs.get('netbios_name_servers')]281 if 'netbios_name_servers' in inputs.keys() else [],282 'netbios_node_type': 2...

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