From 3b9f08072abe9f92d292e9fa5998c62a766b01f3 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 21 Dec 2012 16:04:16 -0800 Subject: Ignore double messages to associate the same ip Associating an ip removes the old association and adds a new one. If we are already associated to the target ip, then we can avoid sending extra messages and making db calls. The current possibility of a double send contributes to bug 1092762. Change-Id: I5a40177fcd05b150f39e3144c1d521bd979b358b --- nova/network/manager.py | 3 +++ nova/tests/network/test_manager.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index 97d4fa10d..5189b40c7 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -543,6 +543,9 @@ class FloatingIP(object): # find previously associated instance fixed_ip = self.db.fixed_ip_get(context, floating_ip['fixed_ip_id']) + if fixed_ip['address'] == fixed_address: + # NOTE(vish): already associated to this address + return orig_instance_uuid = fixed_ip['instance_uuid'] self.disassociate_floating_ip(context, floating_address) diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index 0e441eef8..c2aa1dbbb 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -740,15 +740,19 @@ class VlanNetworkTestCase(test.TestCase): self.stubs.Set(self.network, 'disassociate_floating_ip', fake9) def fake_fixed_ip_get(context, fixed_ip_id): - return {'instance_uuid': 'fake_uuid'} + return {'address': 'old', 'instance_uuid': 'fake_uuid'} self.stubs.Set(self.network.db, 'fixed_ip_get', fake_fixed_ip_get) + # doesn't raise because we exit early if the address is the same + self.network.associate_floating_ip(ctxt, mox.IgnoreArg(), 'old') + + # raises because we call disassociate which is mocked self.assertRaises(test.TestingException, self.network.associate_floating_ip, ctxt, mox.IgnoreArg(), - mox.IgnoreArg()) + 'new') self.stubs.Set(self.network.db, 'floating_ip_get_by_address', fake3) -- cgit