コード例 #1
0
    def test_constructs_peering_routes_for_peering_relationship_and_vpcs(self):
        vpc1 = mocks.build_vpc_response_mock(name="VPC 1")
        vpc2 = mocks.build_vpc_response_mock(name="VPC 2")

        account_id = randoms.account_id()
        region = randoms.region()

        ec2_gateways = mocks.EC2Gateways([mocks.EC2Gateway(account_id, region)])
        logger = Mock(name="Logger")

        vpc_link = VPCLink(
            ec2_gateways,
            logger,
            between=[vpc1, vpc2],
            routes=[[vpc1, vpc2],
                    [vpc2, vpc1]])
        vpc_peering_relationship = vpc_link.peering_relationship

        self.assertEqual(
            vpc_link.peering_routes,
            [
                VPCPeeringRoute(
                    ec2_gateways,
                    logger,
                    between=[vpc1, vpc2],
                    peering_relationship=vpc_peering_relationship),
                VPCPeeringRoute(
                    ec2_gateways,
                    logger,
                    between=[vpc2, vpc1],
                    peering_relationship=vpc_peering_relationship)
            ])
コード例 #2
0
    def test_ignores_missing_dependencies(self):
        account_id = randoms.account_id()
        region = randoms.region()
        vpc1_id = randoms.vpc_id()

        vpc_1_response = mocks.build_vpc_response_mock(
            name='VPC 1',
            id=vpc1_id,
            tags=builders.build_vpc_tags(
                component="thing1",
                deployment_identifier="gold",
                dependencies=["thing2-silver", "thing3-bronze"]))
        vpc_2_response = mocks.build_vpc_response_mock(
            name='VPC 2',
            tags=builders.build_vpc_tags(component="thing2",
                                         deployment_identifier="silver",
                                         dependencies=[]))

        vpc_1 = VPC(vpc_1_response, account_id, region)
        vpc_2 = VPC(vpc_2_response, account_id, region)

        ec2_gateway = mocks.EC2Gateway(account_id, region)
        ec2_gateways = mocks.EC2Gateways([ec2_gateway])
        logger = Mock(name="Logger")

        ec2_gateway.resource().vpcs.all = Mock(
            name="All VPCs", return_value=[vpc_1_response, vpc_2_response])

        vpc_links = VPCLinks(ec2_gateways, logger)
        resolved_vpc_links = vpc_links.resolve_for(account_id, vpc1_id)

        self.assertEqual(len(resolved_vpc_links), 1)
        self.assertEqual(
            resolved_vpc_links, {
                VPCLink(ec2_gateways,
                        logger,
                        between=[vpc_1, vpc_2],
                        routes=[[vpc_1, vpc_2]])
            })
コード例 #3
0
    def test_resolves_using_multiple_ec2_gateways(self):
        region_1 = randoms.region()
        region_2 = randoms.region()
        account_id_1 = randoms.account_id()
        account_id_2 = randoms.account_id()

        target_vpc_id = randoms.vpc_id()

        target_vpc_response = mocks.build_vpc_response_mock(
            id=target_vpc_id,
            name="Target VPC",
            tags=builders.build_vpc_tags(
                component='thing1',
                deployment_identifier='gold',
                dependencies=['thing2-silver', 'thing3-bronze']))

        dependent_dependency_vpc_response = mocks.build_vpc_response_mock(
            name='Dependent Dependency VPC',
            tags=builders.build_vpc_tags(component='thing2',
                                         deployment_identifier='silver',
                                         dependencies=['thing1-gold']))
        standard_dependency_vpc_response = mocks.build_vpc_response_mock(
            name='Standard Dependency VPC',
            tags=builders.build_vpc_tags(component='thing3',
                                         deployment_identifier='bronze',
                                         dependencies=[]))

        standard_dependent_vpc_response = mocks.build_vpc_response_mock(
            name='Standard Dependent VPC',
            tags=builders.build_vpc_tags(component='thing4',
                                         deployment_identifier='lead',
                                         dependencies=['thing1-gold']))

        other_vpc_response = mocks.build_vpc_response_mock(
            name='Other VPC',
            tags=builders.build_vpc_tags(component='other-thing',
                                         deployment_identifier='copper',
                                         dependencies=[]))

        target_vpc = VPC(target_vpc_response, account_id_1, region_1)
        dependent_dependency_vpc = \
            VPC(dependent_dependency_vpc_response, account_id_1, region_1)
        standard_dependency_vpc = \
            VPC(standard_dependency_vpc_response, account_id_2, region_2)
        standard_dependent_vpc = \
            VPC(standard_dependent_vpc_response, account_id_1, region_1)

        ec2_gateway_1 = mocks.EC2Gateway(account_id_1, region_1)
        ec2_gateway_2 = mocks.EC2Gateway(account_id_2, region_2)
        ec2_gateways = mocks.EC2Gateways([ec2_gateway_1, ec2_gateway_2])
        logger = Mock(name="Logger")

        ec2_gateway_1.resource().vpcs.all = Mock(
            name="All VPCs in account %s, region %s" %
            (account_id_1, region_1),
            return_value=[
                dependent_dependency_vpc_response, target_vpc_response,
                standard_dependent_vpc_response
            ])
        ec2_gateway_2.resource().vpcs.all = Mock(
            name='All VPCs in account %s, region %s' %
            (account_id_2, region_2),
            return_value=[
                standard_dependency_vpc_response, other_vpc_response
            ])

        vpc_links = VPCLinks(ec2_gateways, logger)
        resolved_vpc_links = vpc_links.resolve_for(account_id_1, target_vpc_id)

        self.assertEqual(
            resolved_vpc_links, {
                VPCLink(ec2_gateways,
                        logger,
                        between=[target_vpc, dependent_dependency_vpc],
                        routes=[[target_vpc, dependent_dependency_vpc],
                                [dependent_dependency_vpc, target_vpc]]),
                VPCLink(ec2_gateways,
                        logger,
                        between=[target_vpc, standard_dependency_vpc],
                        routes=[[target_vpc, standard_dependency_vpc]]),
                VPCLink(ec2_gateways,
                        logger,
                        between=[standard_dependent_vpc, target_vpc],
                        routes=[[standard_dependent_vpc, target_vpc]])
            })
コード例 #4
0
 def __vpc_link(self, between, routes):
     return VPCLink(self.ec2_gateways, self.logger, between, routes)