Remove 'instance_info_cache_update_at_top'

This was being called within the 'InstanceInfoCache' object. Remove it
in its entirety, given that nothing should be calling it now.

An 'update_cells' argument is removed from a number of functions as
these all resulted in a call to the cells v1 RPC API, a call that is now
removed.

Part of blueprint remove-cells-v1

Change-Id: Ia8da8cd040d104d745bd7adf20438b8eec558680
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-04-04 16:40:32 +01:00
parent 6584870607
commit e3a8188e21
8 changed files with 10 additions and 93 deletions

View File

@ -31,7 +31,6 @@ from oslo_utils import uuidutils
from nova import cells
import nova.conf
from nova import exception
from nova import objects
from nova.objects import base as objects_base
from nova import profiler
from nova import rpc
@ -248,17 +247,6 @@ class CellsAPI(object):
self.client.cast(ctxt, 'bw_usage_update_at_top',
bw_update_info=bw_update_info)
def instance_info_cache_update_at_top(self, ctxt, instance_info_cache):
"""Broadcast up that an instance's info_cache has changed."""
version = '1.35'
instance = objects.Instance(uuid=instance_info_cache.instance_uuid,
info_cache=instance_info_cache)
if not self.client.can_send_version('1.35'):
instance = objects_base.obj_to_primitive(instance)
version = '1.34'
cctxt = self.client.prepare(version=version)
cctxt.cast(ctxt, 'instance_update_at_top', instance=instance)
def get_cell_info_for_neighbors(self, ctxt):
"""Get information about our neighbor cells from the manager."""
if not CONF.cells.enable:

View File

@ -31,8 +31,7 @@ LOG = logging.getLogger(__name__)
@hooks.add_hook('instance_network_info')
def update_instance_cache_with_nw_info(impl, context, instance,
nw_info=None, update_cells=True):
def update_instance_cache_with_nw_info(impl, context, instance, nw_info=None):
if instance.deleted:
LOG.debug('Instance is deleted, no further info cache update',
instance=instance)
@ -52,7 +51,7 @@ def update_instance_cache_with_nw_info(impl, context, instance,
# from the DB first.
ic = objects.InstanceInfoCache.new(context, instance.uuid)
ic.network_info = nw_info
ic.save(update_cells=update_cells)
ic.save()
instance.info_cache = ic
except Exception:
with excutils.save_and_reraise_exception():
@ -254,14 +253,8 @@ class NetworkAPI(base.Base):
"""Returns all network info related to an instance."""
with lockutils.lock('refresh_cache-%s' % instance.uuid):
result = self._get_instance_nw_info(context, instance, **kwargs)
# NOTE(comstud): Don't update API cell with new info_cache every
# time we pull network info for an instance. The periodic healing
# of info_cache causes too many cells messages. Healing the API
# will happen separately.
update_cells = kwargs.get('update_cells', False)
update_instance_cache_with_nw_info(self, context, instance,
nw_info=result,
update_cells=update_cells)
nw_info=result)
return result
def _get_instance_nw_info(self, context, instance, **kwargs):

View File

@ -314,7 +314,7 @@ class NetworkManager(manager.Manager):
None, None)
ic = objects.InstanceInfoCache.new(admin_context, instance_id)
ic.network_info = nw_info
ic.save(update_cells=False)
ic.save()
except exception.InstanceInfoCacheNotFound:
pass
groups = instance.security_groups

View File

@ -1129,8 +1129,7 @@ class API(base_api.NetworkAPI):
context, instance, networks=ordered_nets,
port_ids=ordered_port_ids,
admin_client=admin_client,
preexisting_port_ids=preexisting_port_ids,
update_cells=True)
preexisting_port_ids=preexisting_port_ids)
# Only return info about ports we processed in this run, which might
# have been pre-existing neutron ports or ones that nova created. In
# the initial allocation case (server create), this will be everything

View File

@ -14,8 +14,6 @@
from oslo_log import log as logging
from nova.cells import opts as cells_opts
from nova.cells import rpcapi as cells_rpcapi
from nova.db import api as db
from nova import exception
from nova.objects import base
@ -71,33 +69,16 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject):
instance_uuid=instance_uuid)
return cls._from_db_object(context, cls(context), db_obj)
@staticmethod
def _info_cache_cells_update(ctxt, info_cache):
cell_type = cells_opts.get_cell_type()
if cell_type != 'compute':
return
cells_api = cells_rpcapi.CellsAPI()
try:
cells_api.instance_info_cache_update_at_top(ctxt, info_cache)
except Exception:
LOG.exception("Failed to notify cells of instance info "
"cache update")
# TODO(stephenfin): Remove 'update_cells' in version 2.0
@base.remotable
def save(self, update_cells=True):
if 'network_info' in self.obj_what_changed():
if update_cells:
stale_instance = self.obj_clone()
nw_info_json = self.fields['network_info'].to_primitive(
self, 'network_info', self.network_info)
rv = db.instance_info_cache_update(self._context,
self.instance_uuid,
{'network_info': nw_info_json})
self._from_db_object(self._context, self, rv)
if update_cells:
# Send a copy of ourselves before updates are applied so
# that cells can tell what changed.
self._info_cache_cells_update(self._context, stale_instance)
self.obj_reset_changes()
@base.remotable

View File

@ -184,8 +184,7 @@ class ApiTestCase(test.TestCase):
return fake_info_cache
def fake_update_instance_cache_with_nw_info(api, context, instance,
nw_info=None,
update_cells=True):
nw_info=None):
return
with test.nested(
@ -555,8 +554,7 @@ class ApiTestCase(test.TestCase):
result = self.network_api.get_instance_nw_info(self.context, instance)
mock_get.assert_called_once_with(self.context, instance)
mock_update.assert_called_once_with(self.network_api, self.context,
instance, nw_info=fake_result,
update_cells=False)
instance, nw_info=fake_result)
self.assertEqual(fake_result, result)

View File

@ -715,7 +715,7 @@ class TestNeutronv2Base(test.TestCase):
mock.ANY, self.instance, networks=nets_in_requested_net_order,
port_ids=ports_in_requested_net_order,
admin_client=mocked_client,
preexisting_port_ids=preexisting_port_ids, update_cells=True)
preexisting_port_ids=preexisting_port_ids)
return nw_info, mocked_client
@ -3573,8 +3573,7 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
result = self.api.get_instance_nw_info(self.context, instance)
mock_get.assert_called_once_with(self.context, instance)
mock_update.assert_called_once_with(self.api, self.context, instance,
nw_info=fake_result,
update_cells=False)
nw_info=fake_result)
self.assertEqual(fake_result, result)
def _test_validate_networks_fixed_ip_no_dup(self, nets, requested_networks,

View File

@ -18,8 +18,6 @@ import mock
from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import timeutils
from nova.cells import opts as cells_opts
from nova.cells import rpcapi as cells_rpcapi
from nova.db import api as db
from nova import exception
from nova.network import model as network_model
@ -65,45 +63,6 @@ class _TestInstanceInfoCacheObject(object):
self.assertEqual(uuids.info_instance, obj.instance_uuid)
self.assertIsNone(obj.network_info)
@mock.patch.object(cells_opts, 'get_cell_type')
@mock.patch.object(cells_rpcapi, 'CellsAPI')
@mock.patch.object(db, 'instance_info_cache_update')
def _save_helper(self, cell_type, update_cells, mock_update,
mock_rpc, mock_get_type):
obj = instance_info_cache.InstanceInfoCache()
cells_api = cells_rpcapi.CellsAPI()
nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}])
new_info_cache = fake_info_cache.copy()
new_info_cache['network_info'] = nwinfo.json()
mock_update.return_value = new_info_cache
with mock.patch.object(cells_api,
'instance_info_cache_update_at_top'):
if update_cells:
mock_get_type.return_vaule = cell_type
if cell_type == 'compute':
mock_rpc.return_value = cells_api
cells_api.instance_info_cache_update_at_top(
self.context, 'foo')
mock_rpc.assert_called_once_with()
obj._context = self.context
obj.instance_uuid = uuids.info_instance
obj.network_info = nwinfo
obj.save(update_cells=update_cells)
mock_update.assert_called_once_with(self.context, obj.instance_uuid,
{'network_info': nwinfo.json()})
if update_cells:
mock_get_type.assert_called_once()
def test_save_with_update_cells_and_compute_cell(self):
self._save_helper('compute', True)
def test_save_with_update_cells_and_non_compute_cell(self):
self._save_helper(None, True)
def test_save_without_update_cells(self):
self._save_helper(None, False)
@mock.patch.object(db, 'instance_info_cache_update')
def test_save_updates_self(self, mock_update):
fake_updated_at = datetime.datetime(2015, 1, 1)