Fix deleting volume for instance

Story: 2008337
Task: 41238

Change-Id: Ifa333c30d4e24a2d693a6a5229dd1e83ad32d56d
This commit is contained in:
Lingxian Kong 2020-11-10 22:10:43 +13:00
parent 78772cef68
commit c02d2f74eb
2 changed files with 16 additions and 11 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed an issue that orphan volumes left after removing instances,
especially for the case that instance creation failed because of timeout
when waiting for the volume available.

View File

@ -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,