From bed296b17ded5012d6651957df387336c10dd002 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 9 Jul 2012 16:26:55 -0700 Subject: associate_floating_ip an ip already in use Fixes bug 10014860 to be compliant w/ AWS EC2 spec instead of return exception.FloatingIpAssociated, disassociate from old fixed_ip and associate to new fixed_ip. Change-Id: I54ab3492092940dbb01f2787cc329a0162698568 --- nova/network/manager.py | 4 ++-- nova/tests/network/test_manager.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index d4937d90b..00bb15346 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -493,9 +493,9 @@ class FloatingIP(object): # make sure project ownz this floating ip (allocated) self._floating_ip_owned_by_project(context, floating_ip) - # make sure floating ip isn't already associated + # disassociate any already associated if floating_ip['fixed_ip_id']: - raise exception.FloatingIpAssociated(address=floating_address) + self.disassociate_floating_ip(context, floating_address) fixed_ip = self.db.fixed_ip_get_by_address(context, fixed_address) diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index b3a5ef0ea..a5a6b9548 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -670,6 +670,9 @@ class VlanNetworkTestCase(test.TestCase): raise exception.ProcessExecutionError('', 'Cannot find device "em0"\n') + def fake9(*args, **kwargs): + raise test.TestingException() + # raises because interface doesn't exist self.stubs.Set(self.network.db, 'floating_ip_fixed_ip_associate', @@ -687,7 +690,8 @@ class VlanNetworkTestCase(test.TestCase): # raises because floating_ip is already associated to a fixed_ip self.stubs.Set(self.network.db, 'floating_ip_get_by_address', fake2) - self.assertRaises(exception.FloatingIpAssociated, + self.stubs.Set(self.network, 'disassociate_floating_ip', fake9) + self.assertRaises(test.TestingException, self.network.associate_floating_ip, ctxt, mox.IgnoreArg(), -- cgit