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", "Timeout deleting compute server %(vm_id)s",
{'instance_id': self.id, 'vm_id': self.server_id}) {'instance_id': self.id, 'vm_id': self.server_id})
# If volume has been resized it must be manually removed # Cinder volume.
try: vols = self.volume_client.volumes.list(
if self.volume_id: search_opts={'name': f'trove-{self.id}'})
volume = self.volume_client.volumes.get(self.volume_id) for vol in vols:
if volume.status in ["available", "error"]: LOG.info(f"Deleting volume {vol.id} for instance {self.id}")
LOG.info("Deleting volume %s for instance %s",
self.volume_id, self.id) try:
volume.delete() vol.delete()
except Exception as e: except Exception as e:
LOG.warning("Failed to delete volume for instance %s, error: %s", LOG.warning(f"Failed to delete volume {vol.id}({vol.status}) "
self.id, str(e)) f"for instance {self.id}, error: {str(e)}")
notification.TroveInstanceDelete( notification.TroveInstanceDelete(
instance=self, instance=self,