From 881a93473c32a7c7e23a8e6dcede8394053408c6 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 20 Dec 2012 20:13:37 -0800 Subject: Eliminate race conditions in floating association This makes associating and disassociating floating ips atomic and idempotent. This means multiple concurrent messages will not leave behind iptables rules and concurrent request will not cause odd failures. Fixes bug 1092762 and bug 1092761. Change-Id: Idbcad6c1d2a3d4881cf7180b848ed3844fac4054 --- nova/tests/network/test_manager.py | 2 +- nova/tests/test_db_api.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index 0e441eef8..4b266055b 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -669,7 +669,7 @@ class VlanNetworkTestCase(test.TestCase): is_admin=False) def fake1(*args, **kwargs): - pass + return '10.0.0.1' # floating ip that's already associated def fake2(*args, **kwargs): diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 29bce8bf5..4d6471a3f 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -246,6 +246,21 @@ class DbApiTestCase(test.TestCase): self.assertEqual(0, len(results)) db.instance_update(ctxt, instance['uuid'], {"task_state": None}) + def test_multi_associate_disassociate(self): + ctxt = context.get_admin_context() + values = {'address': 'floating'} + floating = db.floating_ip_create(ctxt, values) + values = {'address': 'fixed'} + fixed = db.fixed_ip_create(ctxt, values) + res = db.floating_ip_fixed_ip_associate(ctxt, floating, fixed, 'foo') + self.assertEqual(res, fixed) + res = db.floating_ip_fixed_ip_associate(ctxt, floating, fixed, 'foo') + self.assertEqual(res, None) + res = db.floating_ip_disassociate(ctxt, floating) + self.assertEqual(res, fixed) + res = db.floating_ip_disassociate(ctxt, floating) + self.assertEqual(res, None) + def test_network_create_safe(self): ctxt = context.get_admin_context() values = {'host': 'localhost', 'project_id': 'project1'} -- cgit