Perform old-style local delete for shelved offloaded instances

This fixes a regression from some local delete code added for cells v2
where it assumed that if an instance did not have a host, it wasn't
scheduled to a cell yet. That assumption misses the fact that the
instance won't have a host if it was shelved offloaded. And to be
shelved offloaded, the instance had to have first been built on a host
in a cell.

So we simply duplicate the same check as later in the _delete() method
for instance.host or shelved-offloaded to decide what the case is.

Obviously this is all a giant mess of duplicate delete path code that
needs to be unwound, and that's the plan, but first we're fixing
regressions and then we can start rolling this duplication all back
so we can get back to the single local delete flow that we know and love.

Change-Id: Ie2063f621618c1d90aeb59f0f1d7da351862ea9f
Closes-Bug: #1678326
(cherry picked from commit 9245bbf79d)
This commit is contained in:
Matt Riedemann 2017-04-05 16:27:41 -04:00
parent 2b66c6780a
commit 6384e935be
2 changed files with 9 additions and 5 deletions

View File

@ -1771,10 +1771,12 @@ class API(base.Base):
instance=instance)
return
# If there is an instance.host the instance has been scheduled and
# sent to a cell/compute which means it was pulled from the cell db.
# 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.
# Normal delete should be attempted.
if not instance.host:
if not (instance.host or
instance.vm_state == vm_states.SHELVED_OFFLOADED):
try:
if self._delete_while_booting(context, instance):
return

View File

@ -64,6 +64,8 @@ class TestLocalDeleteAttachedVolumes(test.TestCase):
self.flags(driver='chance_scheduler', group='scheduler')
self.start_service('scheduler')
self.start_service('compute')
# The consoleauth service is needed for deleting console tokens.
self.start_service('consoleauth')
self.useFixture(cast_as_call.CastAsCall(self.stubs))
@ -164,5 +166,5 @@ class TestLocalDeleteAttachedVolumes(test.TestCase):
LOG.info('Validating that volume %s was detached from server %s.',
volume_id, server_id)
# When bug 1675570 is fixed, this should be assertNotIn.
self.assertIn(volume_id, self.cinder.attachments[server_id])
# Now that the bug is fixed, assert the volume was detached.
self.assertNotIn(volume_id, self.cinder.attachments[server_id])