Fixes missing ec2 api address disassociate error on failure

Fixes ec2 api address disassociate so that the ec2 error
InvalidAssociationID.NotFound is returned when it is passed an
invalid association rather than returning success. Note this is
slightly different than the original bug report but the type
of failure has changed since the bug was originally filed.

Change-Id: I10034a2fed62d4e93bc384aef3ff594b66e285f2
Closes-Bug: 1179816
(cherry picked from commit 00d8c334bb)
This commit is contained in:
Chris Yeoh 2014-09-26 16:56:07 +09:30
parent c04b6ea0ef
commit f9fad7aa61
3 changed files with 11 additions and 3 deletions

View File

@ -1271,6 +1271,9 @@ class CloudController(object):
LOG.audit(_("Disassociate address %s"), public_ip, context=context)
self.network_api.disassociate_floating_ip(context, instance,
address=public_ip)
else:
msg = _('Floating ip is not associated.')
raise exception.InvalidAssociation(message=msg)
return {'return': "true"}
def run_instances(self, context, **kwargs):

View File

@ -1221,6 +1221,11 @@ class InstanceInfoCacheNotFound(NotFound):
"found.")
class InvalidAssociation(NotFound):
ec2_code = 'InvalidAssociationID.NotFound'
msg_fmt = _("Invalid association.")
class NodeNotFound(NotFound):
msg_fmt = _("Node %(node_id)s could not be found.")

View File

@ -368,9 +368,9 @@ class CloudTestCase(test.TestCase):
'pool': 'nova'})
self.cloud.allocate_address(self.context)
self.cloud.describe_addresses(self.context)
result = self.cloud.disassociate_address(self.context,
public_ip=address)
self.assertEqual(result['return'], 'true')
self.assertRaises(exception.InvalidAssociation,
self.cloud.disassociate_address,
self.context, public_ip=address)
db.floating_ip_destroy(self.context, address)
def test_describe_security_groups(self):