diff options
| author | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-08 12:33:29 +0930 |
|---|---|---|
| committer | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-08 12:33:29 +0930 |
| commit | 6cfc02531f92c2e98eb947bc7a46d6bed0158d82 (patch) | |
| tree | 643b56f133adeff3b37d70c00c8c99c72f14de70 | |
| parent | e02c365888d046179b4326a1e6d85602f56ec032 (diff) | |
| download | nova-6cfc02531f92c2e98eb947bc7a46d6bed0158d82.tar.gz nova-6cfc02531f92c2e98eb947bc7a46d6bed0158d82.tar.xz nova-6cfc02531f92c2e98eb947bc7a46d6bed0158d82.zip | |
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
| -rw-r--r-- | nova/network/api.py | 2 | ||||
| -rw-r--r-- | 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 b8baf9810..491efe759 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -346,7 +346,6 @@ class API(base.Base): 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 @@ class API(base.Base): 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 304229b20..76ace8b02 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -255,3 +255,19 @@ class ApiTestCase(test.TestCase): 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) |
