Merge "Target cell on local delete"

This commit is contained in:
Jenkins 2017-06-06 23:51:34 +00:00 committed by Gerrit Code Review
commit 11ad2da58b
2 changed files with 27 additions and 2 deletions

View File

@ -1839,6 +1839,7 @@ class API(base.Base):
instance=instance)
return
cell = None
# If there is an instance.host (or the instance is shelved-offloaded),
# the instance has been scheduled and sent to a cell/compute which
# means it was pulled from the cell db.
@ -2024,8 +2025,23 @@ class API(base.Base):
# If instance is in shelved_offloaded state or compute node
# isn't up, delete instance from db and clean bdms info and
# network info
self._local_delete(context, instance, bdms, delete_type, cb)
quotas.commit()
if cell is None:
# NOTE(danms): If we didn't get our cell from one of the
# paths above, look it up now.
try:
im = objects.InstanceMapping.get_by_instance_uuid(
context, instance.uuid)
cell = im.cell_mapping
except exception.InstanceMappingNotFound:
LOG.warning('During local delete, failed to find '
'instance mapping', instance=instance)
return
LOG.debug('Doing local delete in cell %s', cell.identity,
instance=instance)
with nova_context.target_cell(context, cell) as cctxt:
self._local_delete(cctxt, instance, bdms, delete_type, cb)
quotas.commit()
except exception.InstanceNotFound:
# NOTE(comstud): Race condition. Instance already gone.

View File

@ -840,6 +840,12 @@ class _ComputeAPIUnitTestMixIn(object):
self.compute_api.notifier,
self.context, inst, '%s.end' % delete_type,
system_metadata=inst.system_metadata)
cell = objects.CellMapping(uuid=uuids.cell,
transport_url='fake://',
database_connection='fake://')
im = objects.InstanceMapping(cell_mapping=cell)
objects.InstanceMapping.get_by_instance_uuid(
self.context, inst.uuid).AndReturn(im)
def _test_delete(self, delete_type, **attrs):
reservations = ['fake-resv']
@ -883,6 +889,9 @@ class _ComputeAPIUnitTestMixIn(object):
self.mox.StubOutWithMock(rpcapi, 'confirm_resize')
self.mox.StubOutWithMock(self.compute_api.consoleauth_rpcapi,
'delete_tokens_for_instance')
self.mox.StubOutWithMock(objects.InstanceMapping,
'get_by_instance_uuid')
if (inst.vm_state in
(vm_states.SHELVED, vm_states.SHELVED_OFFLOADED)):
self._test_delete_shelved_part(inst)