remove get_nw_info_for_instance from compute.utils
This patch removes get_nw_info_for_instance(instance) from nova.compute.utils as it was just a proxy for instance.get_network_info() call. Change-Id: Iddae8074554995df22b656bb2e9bddaec6d775cc
This commit is contained in:
parent
8548d3138b
commit
a4a9733f4a
|
@ -26,7 +26,6 @@ import webob
|
|||
from webob import exc
|
||||
|
||||
from nova.compute import task_states
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
|
@ -323,7 +322,7 @@ def get_networks_for_instance(context, instance):
|
|||
'mac_address': 'aa:aa:aa:aa:aa:aa'}]},
|
||||
...}
|
||||
"""
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
nw_info = instance.get_network_info()
|
||||
return get_networks_for_instance_from_nw_info(nw_info)
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ from nova.api.openstack import extensions
|
|||
from nova.api.openstack import wsgi
|
||||
from nova.api import validation
|
||||
from nova import compute
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import network
|
||||
|
@ -224,7 +223,7 @@ class FloatingIPActionController(wsgi.Controller):
|
|||
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
expected_attrs=['flavor'])
|
||||
cached_nwinfo = compute_utils.get_nw_info_for_instance(instance)
|
||||
cached_nwinfo = instance.get_network_info()
|
||||
if not cached_nwinfo:
|
||||
LOG.warning(
|
||||
'Info cache is %r during associate with no nw_info cache',
|
||||
|
|
|
@ -2633,7 +2633,7 @@ class API(base.Base):
|
|||
ipv6_f = re.compile(str(filters.get('ip6')))
|
||||
|
||||
def _match_instance(instance):
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
nw_info = instance.get_network_info()
|
||||
for vif in nw_info:
|
||||
for fixed_ip in vif.fixed_ips():
|
||||
address = fixed_ip.get('address')
|
||||
|
|
|
@ -932,7 +932,7 @@ class ComputeManager(manager.Manager):
|
|||
LOG.exception('Failed to start instance', instance=instance)
|
||||
return
|
||||
|
||||
net_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
net_info = instance.get_network_info()
|
||||
try:
|
||||
self.driver.plug_vifs(instance, net_info)
|
||||
except NotImplementedError as e:
|
||||
|
@ -2253,7 +2253,7 @@ class ComputeManager(manager.Manager):
|
|||
self.host, action=fields.NotificationAction.SHUTDOWN,
|
||||
phase=fields.NotificationPhase.START)
|
||||
|
||||
network_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
network_info = instance.get_network_info()
|
||||
|
||||
# NOTE(vish) get bdms before destroying the instance
|
||||
vol_bdms = [bdm for bdm in bdms if bdm.is_volume]
|
||||
|
@ -2933,7 +2933,7 @@ class ComputeManager(manager.Manager):
|
|||
self.network_api.setup_instance_network_on_host(
|
||||
context, instance, self.host)
|
||||
|
||||
network_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
network_info = instance.get_network_info()
|
||||
if bdms is None:
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance.uuid)
|
||||
|
|
|
@ -489,10 +489,6 @@ def notify_about_host_update(context, event_suffix, host_payload):
|
|||
notifier.info(context, 'HostAPI.%s' % event_suffix, host_payload)
|
||||
|
||||
|
||||
def get_nw_info_for_instance(instance):
|
||||
return instance.get_network_info()
|
||||
|
||||
|
||||
def refresh_info_cache_for_instance(context, instance):
|
||||
"""Refresh the info cache for an instance.
|
||||
|
||||
|
|
|
@ -1302,7 +1302,7 @@ class API(base_api.NetworkAPI):
|
|||
"networks as not none.")
|
||||
raise exception.NovaException(message=message)
|
||||
|
||||
ifaces = compute_utils.get_nw_info_for_instance(instance)
|
||||
ifaces = instance.get_network_info()
|
||||
# This code path is only done when refreshing the network_cache
|
||||
if port_ids is None:
|
||||
port_ids = [iface['id'] for iface in ifaces]
|
||||
|
@ -2194,7 +2194,7 @@ class API(base_api.NetworkAPI):
|
|||
These ports were not created by nova and hence should not be
|
||||
deallocated upon instance deletion.
|
||||
"""
|
||||
net_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
net_info = instance.get_network_info()
|
||||
if not net_info:
|
||||
LOG.debug('Instance cache missing network info.',
|
||||
instance=instance)
|
||||
|
|
|
@ -21,7 +21,6 @@ import webob
|
|||
from nova.api.openstack.compute import floating_ips as fips_v21
|
||||
from nova.api.openstack import extensions
|
||||
from nova import compute
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
|
@ -236,7 +235,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
network_api_disassociate)
|
||||
self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
|
||||
get_instance_by_floating_ip_addr)
|
||||
self.stubs.Set(compute_utils, "get_nw_info_for_instance",
|
||||
self.stubs.Set(objects.Instance, "get_network_info",
|
||||
stub_nw_info(self))
|
||||
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self)
|
||||
|
@ -903,7 +902,7 @@ class ExtendedFloatingIpTestV21(test.TestCase):
|
|||
network_api_disassociate)
|
||||
self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
|
||||
get_instance_by_floating_ip_addr)
|
||||
self.stubs.Set(compute_utils, "get_nw_info_for_instance",
|
||||
self.stubs.Set(objects.Instance, "get_network_info",
|
||||
stub_nw_info(self))
|
||||
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self)
|
||||
|
|
|
@ -683,7 +683,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
with test.nested(
|
||||
mock.patch.object(context, 'get_admin_context',
|
||||
return_value=self.context),
|
||||
mock.patch.object(compute_utils, 'get_nw_info_for_instance',
|
||||
mock.patch.object(objects.Instance, 'get_network_info',
|
||||
return_value=network_model.NetworkInfo()),
|
||||
mock.patch.object(self.compute.driver, 'plug_vifs',
|
||||
side_effect=exception.VirtualInterfacePlugException(
|
||||
|
@ -922,7 +922,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
expected_attrs=['system_metadata'])
|
||||
|
||||
with test.nested(
|
||||
mock.patch.object(compute_utils, 'get_nw_info_for_instance',
|
||||
mock.patch.object(objects.Instance, 'get_network_info',
|
||||
return_value=network_model.NetworkInfo()),
|
||||
mock.patch.object(self.compute.driver, 'plug_vifs'),
|
||||
mock.patch.object(self.compute.driver, 'finish_revert_migration'),
|
||||
|
@ -942,7 +942,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
mock_retry.assert_called_once_with(self.context, instance,
|
||||
power_state.SHUTDOWN)
|
||||
mock_get_nw.assert_called_once_with(instance)
|
||||
mock_get_nw.assert_called_once_with()
|
||||
mock_plug.assert_called_once_with(instance, [])
|
||||
mock_get_inst.assert_called_once_with(self.context, instance)
|
||||
mock_finish.assert_called_once_with(self.context, instance,
|
||||
|
@ -972,12 +972,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
task_state=task_states.MIGRATING)
|
||||
with test.nested(
|
||||
mock.patch.object(instance, 'save'),
|
||||
mock.patch('nova.compute.utils.get_nw_info_for_instance',
|
||||
mock.patch('nova.objects.Instance.get_network_info',
|
||||
return_value=network_model.NetworkInfo())
|
||||
) as (save, get_nw_info):
|
||||
self.compute._init_instance(self.context, instance)
|
||||
save.assert_called_once_with(expected_task_state=['migrating'])
|
||||
get_nw_info.assert_called_once_with(instance)
|
||||
get_nw_info.assert_called_once_with()
|
||||
self.assertIsNone(instance.task_state)
|
||||
self.assertEqual(vm_states.ACTIVE, instance.vm_state)
|
||||
|
||||
|
@ -1180,7 +1180,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
with test.nested(
|
||||
mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=power_state.RUNNING),
|
||||
mock.patch.object(compute_utils, 'get_nw_info_for_instance'),
|
||||
mock.patch.object(objects.Instance, 'get_network_info'),
|
||||
mock.patch.object(instance, 'save', autospec=True)
|
||||
) as (mock_get_power_state, mock_nw_info, mock_instance_save):
|
||||
self.compute._init_instance(self.context, instance)
|
||||
|
@ -1188,7 +1188,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
self.assertIsNone(instance.task_state)
|
||||
|
||||
@mock.patch('nova.context.RequestContext.elevated')
|
||||
@mock.patch('nova.compute.utils.get_nw_info_for_instance')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch(
|
||||
'nova.compute.manager.ComputeManager._get_instance_block_device_info')
|
||||
@mock.patch('nova.virt.driver.ComputeDriver.destroy')
|
||||
|
@ -1215,7 +1215,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
action='shutdown', phase='end')])
|
||||
|
||||
@mock.patch('nova.context.RequestContext.elevated')
|
||||
@mock.patch('nova.compute.utils.get_nw_info_for_instance')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch(
|
||||
'nova.compute.manager.ComputeManager._get_instance_block_device_info')
|
||||
@mock.patch('nova.virt.driver.ComputeDriver.destroy')
|
||||
|
@ -1261,11 +1261,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=return_power_state),
|
||||
mock.patch.object(self.compute, 'reboot_instance'),
|
||||
mock.patch.object(compute_utils, 'get_nw_info_for_instance')
|
||||
mock.patch.object(objects.Instance, 'get_network_info')
|
||||
) as (
|
||||
_get_power_state,
|
||||
reboot_instance,
|
||||
get_nw_info_for_instance
|
||||
get_network_info
|
||||
):
|
||||
self.compute._init_instance(self.context, instance)
|
||||
call = mock.call(self.context, instance, block_device_info=None,
|
||||
|
@ -1333,11 +1333,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=power_state.RUNNING),
|
||||
mock.patch.object(instance, 'save', autospec=True),
|
||||
mock.patch.object(compute_utils, 'get_nw_info_for_instance')
|
||||
mock.patch.object(objects.Instance, 'get_network_info')
|
||||
) as (
|
||||
_get_power_state,
|
||||
instance_save,
|
||||
get_nw_info_for_instance
|
||||
get_network_info
|
||||
):
|
||||
self.compute._init_instance(self.context, instance)
|
||||
instance_save.assert_called_once_with()
|
||||
|
|
|
@ -21,7 +21,6 @@ import string
|
|||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from nova.compute import flavors
|
||||
|
@ -731,15 +730,6 @@ class ComputeUtilsGetValFromSysMetadata(test.NoDBTestCase):
|
|||
self.assertEqual(0, result)
|
||||
|
||||
|
||||
class ComputeUtilsGetNWInfo(test.NoDBTestCase):
|
||||
def test_instance_object_none_info_cache(self):
|
||||
inst = fake_instance.fake_instance_obj('fake-context',
|
||||
expected_attrs=['info_cache'])
|
||||
self.assertIsNone(inst.info_cache)
|
||||
result = compute_utils.get_nw_info_for_instance(inst)
|
||||
self.assertEqual(jsonutils.dumps([]), result.json())
|
||||
|
||||
|
||||
class ComputeUtilsGetRebootTypes(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
super(ComputeUtilsGetRebootTypes, self).setUp()
|
||||
|
|
|
@ -4272,13 +4272,14 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
instance, port_id, migrate_profile, admin_client)
|
||||
update_port_mock.assert_called_once_with(port_id, port_profile)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.compute_utils')
|
||||
def test_get_preexisting_port_ids(self, mocked_comp_utils):
|
||||
mocked_comp_utils.get_nw_info_for_instance.return_value = [model.VIF(
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
def test_get_preexisting_port_ids(self, mock_get_nw_info):
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
mock_get_nw_info.return_value = [model.VIF(
|
||||
id='1', preserve_on_delete=False), model.VIF(
|
||||
id='2', preserve_on_delete=True), model.VIF(
|
||||
id='3', preserve_on_delete=True)]
|
||||
result = self.api._get_preexisting_port_ids(None)
|
||||
result = self.api._get_preexisting_port_ids(instance)
|
||||
self.assertEqual(['2', '3'], result, "Invalid preexisting ports")
|
||||
|
||||
def _test_unbind_ports_get_client(self, mock_neutron,
|
||||
|
@ -4492,22 +4493,22 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
|
||||
@mock.patch('nova.network.neutronv2.api.API.get_instance_nw_info')
|
||||
@mock.patch('nova.network.neutronv2.api.API._unbind_ports')
|
||||
@mock.patch('nova.network.neutronv2.api.compute_utils')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
@mock.patch.object(objects.VirtualInterface, 'get_by_uuid')
|
||||
def test_preexisting_deallocate_port_for_instance(self,
|
||||
mock_get_vif_by_uuid,
|
||||
mock_ntrn,
|
||||
mock_comp_utils,
|
||||
mock_inst_get_nwinfo,
|
||||
mock_unbind,
|
||||
mock_netinfo):
|
||||
mock_comp_utils.get_nw_info_for_instance.return_value = [model.VIF(
|
||||
id='1', preserve_on_delete=False), model.VIF(
|
||||
id='2', preserve_on_delete=True), model.VIF(
|
||||
id='3', preserve_on_delete=True)]
|
||||
mock_inst = mock.Mock(project_id="proj-1",
|
||||
availability_zone='zone-1',
|
||||
uuid='inst-1')
|
||||
mock_inst.get_network_info.return_value = [model.VIF(
|
||||
id='1', preserve_on_delete=False), model.VIF(
|
||||
id='2', preserve_on_delete=True), model.VIF(
|
||||
id='3', preserve_on_delete=True)]
|
||||
mock_client = mock.Mock()
|
||||
mock_ntrn.return_value = mock_client
|
||||
mock_vif = mock.MagicMock(spec=objects.VirtualInterface)
|
||||
|
|
|
@ -249,7 +249,7 @@ class IptablesFirewallTestCase(test.NoDBTestCase):
|
|||
|
||||
linux_net.iptables_manager.execute = fake_iptables_execute
|
||||
|
||||
self.stub_out('nova.compute.utils.get_nw_info_for_instance',
|
||||
self.stub_out('nova.objects.Instance.get_network_info',
|
||||
lambda instance: network_model)
|
||||
|
||||
self.fw.prepare_instance_filter(instance_ref, network_model)
|
||||
|
|
|
@ -476,7 +476,7 @@ class TestIptablesFirewallDriver(test.NoDBTestCase):
|
|||
ins_list_mock.get_by_security_group.return_value = [i_obj_list_mock]
|
||||
return i_mock, i_obj_mock, ni_mock, driver
|
||||
|
||||
@mock.patch('nova.compute.utils.get_nw_info_for_instance')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch('nova.objects.InstanceList')
|
||||
@mock.patch('nova.objects.SecurityGroupRuleList')
|
||||
@mock.patch('nova.objects.SecurityGroupList')
|
||||
|
@ -510,7 +510,7 @@ class TestIptablesFirewallDriver(test.NoDBTestCase):
|
|||
self.assertEqual(expected, v4_rules)
|
||||
self.assertEqual(expected, v6_rules)
|
||||
|
||||
@mock.patch('nova.compute.utils.get_nw_info_for_instance')
|
||||
@mock.patch('nova.objects.Instance.get_network_info')
|
||||
@mock.patch('nova.objects.InstanceList')
|
||||
@mock.patch('nova.objects.SecurityGroupRuleList')
|
||||
@mock.patch('nova.objects.SecurityGroupList')
|
||||
|
|
|
@ -2896,8 +2896,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
|
|||
|
||||
network_model = fake_network.fake_get_instance_nw_info(self, 1)
|
||||
|
||||
from nova.compute import utils as compute_utils # noqa
|
||||
self.stubs.Set(compute_utils, 'get_nw_info_for_instance',
|
||||
self.stubs.Set(objects.Instance, 'get_network_info',
|
||||
lambda instance: network_model)
|
||||
|
||||
self.fw.prepare_instance_filter(instance_ref, network_model)
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
|
||||
from nova.compute import utils as compute_utils
|
||||
import nova.conf
|
||||
from nova import context
|
||||
from nova.i18n import _LI
|
||||
|
@ -355,8 +354,7 @@ class IptablesFirewallDriver(FirewallDriver):
|
|||
if inst.info_cache.deleted:
|
||||
LOG.debug('ignoring deleted cache')
|
||||
continue
|
||||
nw_info = compute_utils.get_nw_info_for_instance(
|
||||
inst)
|
||||
nw_info = inst.get_network_info()
|
||||
|
||||
ips = [ip['address'] for ip in nw_info.fixed_ips()
|
||||
if ip['version'] == version]
|
||||
|
|
Loading…
Reference in New Issue