Skip to content

Commit

Permalink
Fixes KeyError bug with network api associate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chris Yeoh committed May 8, 2013
1 parent e02c365 commit 6cfc025
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions nova/network/api.py
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions nova/tests/network/test_api.py
Expand Up @@ -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)

0 comments on commit 6cfc025

Please sign in to comment.