Remove 'bdm_(update_or_create|destroy)_at_top'

These were being called within the 'BlockDeviceMapping' object. Remove
them in their entirety, given that nothing should be calling them now.
Note that this effectively breaks cells v1 but that shouldn't matter,
given that it's no longer possible to use the thing.

Part of blueprint remove-cells-v1

Change-Id: I13fb0575317015128853ac093bccffe233f3c79f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-04-04 16:16:47 +01:00
parent 6abd6ea2b4
commit 25545d7f55
8 changed files with 17 additions and 516 deletions

View File

@ -36,7 +36,6 @@ from nova import context
from nova import exception
from nova import manager
from nova import objects
from nova.objects import base as base_obj
from nova.objects import instance as instance_obj
@ -425,19 +424,6 @@ class CellsManager(manager.Manager):
def get_capacities(self, ctxt, cell_name):
return self.state_manager.get_capacities(cell_name)
def bdm_update_or_create_at_top(self, ctxt, bdm, create=None):
"""BDM was created/updated in this cell. Tell the API cells."""
# TODO(ndipanov): Move inter-cell RPC to use objects
bdm = base_obj.obj_to_primitive(bdm)
self.msg_runner.bdm_update_or_create_at_top(ctxt, bdm, create=create)
def bdm_destroy_at_top(self, ctxt, instance_uuid, device_name=None,
volume_id=None):
"""BDM was destroyed for instance in this cell. Tell the API cells."""
self.msg_runner.bdm_destroy_at_top(ctxt, instance_uuid,
device_name=device_name,
volume_id=volume_id)
def get_migrations(self, ctxt, filters):
"""Fetch migrations applying the filters."""
target_cell = None

View File

@ -1155,66 +1155,6 @@ class _BroadcastMessageMethods(_BaseMessageMethods):
self.consoleauth_rpcapi.delete_tokens_for_instance(message.ctxt,
instance_uuid)
def bdm_update_or_create_at_top(self, message, bdm, create):
"""Create or update a block device mapping in API cells. If
create is True, only try to create. If create is None, try to
update but fall back to create. If create is False, only attempt
to update. This maps to nova-conductor's behavior.
"""
if not self._at_the_top():
return
items_to_remove = ['id']
for key in items_to_remove:
bdm.pop(key, None)
if create is None:
LOG.debug('Calling db.block_device_mapping_update_or_create from '
'API cell with values: %s', bdm)
self.db.block_device_mapping_update_or_create(message.ctxt,
bdm,
legacy=False)
return
elif create is True:
LOG.debug('Calling db.block_device_mapping_create from API '
'cell with values: %s', bdm)
self.db.block_device_mapping_create(message.ctxt, bdm,
legacy=False)
return
# Unfortunately this update call wants BDM ID... but we don't know
# what it is in this cell. Search for it.. try matching either
# device_name or volume_id.
dev_name = bdm['device_name']
vol_id = bdm['volume_id']
instance_bdms = self.db.block_device_mapping_get_all_by_instance(
message.ctxt, bdm['instance_uuid'])
for instance_bdm in instance_bdms:
if dev_name and instance_bdm['device_name'] == dev_name:
break
if vol_id and instance_bdm['volume_id'] == vol_id:
break
else:
LOG.warning("No match when trying to update BDM: %(bdm)s",
dict(bdm=bdm))
return
LOG.debug('Calling db.block_device_mapping_update from API cell with '
'bdm id %s and values: %s', instance_bdm['id'], bdm)
self.db.block_device_mapping_update(message.ctxt,
instance_bdm['id'], bdm,
legacy=False)
def bdm_destroy_at_top(self, message, instance_uuid, device_name,
volume_id):
"""Destroy a block device mapping in API cells by device name
or volume_id. device_name or volume_id can be None, but not both.
"""
if not self._at_the_top():
return
if device_name:
self.db.block_device_mapping_destroy_by_instance_and_device(
message.ctxt, instance_uuid, device_name)
elif volume_id:
self.db.block_device_mapping_destroy_by_instance_and_volume(
message.ctxt, instance_uuid, volume_id)
def get_migrations(self, message, filters):
return self.compute_api.get_migrations(message.ctxt, filters)
@ -1648,25 +1588,6 @@ class MessageRunner(object):
cell_name, need_response=True)
return message.process()
def bdm_update_or_create_at_top(self, ctxt, bdm, create=None):
"""Update/Create a BDM at top level cell."""
message = _BroadcastMessage(self, ctxt,
'bdm_update_or_create_at_top',
dict(bdm=bdm, create=create),
'up', run_locally=False)
message.process()
def bdm_destroy_at_top(self, ctxt, instance_uuid, device_name=None,
volume_id=None):
"""Destroy a BDM at top level cell."""
method_kwargs = dict(instance_uuid=instance_uuid,
device_name=device_name,
volume_id=volume_id)
message = _BroadcastMessage(self, ctxt, 'bdm_destroy_at_top',
method_kwargs,
'up', run_locally=False)
message.process()
def get_migrations(self, ctxt, cell_name, run_locally, filters):
"""Fetch all migrations applying the filters for a given cell or all
cells.

View File

@ -413,39 +413,6 @@ class CellsAPI(object):
cctxt = self.client.prepare(version='1.9')
return cctxt.call(ctxt, 'get_capacities', cell_name=cell_name)
def bdm_update_or_create_at_top(self, ctxt, bdm, create=None):
"""Create or update a block device mapping in API cells. If
create is True, only try to create. If create is None, try to
update but fall back to create. If create is False, only attempt
to update. This maps to nova-conductor's behavior.
"""
if self.client.can_send_version('1.28'):
version = '1.28'
else:
version = '1.10'
bdm = objects_base.obj_to_primitive(bdm)
cctxt = self.client.prepare(version=version)
try:
cctxt.cast(ctxt, 'bdm_update_or_create_at_top',
bdm=bdm, create=create)
except Exception:
LOG.exception("Failed to notify cells of BDM update/create.")
def bdm_destroy_at_top(self, ctxt, instance_uuid, device_name=None,
volume_id=None):
"""Broadcast upwards that a block device mapping was destroyed.
One of device_name or volume_id should be specified.
"""
cctxt = self.client.prepare(version='1.10')
try:
cctxt.cast(ctxt, 'bdm_destroy_at_top',
instance_uuid=instance_uuid,
device_name=device_name,
volume_id=volume_id)
except Exception:
LOG.exception("Failed to notify cells of BDM destroy.")
def get_migrations(self, ctxt, filters):
"""Get all migrations applying the filters."""
cctxt = self.client.prepare(version='1.11')

View File

@ -19,8 +19,6 @@ from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova import block_device
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.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models as db_models
@ -201,13 +199,6 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
the ones that match. Normally only used when creating the
instance for the first time.
"""
cell_type = cells_opts.get_cell_type()
if cell_type == 'api':
raise exception.ObjectActionError(
action='create',
reason='BlockDeviceMapping cannot be '
'created in the API cell.')
if self.obj_attr_is_set('id'):
raise exception.ObjectActionError(action='create',
reason='already created')
@ -216,7 +207,6 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
raise exception.ObjectActionError(action='create',
reason='instance assigned')
cells_create = update_or_create or None
if update_or_create:
db_bdm = db.block_device_mapping_update_or_create(
context, updates, legacy=False)
@ -225,14 +215,6 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
context, updates, legacy=False)
self._from_db_object(context, self, db_bdm)
# NOTE(alaski): bdms are looked up by instance uuid and device_name
# so if we sync up with no device_name an entry will be created that
# will not be found on a later update_or_create call and a second bdm
# create will occur.
if cell_type == 'compute' and db_bdm.get('device_name') is not None:
cells_api = cells_rpcapi.CellsAPI()
cells_api.bdm_update_or_create_at_top(
context, self, create=cells_create)
@base.remotable
def create(self):
@ -250,13 +232,6 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
db.block_device_mapping_destroy(self._context, self.id)
delattr(self, base.get_attrname('id'))
cell_type = cells_opts.get_cell_type()
if cell_type == 'compute':
cells_api = cells_rpcapi.CellsAPI()
cells_api.bdm_destroy_at_top(self._context, self.instance_uuid,
device_name=self.device_name,
volume_id=self.volume_id)
@base.remotable
def save(self):
updates = self.obj_get_changes()
@ -269,18 +244,6 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
if not updated:
raise exception.BDMNotFound(id=self.id)
self._from_db_object(self._context, self, updated)
cell_type = cells_opts.get_cell_type()
if cell_type == 'compute':
create = False
# NOTE(alaski): If the device name has just been set this bdm
# likely does not exist in the parent cell and we should create it.
# If this is a modification of the device name we should update
# rather than create which is why None is used here instead of True
if 'device_name' in updates:
create = None
cells_api = cells_rpcapi.CellsAPI()
cells_api.bdm_update_or_create_at_top(self._context, self,
create=create)
# NOTE(danms): This method is deprecated and will be removed in
# v2.0 of the object

View File

@ -627,30 +627,6 @@ class CellsManagerClassTestCase(test.NoDBTestCase):
console_type=console_type)
self.assertEqual('fake-response', response)
def test_bdm_update_or_create_at_top(self):
self.mox.StubOutWithMock(self.msg_runner,
'bdm_update_or_create_at_top')
self.msg_runner.bdm_update_or_create_at_top(self.ctxt,
'fake-bdm',
create='foo')
self.mox.ReplayAll()
self.cells_manager.bdm_update_or_create_at_top(self.ctxt,
'fake-bdm',
create='foo')
def test_bdm_destroy_at_top(self):
self.mox.StubOutWithMock(self.msg_runner, 'bdm_destroy_at_top')
self.msg_runner.bdm_destroy_at_top(self.ctxt,
'fake_instance_uuid',
device_name='fake_device_name',
volume_id='fake_volume_id')
self.mox.ReplayAll()
self.cells_manager.bdm_destroy_at_top(self.ctxt,
'fake_instance_uuid',
device_name='fake_device_name',
volume_id='fake_volume_id')
def test_get_migrations(self):
filters = {'status': 'confirmed'}
cell1_migrations = objects.MigrationList(

View File

@ -1892,176 +1892,6 @@ class CellsBroadcastMethodsTestCase(test.NoDBTestCase):
self.src_msg_runner.consoleauth_delete_tokens(self.ctxt, fake_uuid)
def test_bdm_update_or_create_with_none_create(self):
fake_bdm = {'id': 'fake_id',
'volume_id': 'fake_volume_id'}
expected_bdm = fake_bdm.copy()
expected_bdm.pop('id')
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_update_or_create')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_update_or_create')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_update_or_create')
self.tgt_db_inst.block_device_mapping_update_or_create(
self.ctxt, expected_bdm, legacy=False)
self.mox.ReplayAll()
self.src_msg_runner.bdm_update_or_create_at_top(self.ctxt,
fake_bdm,
create=None)
def test_bdm_update_or_create_with_true_create(self):
fake_bdm = {'id': 'fake_id',
'volume_id': 'fake_volume_id'}
expected_bdm = fake_bdm.copy()
expected_bdm.pop('id')
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_create')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_create')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_create')
self.tgt_db_inst.block_device_mapping_create(
self.ctxt, fake_bdm, legacy=False)
self.mox.ReplayAll()
self.src_msg_runner.bdm_update_or_create_at_top(self.ctxt,
fake_bdm,
create=True)
def test_bdm_update_or_create_with_false_create_vol_id(self):
fake_bdm = {'id': 'fake_id',
'instance_uuid': uuids.instance,
'device_name': 'fake_device_name',
'volume_id': 'fake_volume_id'}
expected_bdm = fake_bdm.copy()
expected_bdm.pop('id')
fake_inst_bdms = [{'id': 1,
'volume_id': 'not-a-match',
'device_name': 'not-a-match'},
{'id': 2,
'volume_id': 'fake_volume_id',
'device_name': 'not-a-match'},
{'id': 3,
'volume_id': 'not-a-match',
'device_name': 'not-a-match'}]
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_update')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_update')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_update')
self.tgt_db_inst.block_device_mapping_get_all_by_instance(
self.ctxt, uuids.instance).AndReturn(
fake_inst_bdms)
# Should try to update ID 2.
self.tgt_db_inst.block_device_mapping_update(
self.ctxt, 2, expected_bdm, legacy=False)
self.mox.ReplayAll()
self.src_msg_runner.bdm_update_or_create_at_top(self.ctxt,
fake_bdm,
create=False)
def test_bdm_update_or_create_with_false_create_dev_name(self):
fake_bdm = {'id': 'fake_id',
'instance_uuid': uuids.instance,
'device_name': 'fake_device_name',
'volume_id': 'fake_volume_id'}
expected_bdm = fake_bdm.copy()
expected_bdm.pop('id')
fake_inst_bdms = [{'id': 1,
'volume_id': 'not-a-match',
'device_name': 'not-a-match'},
{'id': 2,
'volume_id': 'not-a-match',
'device_name': 'fake_device_name'},
{'id': 3,
'volume_id': 'not-a-match',
'device_name': 'not-a-match'}]
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_update')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_update')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_update')
self.tgt_db_inst.block_device_mapping_get_all_by_instance(
self.ctxt, uuids.instance).AndReturn(
fake_inst_bdms)
# Should try to update ID 2.
self.tgt_db_inst.block_device_mapping_update(
self.ctxt, 2, expected_bdm, legacy=False)
self.mox.ReplayAll()
self.src_msg_runner.bdm_update_or_create_at_top(self.ctxt,
fake_bdm,
create=False)
def test_bdm_destroy_by_volume(self):
fake_instance_uuid = uuids.instance
fake_volume_id = 'fake-volume-name'
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_destroy_by_instance_and_volume')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_destroy_by_instance_and_volume')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_destroy_by_instance_and_volume')
self.tgt_db_inst.block_device_mapping_destroy_by_instance_and_volume(
self.ctxt, fake_instance_uuid, fake_volume_id)
self.mox.ReplayAll()
self.src_msg_runner.bdm_destroy_at_top(self.ctxt, fake_instance_uuid,
volume_id=fake_volume_id)
def test_bdm_destroy_by_device(self):
fake_instance_uuid = uuids.instance
fake_device_name = 'fake-device-name'
# Shouldn't be called for these 2 cells
self.mox.StubOutWithMock(self.src_db_inst,
'block_device_mapping_destroy_by_instance_and_device')
self.mox.StubOutWithMock(self.mid_db_inst,
'block_device_mapping_destroy_by_instance_and_device')
self.mox.StubOutWithMock(self.tgt_db_inst,
'block_device_mapping_destroy_by_instance_and_device')
self.tgt_db_inst.block_device_mapping_destroy_by_instance_and_device(
self.ctxt, fake_instance_uuid, fake_device_name)
self.mox.ReplayAll()
self.src_msg_runner.bdm_destroy_at_top(self.ctxt, fake_instance_uuid,
device_name=fake_device_name)
def test_get_migrations(self):
self._setup_attrs(up=False)
filters = {'status': 'confirmed'}

View File

@ -469,32 +469,6 @@ class CellsAPITestCase(test.NoDBTestCase):
expected_args, version='1.6')
self.assertEqual('fake_response', result)
def test_bdm_update_or_create_at_top(self):
fake_bdm = {'id': 2, 'other': 'meow'}
call_info = self._stub_rpc_method('cast', None)
self.cells_rpcapi.bdm_update_or_create_at_top(
self.fake_context, fake_bdm, create='fake-create')
expected_args = {'bdm': fake_bdm, 'create': 'fake-create'}
self._check_result(call_info, 'bdm_update_or_create_at_top',
expected_args, version='1.28')
def test_bdm_destroy_at_top(self):
call_info = self._stub_rpc_method('cast', None)
self.cells_rpcapi.bdm_destroy_at_top(self.fake_context,
uuids.instance,
device_name='fake-device',
volume_id='fake-vol')
expected_args = {'instance_uuid': uuids.instance,
'device_name': 'fake-device',
'volume_id': 'fake-vol'}
self._check_result(call_info, 'bdm_destroy_at_top',
expected_args, version='1.10')
def test_get_migrations(self):
call_info = self._stub_rpc_method('call', None)
filters = {'cell_name': 'ChildCell', 'status': 'confirmed'}

View File

@ -15,7 +15,6 @@
import mock
from oslo_utils.fixture import uuidsentinel as uuids
from nova.cells import rpcapi as cells_rpcapi
from nova import context
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
@ -48,59 +47,18 @@ class _TestBlockDeviceMappingObject(object):
fake_bdm['instance'] = instance
return fake_bdm
def _test_save(self, cell_type=None, update_device_name=False):
if cell_type:
self.flags(enable=True, cell_type=cell_type, group='cells')
else:
self.flags(enable=False, group='cells')
create = False
def test_save(self):
fake_bdm = self.fake_bdm()
with test.nested(
mock.patch.object(
db, 'block_device_mapping_update', return_value=fake_bdm),
mock.patch.object(
cells_rpcapi.CellsAPI, 'bdm_update_or_create_at_top')
) as (bdm_update_mock, cells_update_mock):
with mock.patch.object(db, 'block_device_mapping_update',
return_value=fake_bdm) as bdm_update_mock:
bdm_object = objects.BlockDeviceMapping(context=self.context)
bdm_object.id = 123
bdm_object.volume_id = 'fake_volume_id'
if update_device_name:
bdm_object.device_name = '/dev/vda'
create = None
bdm_object.save()
if update_device_name:
bdm_update_mock.assert_called_once_with(
self.context, 123,
{'volume_id': 'fake_volume_id',
'device_name': '/dev/vda'},
legacy=False)
else:
bdm_update_mock.assert_called_once_with(
self.context, 123, {'volume_id': 'fake_volume_id'},
legacy=False)
if cell_type != 'compute':
self.assertFalse(cells_update_mock.called)
else:
self.assertEqual(1, cells_update_mock.call_count)
self.assertGreater(len(cells_update_mock.call_args[0]), 1)
self.assertIsInstance(cells_update_mock.call_args[0][1],
block_device_obj.BlockDeviceMapping)
self.assertEqual({'create': create},
cells_update_mock.call_args[1])
def test_save_nocells(self):
self._test_save()
def test_save_apicell(self):
self._test_save(cell_type='api')
def test_save_computecell(self):
self._test_save(cell_type='compute')
def test_save_computecell_device_name_changed(self):
self._test_save(cell_type='compute', update_device_name=True)
bdm_update_mock.assert_called_once_with(
self.context, 123, {'volume_id': 'fake_volume_id'},
legacy=False)
def test_save_instance_changed(self):
bdm_object = objects.BlockDeviceMapping(context=self.context)
@ -211,18 +169,11 @@ class _TestBlockDeviceMappingObject(object):
obj_bdm.get_by_volume_and_instance,
self.context, 'fake-volume-id', 'fake-instance-id')
def _test_create_mocked(self, cell_type=None, update_or_create=False,
device_name=None):
if cell_type:
self.flags(enable=True, cell_type=cell_type, group='cells')
else:
self.flags(enable=False, group='cells')
def _test_create_mocked(self, update_or_create=False):
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
'destination_type': 'volume',
'instance_uuid': uuids.instance,
'attachment_id': None}
if device_name:
values['device_name'] = device_name
fake_bdm = fake_block_device.FakeDbBlockDeviceDict(values)
with test.nested(
@ -231,71 +182,27 @@ class _TestBlockDeviceMappingObject(object):
mock.patch.object(
db, 'block_device_mapping_update_or_create',
return_value=fake_bdm),
mock.patch.object(cells_rpcapi.CellsAPI,
'bdm_update_or_create_at_top')
) as (bdm_create_mock, bdm_update_or_create_mock, cells_update_mock):
) as (bdm_create_mock, bdm_update_or_create_mock):
bdm = objects.BlockDeviceMapping(context=self.context, **values)
if update_or_create:
method = bdm.update_or_create
else:
method = bdm.create
if cell_type == 'api':
self.assertRaises(exception.ObjectActionError,
method)
method()
if update_or_create:
bdm_update_or_create_mock.assert_called_once_with(
self.context, values, legacy=False)
else:
method()
if update_or_create:
bdm_update_or_create_mock.assert_called_once_with(
self.context, values, legacy=False)
else:
bdm_create_mock.assert_called_once_with(
self.context, values, legacy=False)
if cell_type == 'compute' and 'device_name' in values:
self.assertEqual(1, cells_update_mock.call_count)
self.assertGreater(len(cells_update_mock.call_args[0]), 1)
self.assertEqual(self.context,
cells_update_mock.call_args[0][0])
self.assertIsInstance(cells_update_mock.call_args[0][1],
block_device_obj.BlockDeviceMapping)
self.assertEqual({'create': update_or_create or None},
cells_update_mock.call_args[1])
else:
self.assertFalse(cells_update_mock.called)
bdm_create_mock.assert_called_once_with(
self.context, values, legacy=False)
def test_create_nocells(self):
def test_create(self):
self._test_create_mocked()
def test_update_or_create(self):
self._test_create_mocked(update_or_create=True)
def test_create_apicell(self):
self._test_create_mocked(cell_type='api')
def test_update_or_create_apicell(self):
self._test_create_mocked(cell_type='api', update_or_create=True)
def test_create_computecell(self):
self._test_create_mocked(cell_type='compute')
def test_update_or_create_computecell(self):
self._test_create_mocked(cell_type='compute', update_or_create=True)
def test_device_name_compute_cell(self):
self._test_create_mocked(cell_type='compute', device_name='/dev/xvdb')
def test_create(self):
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
'destination_type': 'volume',
'instance_uuid': uuids.instance}
bdm = objects.BlockDeviceMapping(context=self.context, **values)
with mock.patch.object(cells_rpcapi.CellsAPI,
'bdm_update_or_create_at_top'):
bdm.create()
for k, v in values.items():
self.assertEqual(v, getattr(bdm, k))
def test_create_fails(self):
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
'destination_type': 'volume',
@ -315,37 +222,14 @@ class _TestBlockDeviceMappingObject(object):
self.assertRaises(exception.ObjectActionError,
bdm.create)
def _test_destroy_mocked(self, cell_type=None):
def test_destroy(self):
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
'destination_type': 'volume', 'id': 1,
'instance_uuid': uuids.instance, 'device_name': 'fake'}
if cell_type:
self.flags(enable=True, cell_type=cell_type, group='cells')
else:
self.flags(enable=False, group='cells')
with test.nested(
mock.patch.object(db, 'block_device_mapping_destroy'),
mock.patch.object(cells_rpcapi.CellsAPI, 'bdm_destroy_at_top')
) as (bdm_del, cells_destroy):
with mock.patch.object(db, 'block_device_mapping_destroy') as bdm_del:
bdm = objects.BlockDeviceMapping(context=self.context, **values)
bdm.destroy()
bdm_del.assert_called_once_with(self.context, values['id'])
if cell_type != 'compute':
self.assertFalse(cells_destroy.called)
else:
cells_destroy.assert_called_once_with(
self.context, values['instance_uuid'],
device_name=values['device_name'],
volume_id=values['volume_id'])
def test_destroy_nocells(self):
self._test_destroy_mocked()
def test_destroy_apicell(self):
self._test_destroy_mocked(cell_type='api')
def test_destroy_computecell(self):
self._test_destroy_mocked(cell_type='compute')
def test_is_image_true(self):
bdm = objects.BlockDeviceMapping(context=self.context,