From 6cfc02531f92c2e98eb947bc7a46d6bed0158d82 Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Wed, 8 May 2013 12:33:29 +0930 Subject: [PATCH] Fixes KeyError bug with network api associate Fixes bug in network api associate function where it would always raise a KeyError when associating or disassociating a project. Fixes bug 1171284 Change-Id: Iae0e57e0a961b8a3377b38dad72094188755a3e8 --- nova/network/api.py | 2 -- nova/tests/network/test_api.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/nova/network/api.py b/nova/network/api.py index b8baf9810e2..491efe759b3 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -346,7 +346,6 @@ def add_network_to_project(self, context, project_id, network_uuid=None): def associate(self, context, network_uuid, host=_sentinel, project=_sentinel): """Associate or disassociate host or project to network.""" - associations = {} network_id = self.get(context, network_uuid)['id'] if host is not API._sentinel: if host is None: @@ -356,7 +355,6 @@ def associate(self, context, network_uuid, host=_sentinel, else: self.db.network_set_host(context, network_id, host) if project is not API._sentinel: - project = associations['project'] if project is None: self.db.network_disassociate(context, network_id, disassociate_host=False, diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index 304229b2001..76ace8b0260 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -255,3 +255,19 @@ def fake_fixed_ip_get_by_instance(ctxt, uuid): instance = {'uuid': FAKE_UUID} result = self.network_api._is_multi_host(self.context, instance) self.assertEqual(is_multi_host, result) + + def test_network_disassociate_project(self): + def fake_network_disassociate(ctx, network_id, disassociate_host, + disassociate_project): + self.assertEqual(network_id, 1) + self.assertEqual(disassociate_host, False) + self.assertEqual(disassociate_project, True) + + def fake_get(context, network_uuid): + return {'id': 1} + + self.stubs.Set(self.network_api.db, 'network_disassociate', + fake_network_disassociate) + self.stubs.Set(self.network_api, 'get', fake_get) + + self.network_api.associate(self.context, FAKE_UUID, project=None)