summaryrefslogtreecommitdiff
path: root/trove
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2020-11-10 22:10:43 +1300
committerLingxian Kong <anlin.kong@gmail.com>2020-11-11 09:02:44 +1300
commitc02d2f74ebfc17d439e85bbe1b57ad93829bf536 (patch)
treeb8abd213e79a412018e31029c2caad035d4a3bd2 /trove
parent78772cef68887a59adbde42057ef43d586e28b85 (diff)
downloadtrove-c02d2f74ebfc17d439e85bbe1b57ad93829bf536.tar.gz
Fix deleting volume for instance
Story: 2008337 Task: 41238 Change-Id: Ifa333c30d4e24a2d693a6a5229dd1e83ad32d56d
Diffstat (limited to 'trove')
-rw-r--r--trove/instance/models.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/trove/instance/models.py b/trove/instance/models.py
index 4d9396a6..43670086 100644
--- a/trove/instance/models.py
+++ b/trove/instance/models.py
@@ -837,17 +837,17 @@ class BaseInstance(SimpleInstance):
"Timeout deleting compute server %(vm_id)s",
{'instance_id': self.id, 'vm_id': self.server_id})
- # If volume has been resized it must be manually removed
- try:
- if self.volume_id:
- volume = self.volume_client.volumes.get(self.volume_id)
- if volume.status in ["available", "error"]:
- LOG.info("Deleting volume %s for instance %s",
- self.volume_id, self.id)
- volume.delete()
- except Exception as e:
- LOG.warning("Failed to delete volume for instance %s, error: %s",
- self.id, str(e))
+ # Cinder volume.
+ vols = self.volume_client.volumes.list(
+ search_opts={'name': f'trove-{self.id}'})
+ for vol in vols:
+ LOG.info(f"Deleting volume {vol.id} for instance {self.id}")
+
+ try:
+ vol.delete()
+ except Exception as e:
+ LOG.warning(f"Failed to delete volume {vol.id}({vol.status}) "
+ f"for instance {self.id}, error: {str(e)}")
notification.TroveInstanceDelete(
instance=self,