diff --git a/nova/compute/api.py b/nova/compute/api.py index fb220229b237..cf264c8d428c 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -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: diff --git a/nova/tests/functional/wsgi/test_servers.py b/nova/tests/functional/wsgi/test_servers.py index 70901aa0b06b..5cec3fda5009 100644 --- a/nova/tests/functional/wsgi/test_servers.py +++ b/nova/tests/functional/wsgi/test_servers.py @@ -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']])