def test_bad_address_external_resource(self):

        ctx = self.mock_ctx('test_bad_address_external_resource')
        current_ctx.set(ctx=ctx)
        ctx.node.properties['use_external_resource'] = True
        ctx.node.properties['resource_id'] = '127.0.0.1'
        ex = self.assertRaises(
            NonRecoverableError,
            elasticip.ElasticIP().raise_forbidden_external_resource, ctx)
        self.assertIn('is not in this account', ex.message)
    def test_validation(self):
        """ Tests that creation_validation raises an error
        the Elastic IP doesn't exist in the account and use_external_resource
        is true.
        """

        ctx = self.mock_elastic_ip_node('test_allocate')
        ctx.node.properties['use_external_resource'] = True
        ctx.node.properties['resource_id'] = '127.0.0.1'
        current_ctx.set(ctx=ctx)
        ex = self.assertRaises(NonRecoverableError,
                               elasticip.ElasticIP().creation_validation)
        self.assertIn('elasticip does not exist', ex.message)
    def test_validation_not_external(self):
        """ Tests that creation_validation raises an error
        the Elastic IP exist in the account and use_external_resource
        is false.
        """

        ctx = self.mock_elastic_ip_node('test_validation_not_external')
        current_ctx.set(ctx=ctx)
        address = self.get_address()
        ctx.node.properties['use_external_resource'] = False
        ctx.node.properties['resource_id'] = address.public_ip
        ex = self.assertRaises(NonRecoverableError,
                               elasticip.ElasticIP().creation_validation)
        self.assertIn('Not external resource, but the supplied', ex.message)
    def test_bad_address_release(self):
        """ tests that release raises an error when
        the address does not exist in the users account.
        """

        ctx = self.mock_ctx('test_bad_address_release')
        current_ctx.set(ctx=ctx)
        ctx.instance.runtime_properties['aws_resource_id'] = \
            '127.0.0.1'
        ex = self.assertRaises(NonRecoverableError,
                               elasticip.ElasticIP().delete,
                               ctx=ctx)
        self.assertIn('Unable to release elasticip. Elasticip not in account.',
                      ex.message)
 def create_elasticip_for_checking(self):
     return elasticip.ElasticIP()