Esempio n. 1
0
    def test_invalid_source_resource(self):
        """ Tests that NonRecoverableError: Instance NotFound is
            raised when a source instance that is not in the user's
            EC2 account is provided to the detach function NEW
        """

        ctx = self.mock_relationship_context('test_invalid_source_resource')
        current_ctx.set(ctx=ctx)
        ctx.target.instance.runtime_properties['aws_resource_id'] = '0.0.0.0'
        ctx.source.instance.runtime_properties['public_ip_address'] = '0.0.0.0'

        with mock.patch(
                'cloudify_aws.base.AwsBase.execute') \
                as mock_execute:
            mock_execute.side_effect = EC2ResponseError(
                    mock.Mock(return_value={'status': 404}),
                    'InvalidInstanceID.NotFound')
            with mock.patch(
                    'boto.ec2.connection.EC2Connection.get_all_instances') \
                    as mock_get_all_instances:

                with self.assertRaisesRegexp(
                        EC2ResponseError,
                        'InvalidInstanceID.NotFound'):
                    mock_get_all_instances.side_effect = EC2ResponseError(
                            mock.Mock(return_value={'status': 404}),
                            'InvalidInstanceID.NotFound')
                    output = elasticip.ElasticIPInstanceConnection()\
                        .get_source_resource()
                    self.assertIsNone(output)
    def test_good_address_associate_vpc_elastic_ip(self):
        """ Tests that associate runs when clean. """

        ctx = self.mock_relationship_context('test_good_address_associate')
        ctx.source.node.properties['domain'] = 'vpc'
        current_ctx.set(ctx=ctx)
        address = self.get_address()
        instance_id = self.get_instance_id()
        ctx.target.instance.runtime_properties['aws_resource_id'] = \
            address.public_ip
        ctx.source.instance.runtime_properties['aws_resource_id'] = \
            instance_id
        elasticip.ElasticIPInstanceConnection().associate(ctx=ctx)
    def test_good_address_disassociate(self):
        """ Tests that disassociate runs when clean. """

        ctx = self.mock_relationship_context('test_good_address_detach')
        current_ctx.set(ctx=ctx)
        address = self.get_address()
        instance_id = self.get_instance_id()

        ctx.target.instance.runtime_properties['aws_resource_id'] = \
            address.public_ip
        ctx.source.instance.runtime_properties['instance_id'] = instance_id
        ctx.target.instance.runtime_properties['instance_id'] = instance_id
        ctx.source.instance.runtime_properties['ip'] = address.public_ip
        elasticip.ElasticIPInstanceConnection().disassociate(ctx=ctx)
Esempio n. 4
0
    def test_bad_address_associate(self):
        """ Tests that when an address that is in the user's
            EC2 account is provided to the attach function
            no errors are raised
        """

        ctx = self.mock_relationship_context('test_bad_address_associate')
        current_ctx.set(ctx=ctx)
        instance_id = self.get_instance_id()
        ctx.target.instance.runtime_properties['aws_resource_id'] = '127.0.0.1'
        ctx.source.instance.runtime_properties['aws_resource_id'] = \
            instance_id
        ex = self.assertRaises(NonRecoverableError,
                               elasticip.ElasticIPInstanceConnection()
                               .associate, ctx=ctx)
        ctx.source.instance.runtime_properties['public_ip_address'] = \
            '127.0.0.1'
        self.assertIn('InvalidAddress.NotFound', ex.message)
 def create_elasticipinstanceconnection_for_checking(self):
     return elasticip.ElasticIPInstanceConnection()