Merge "remove ugly local import"
This commit is contained in:
@@ -30,7 +30,6 @@ from nova.compute import power_state
|
||||
from nova.compute import task_states
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova import notifications
|
||||
from nova.notifications.objects import aggregate as aggregate_notification
|
||||
from nova.notifications.objects import base as notification_base
|
||||
@@ -491,9 +490,7 @@ def notify_about_host_update(context, event_suffix, host_payload):
|
||||
|
||||
|
||||
def get_nw_info_for_instance(instance):
|
||||
if instance.info_cache is None:
|
||||
return network_model.NetworkInfo.hydrate([])
|
||||
return instance.info_cache.network_info
|
||||
return instance.get_network_info()
|
||||
|
||||
|
||||
def refresh_info_cache_for_instance(context, instance):
|
||||
|
||||
@@ -94,11 +94,8 @@ class InstancePayload(base.NotificationPayloadBase):
|
||||
|
||||
def __init__(self, instance):
|
||||
super(InstancePayload, self).__init__()
|
||||
# Note(gibi): ugly but needed to avoid cyclic import
|
||||
from nova.compute import utils
|
||||
|
||||
self.ip_addresses = IpPayload.from_network_info(
|
||||
utils.get_nw_info_for_instance(instance))
|
||||
network_info = instance.get_network_info()
|
||||
self.ip_addresses = IpPayload.from_network_info(network_info)
|
||||
self.flavor = flavor_payload.FlavorPayload(flavor=instance.flavor)
|
||||
|
||||
self.populate_schema(instance=instance)
|
||||
|
||||
@@ -32,6 +32,7 @@ from nova.db.sqlalchemy import api as db_api
|
||||
from nova.db.sqlalchemy import models
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LE, _LW
|
||||
from nova.network import model as network_model
|
||||
from nova import notifications
|
||||
from nova import objects
|
||||
from nova.objects import base
|
||||
@@ -1156,6 +1157,11 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
|
||||
finally:
|
||||
self._normalize_cell_name()
|
||||
|
||||
def get_network_info(self):
|
||||
if self.info_cache is None:
|
||||
return network_model.NetworkInfo.hydrate([])
|
||||
return self.info_cache.network_info
|
||||
|
||||
|
||||
def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
|
||||
get_fault = expected_attrs and 'fault' in expected_attrs
|
||||
|
||||
@@ -825,6 +825,21 @@ class _TestInstanceObject(object):
|
||||
mock_get.assert_called_once_with(self.context, fake_uuid,
|
||||
columns_to_join=['info_cache'])
|
||||
|
||||
def test_get_network_info_with_cache(self):
|
||||
info_cache = instance_info_cache.InstanceInfoCache()
|
||||
nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
|
||||
info_cache.network_info = nwinfo
|
||||
inst = objects.Instance(context=self.context,
|
||||
info_cache=info_cache)
|
||||
|
||||
self.assertEqual(nwinfo, inst.get_network_info())
|
||||
|
||||
def test_get_network_info_without_cache(self):
|
||||
inst = objects.Instance(context=self.context, info_cache=None)
|
||||
|
||||
self.assertEqual(network_model.NetworkInfo.hydrate([]),
|
||||
inst.get_network_info())
|
||||
|
||||
@mock.patch.object(db, 'security_group_update')
|
||||
@mock.patch.object(db, 'instance_update_and_get_original')
|
||||
@mock.patch.object(db, 'instance_get_by_uuid')
|
||||
|
||||
Reference in New Issue
Block a user