Merge "Stop handling 'update_cells' on 'BandwidthUsage.create'"

This commit is contained in:
Zuul 2019-05-29 03:56:20 +00:00 committed by Gerrit Code Review
commit ee9bfb5219
11 changed files with 6 additions and 112 deletions

View File

@ -225,10 +225,6 @@ class CellsManager(manager.Manager):
self.msg_runner.instance_delete_everywhere(ctxt, instance,
delete_type)
def bw_usage_update_at_top(self, ctxt, bw_update_info):
"""Update bandwidth usage at top level cell."""
self.msg_runner.bw_usage_update_at_top(ctxt, bw_update_info)
def sync_instances(self, ctxt, project_id, updated_since, deleted):
"""Force a sync of all instances, potentially by project_id,
and potentially since a certain date/time.

View File

@ -973,12 +973,6 @@ class _BroadcastMessageMethods(_BaseMessageMethods):
else:
self.compute_api.delete(message.ctxt, instance)
def bw_usage_update_at_top(self, message, bw_update_info, **kwargs):
"""Update Bandwidth usage in the DB if we're a top level cell."""
if not self._at_the_top():
return
self.db.bw_usage_update(message.ctxt, **bw_update_info)
def _sync_instance(self, ctxt, instance):
pass
@ -1254,13 +1248,6 @@ class MessageRunner(object):
run_locally=False)
message.process()
def bw_usage_update_at_top(self, ctxt, bw_update_info):
"""Update bandwidth usage at top level cell."""
message = _BroadcastMessage(self, ctxt, 'bw_usage_update_at_top',
dict(bw_update_info=bw_update_info),
'up', run_locally=False)
message.process()
def sync_instances(self, ctxt, project_id, updated_since, deleted):
"""Force a sync of all instances, potentially by project_id,
and potentially since a certain date/time.

View File

@ -215,20 +215,6 @@ class CellsAPI(object):
cctxt.cast(ctxt, 'instance_delete_everywhere', instance=instance,
delete_type=delete_type)
def bw_usage_update_at_top(self, ctxt, uuid, mac, start_period,
bw_in, bw_out, last_ctr_in, last_ctr_out, last_refreshed=None):
"""Broadcast upwards that bw_usage was updated."""
bw_update_info = {'uuid': uuid,
'mac': mac,
'start_period': start_period,
'bw_in': bw_in,
'bw_out': bw_out,
'last_ctr_in': last_ctr_in,
'last_ctr_out': last_ctr_out,
'last_refreshed': last_refreshed}
self.client.cast(ctxt, 'bw_usage_update_at_top',
bw_update_info=bw_update_info)
def get_cell_info_for_neighbors(self, ctxt):
"""Get information about our neighbor cells from the manager."""
if not CONF.cells.enable:

View File

@ -7636,14 +7636,6 @@ class ComputeManager(manager.Manager):
CONF.bandwidth_poll_interval):
self._last_bw_usage_poll = curr_time
LOG.info("Updating bandwidth usage cache")
cells_update_interval = CONF.cells.bandwidth_update_interval
if (cells_update_interval > 0 and
curr_time - self._last_bw_usage_cell_update >
cells_update_interval):
self._last_bw_usage_cell_update = curr_time
update_cells = True
else:
update_cells = False
instances = objects.InstanceList.get_by_host(context,
self.host,
@ -7709,8 +7701,7 @@ class ComputeManager(manager.Manager):
bw_ctr['bw_in'],
bw_ctr['bw_out'],
start_period=start_time,
last_refreshed=refreshed,
update_cells=update_cells)
last_refreshed=refreshed)
def _get_host_volume_bdms(self, context, use_slave=False):
"""Return all block device mappings on a compute host."""

View File

@ -30,7 +30,6 @@ these objects be simple dictionaries.
from oslo_db import concurrency
from oslo_log import log as logging
from nova.cells import rpcapi as cells_rpcapi
import nova.conf
from nova.db import constants
@ -1625,20 +1624,12 @@ def bw_usage_get_by_uuids(context, uuids, start_period):
def bw_usage_update(context, uuid, mac, start_period, bw_in, bw_out,
last_ctr_in, last_ctr_out, last_refreshed=None,
update_cells=True):
last_ctr_in, last_ctr_out, last_refreshed=None):
"""Update cached bandwidth usage for an instance's network based on mac
address. Creates new record if needed.
"""
rv = IMPL.bw_usage_update(context, uuid, mac, start_period, bw_in,
bw_out, last_ctr_in, last_ctr_out, last_refreshed=last_refreshed)
if update_cells:
try:
cells_rpcapi.CellsAPI().bw_usage_update_at_top(context,
uuid, mac, start_period, bw_in, bw_out,
last_ctr_in, last_ctr_out, last_refreshed)
except Exception:
LOG.exception("Failed to notify cells of bw_usage update")
return rv

View File

@ -60,6 +60,7 @@ class BandwidthUsage(base.NovaPersistentObject, base.NovaObject):
if db_bw_usage:
return cls._from_db_object(context, cls(), db_bw_usage)
# TODO(stephenfin): Remove 'update_cells' in version 2.0 of the object
@base.serialize_args
@base.remotable
def create(self, uuid, mac, bw_in, bw_out, last_ctr_in,
@ -67,8 +68,7 @@ class BandwidthUsage(base.NovaPersistentObject, base.NovaObject):
update_cells=True):
db_bw_usage = db.bw_usage_update(
self._context, uuid, mac, start_period, bw_in, bw_out,
last_ctr_in, last_ctr_out, last_refreshed=last_refreshed,
update_cells=update_cells)
last_ctr_in, last_ctr_out, last_refreshed=last_refreshed)
self._from_db_object(self._context, self, db_bw_usage)

View File

@ -173,15 +173,6 @@ class CellsManagerClassTestCase(test.NoDBTestCase):
self.ctxt, instance='fake-instance',
delete_type='fake-type')
def test_bw_usage_update_at_top(self):
self.mox.StubOutWithMock(self.msg_runner,
'bw_usage_update_at_top')
self.msg_runner.bw_usage_update_at_top(self.ctxt,
'fake-bw-info')
self.mox.ReplayAll()
self.cells_manager.bw_usage_update_at_top(
self.ctxt, bw_update_info='fake-bw-info')
def test_heal_instances(self):
self.flags(instance_updated_at_threshold=1000,
instance_update_num_instances=2,

View File

@ -1388,28 +1388,6 @@ class CellsBroadcastMethodsTestCase(test.NoDBTestCase):
self.src_msg_runner.instance_delete_everywhere(self.ctxt,
instance, 'soft')
def test_bw_usage_update_at_top(self):
fake_bw_update_info = {'uuid': 'fake_uuid',
'mac': 'fake_mac',
'start_period': 'fake_start_period',
'bw_in': 'fake_bw_in',
'bw_out': 'fake_bw_out',
'last_ctr_in': 'fake_last_ctr_in',
'last_ctr_out': 'fake_last_ctr_out',
'last_refreshed': 'fake_last_refreshed'}
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst, 'bw_usage_update')
self.mox.StubOutWithMock(self.mid_db_inst, 'bw_usage_update')
self.mox.StubOutWithMock(self.tgt_db_inst, 'bw_usage_update')
self.tgt_db_inst.bw_usage_update(self.ctxt, **fake_bw_update_info)
self.mox.ReplayAll()
self.src_msg_runner.bw_usage_update_at_top(self.ctxt,
fake_bw_update_info)
def test_sync_instances(self):
# Reset this, as this is a broadcast down.
self._setup_attrs(up=False)

View File

@ -166,30 +166,6 @@ class CellsAPITestCase(test.NoDBTestCase):
self._check_result(call_info, 'instance_delete_everywhere',
expected_args, version='1.27')
def test_bw_usage_update_at_top(self):
update_args = ('fake_uuid', 'fake_mac', 'fake_start_period',
'fake_bw_in', 'fake_bw_out', 'fake_ctr_in',
'fake_ctr_out')
update_kwargs = {'last_refreshed': 'fake_refreshed'}
call_info = self._stub_rpc_method('cast', None)
self.cells_rpcapi.bw_usage_update_at_top(
self.fake_context, *update_args, **update_kwargs)
bw_update_info = {'uuid': 'fake_uuid',
'mac': 'fake_mac',
'start_period': 'fake_start_period',
'bw_in': 'fake_bw_in',
'bw_out': 'fake_bw_out',
'last_ctr_in': 'fake_ctr_in',
'last_ctr_out': 'fake_ctr_out',
'last_refreshed': 'fake_refreshed'}
expected_args = {'bw_update_info': bw_update_info}
self._check_result(call_info, 'bw_usage_update_at_top',
expected_args)
def test_get_cell_info_for_neighbors(self):
call_info = self._stub_rpc_method('call', 'fake_response')
result = self.cells_rpcapi.get_cell_info_for_neighbors(

View File

@ -4549,8 +4549,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
bw_usage_update.assert_called_once_with(self.context,
uuids.instance,
'fake-mac', 0, 4, 6, 1, 2,
last_refreshed=mock.ANY,
update_cells=False)
last_refreshed=mock.ANY)
def test_reverts_task_state_instance_not_found(self):
# Tests that the reverts_task_state decorator in the compute manager

View File

@ -8271,8 +8271,7 @@ class BwUsageTestCase(test.TestCase, ModelsObjectComparatorMixin):
'last_ctr_in': 54321,
'last_ctr_out': 67890,
'last_refreshed': now}
result = db.bw_usage_update(
self.ctxt, update_cells=False, **updated_bw_usage)
result = db.bw_usage_update(self.ctxt, **updated_bw_usage)
# check that only bw_usage with ID 1 was updated
self.assertEqual(1, result['id'])