Exemplo n.º 1
0
    def test_requests_and_accepts_a_peering_connection(self):
        requester_account_id = mocks.randoms.account_id()
        accepter_account_id = mocks.randoms.account_id()
        region = mocks.randoms.region()

        vpc1 = VPC(mocks.build_vpc_response_mock(), requester_account_id,
                   region)
        vpc2 = VPC(mocks.build_vpc_response_mock(), accepter_account_id,
                   region)

        requester_ec2_gateway = mocks.EC2Gateway(requester_account_id, region)
        accepter_ec2_gateway = mocks.EC2Gateway(accepter_account_id, region)
        ec2_gateways = mocks.EC2Gateways(
            [requester_ec2_gateway, accepter_ec2_gateway])

        logger = Mock()

        peering_connection = Mock()
        vpc1.request_vpc_peering_connection = Mock(
            return_value=peering_connection)

        vpc_peering_connections = Mock(
            name='VPC peering connections for region: {}'.format(region))
        matching_vpc_peering_connection = Mock(
            name='Matching VPC peering connection')

        accepter_ec2_gateway.resource().vpc_peering_connections = \
            vpc_peering_connections
        vpc_peering_connections.filter = Mock(
            name="Filter VPC peering connections for region: {}".format(
                region),
            return_value=iter([matching_vpc_peering_connection]))

        vpc_peering_relationship = VPCPeeringRelationship(ec2_gateways,
                                                          logger,
                                                          between=[vpc1, vpc2])
        vpc_peering_relationship.provision()

        vpc1.request_vpc_peering_connection. \
            assert_called_with(
            PeerOwnerId=accepter_account_id,
            PeerVpcId=vpc2.id,
            PeerRegion=region)
        matching_vpc_peering_connection.accept. \
            assert_called()
Exemplo n.º 2
0
    def test_logs_that_accepting_peering_connection_failed(self):
        region = mocks.randoms.region()
        account_id = mocks.randoms.account_id()

        vpc1 = VPC(mocks.build_vpc_response_mock(), account_id, region)
        vpc2 = VPC(mocks.build_vpc_response_mock(), account_id, region)

        ec2_gateway = mocks.EC2Gateway(account_id, region)
        ec2_gateways = mocks.EC2Gateways([ec2_gateway])

        logger = Mock()

        vpc_peering_connections = Mock(name='VPC peering connections')
        vpc_peering_connection = Mock(name='VPC peering connection')

        vpc_peering_connection.id = Mock(name='VPC peering connection ID')
        vpc_peering_connection.delete = \
            Mock(name='Delete VPC peering connection')

        ec2_gateway.resource(
        ).vpc_peering_connections = vpc_peering_connections
        vpc_peering_connections.filter = Mock(
            name="Filter VPC peering connections",
            return_value=iter([vpc_peering_connection]))

        accept_error = ClientError({'Error': {'Code': '123'}}, 'something')
        vpc1.request_vpc_peering_connection = Mock(
            return_value=vpc_peering_connection)
        vpc_peering_connection.accept = Mock(side_effect=accept_error)

        vpc_peering_relationship = VPCPeeringRelationship(ec2_gateways,
                                                          logger,
                                                          between=[vpc1, vpc2])
        vpc_peering_relationship.provision()

        logger.warn.assert_any_call(
            "Could not accept peering connection between: '%s' and: '%s'. "
            "Error was: %s", vpc1.id, vpc2.id, accept_error)
Exemplo n.º 3
0
    def test_deletes_created_peering_connection_on_exception(self):
        region = mocks.randoms.region()
        account_id = mocks.randoms.account_id()

        vpc1 = VPC(mocks.build_vpc_response_mock(), account_id, region)
        vpc2 = VPC(mocks.build_vpc_response_mock(), account_id, region)

        ec2_gateway = mocks.EC2Gateway(account_id, region)
        ec2_gateways = mocks.EC2Gateways([ec2_gateway])

        logger = Mock()

        vpc_peering_connections = Mock(name='VPC peering connections')
        vpc_peering_connection = Mock(name='VPC peering connection')

        vpc_peering_connection.id = Mock(name='VPC peering connection ID')
        vpc_peering_connection.delete = \
            Mock(name='Delete VPC peering connection')

        ec2_gateway.resource(
        ).vpc_peering_connections = vpc_peering_connections
        vpc_peering_connections.filter = Mock(
            name="Filter VPC peering connections",
            return_value=iter([vpc_peering_connection]))

        vpc1.request_vpc_peering_connection = Mock(
            return_value=vpc_peering_connection)
        vpc_peering_connection.accept = Mock(
            side_effect=ClientError({'Error': {
                'Code': '123'
            }}, 'something'))

        vpc_peering_relationship = VPCPeeringRelationship(ec2_gateways,
                                                          logger,
                                                          between=[vpc1, vpc2])
        vpc_peering_relationship.provision()

        vpc_peering_connection.delete.assert_called()