def test_disassociate_external_elasticip_or_instance(self): """ This tests that this function returns False if use_external_resource is false. """ ctx = self.mock_relationship_context( 'test_disassociate_external_elasticip_or_instance') current_ctx.set(ctx=ctx) ctx.source.node.properties['use_external_resource'] = False output = \ elasticip._disassociate_external_elasticip_or_instance() self.assertEqual(False, output)
def test_disassociate_external_elasticip_or_instance_external(self): ctx = self.mock_relationship_context( 'test_disassociate_external_elasticip_or_instance_external') current_ctx.set(ctx=ctx) ctx.source.node.properties['use_external_resource'] = True ctx.target.node.properties['use_external_resource'] = True ctx.source.instance.runtime_properties['public_ip_address'] = \ '127.0.0.1' output = \ elasticip._disassociate_external_elasticip_or_instance() self.assertEqual(True, output) self.assertNotIn('public_ip_address', ctx.source.instance.runtime_properties)
def test_disassociate_external_elasticip_or_instance_external(self): ctx = self.mock_relationship_context( 'test_disassociate_external_elasticip_or_instance_external') current_ctx.set(ctx=ctx) ctx.source.node.properties['use_external_resource'] = True ctx.target.node.properties['use_external_resource'] = True ctx.source.instance.runtime_properties['public_ip_address'] = \ '127.0.0.1' output = \ elasticip._disassociate_external_elasticip_or_instance() self.assertEqual(True, output) self.assertNotIn( 'public_ip_address', ctx.source.instance.runtime_properties)
def test_disassociate_external_elasticip(self): """ Tests that when an address that is in the user's EC2 account is provided to the disassociate function and use_external_resource is true no errors are raised """ ctx = self.mock_relationship_context( 'test_disassociate_external_elasticip') current_ctx.set(ctx=ctx) address = self.get_address() instance_id = self.get_instance_id() ctx.target.node.properties['use_external_resource'] = False ctx.target.node.properties['resource_id'] = address.public_ip ctx.source.node.properties['use_external_resource'] = False ctx.source.node.properties['resource_id'] = instance_id ctx.source.instance.runtime_properties['aws_resource_id'] = \ instance_id output = \ elasticip._disassociate_external_elasticip_or_instance() self.assertEqual(False, output)