Merge "Detach volumes when deleting a BFV server pre-scheduling" into stable/queens

This commit is contained in:
Zuul 2018-02-22 08:19:04 +00:00 committed by Gerrit Code Review
commit fd09db13e3
2 changed files with 12 additions and 6 deletions

View File

@ -1772,6 +1772,11 @@ class API(base.Base):
# instance is now in a cell and the delete needs to proceed
# normally.
return False
# We need to detach from any volumes so they aren't orphaned.
self._local_cleanup_bdm_volumes(
build_req.block_device_mappings, instance, context)
return True
def _delete(self, context, instance, delete_type, cb, **instance_attrs):
@ -2044,7 +2049,12 @@ class API(base.Base):
except Exception as exc:
LOG.warning("Ignoring volume cleanup failure due to %s",
exc, instance=instance)
bdm.destroy()
# If we're cleaning up volumes from an instance that wasn't yet
# created in a cell, i.e. the user deleted the server while
# the BuildRequest still existed, then the BDM doesn't actually
# exist in the DB to destroy it.
if 'id' in bdm:
bdm.destroy()
def _local_delete(self, context, instance, bdms, delete_type, cb):
if instance.vm_state == vm_states.SHELVED_OFFLOADED:

View File

@ -275,8 +275,4 @@ class ServersPreSchedulingTestCase(test.TestCase,
# The volume should no longer have any attachments as instance delete
# should have removed them.
# self.assertNotIn(volume_id, cinder.attachments[server['id']])
# FIXME(mriedem): This is part of bug 1404867 where the BDMs aren't
# processed when the build request is deleted. Uncomment the above
# and remove the below when this is fixed.
self.assertIn(volume_id, cinder.attachments[server['id']])
self.assertNotIn(volume_id, cinder.attachments[server['id']])