Skip to content

Commit

Permalink
Fix getting nwinfo for Instance obj
Browse files Browse the repository at this point in the history
This fixes the get_nw_info_for_instance() method in nova/compute/utils.

If an instance object has no 'info_cache' (means we lack an entry in the
instance_info_caches table for the instance), don't try to access the
'network_info' attribute.  Just return a network model with empty
networking information like the dict version of an instance would do.

Change-Id: Ib1f49f10cefeefc55a87fea69b6fbc772c978dca
Closes-bug: 1243291
  • Loading branch information
comstud committed Oct 22, 2013
1 parent 19ea0c8 commit a907c2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nova/compute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def notify_about_aggregate_update(context, event_suffix, aggregate_payload):

def get_nw_info_for_instance(instance):
if isinstance(instance, instance_obj.Instance):
if instance.info_cache is None:
return network_model.NetworkInfo.hydrate([])
return instance.info_cache.network_info
# FIXME(comstud): Transitional while we convert to objects.
info_cache = instance['info_cache'] or {}
Expand Down
15 changes: 15 additions & 0 deletions nova/tests/compute/test_compute_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,18 @@ def fake_show(ctx, image_id):

expected = {'properties': 'DONTCARE'}
self.assertThat(expected, matchers.DictMatches(image_meta))


class ComputeUtilsGetNWInfo(test.TestCase):
def test_instance_object_none_info_cache(self):
inst = fake_instance.fake_instance_obj('fake-context',
expected_attrs=['info_cache'])
self.assertEqual(None, inst.info_cache)
result = compute_utils.get_nw_info_for_instance(inst)
self.assertEqual(jsonutils.dumps([]), result.json())

def test_instance_dict_none_info_cache(self):
inst = fake_instance.fake_db_instance(info_cache=None)
self.assertEqual(None, inst['info_cache'])
result = compute_utils.get_nw_info_for_instance(inst)
self.assertEqual(jsonutils.dumps([]), result.json())

0 comments on commit a907c2f

Please sign in to comment.