From c3d670c2186e681d89cfa511984eff7255ef0826 Mon Sep 17 00:00:00 2001 From: Ali Adil Date: Mon, 27 Jun 2016 20:47:23 -0400 Subject: [PATCH] Ophaned Volume Not Removed on Instance Delete When an instance is created with quota issues, the cinder volume is created butthe nova instance fails to be created. Deleting the instance would fail todelete the volume. Check the status of the volume when deleting the instance, if the status of the volume is "available" delete the volume as it is not connected to any instance. Change-Id: Ie921a8ff2851e2d9d76a3c3836945c750f090c4e Closes-Bug: #1344113 --- trove/taskmanager/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/trove/taskmanager/models.py b/trove/taskmanager/models.py index 568a6fef27..b6e6a4012e 100644 --- a/trove/taskmanager/models.py +++ b/trove/taskmanager/models.py @@ -318,6 +318,24 @@ class ClusterTasks(Cluster): class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): + def _delete_resources(self, deleted_at): + LOG.debug("Begin _delete_resources for instance %s" % self.id) + + # If volume has "available" status, delete it manually. + try: + if self.volume_id: + volume_client = create_cinder_client(self.context) + volume = volume_client.volumes.get(self.volume_id) + if volume.status == "available": + LOG.info(_("Deleting volume %(v)s for instance: %(i)s.") + % {'v': self.volume_id, 'i': self.id}) + volume.delete() + except Exception: + LOG.exception(_("Error deleting volume of instance %(id)s.") % + {'id': self.db_info.id}) + + LOG.debug("End _delete_resource for instance %s" % self.id) + def _get_injected_files(self, datastore_manager): injected_config_location = CONF.get('injected_config_location') guest_info = CONF.get('guest_info')