Fix deleting volume for instance
Story: 2008337 Task: 41238 Change-Id: Ifa333c30d4e24a2d693a6a5229dd1e83ad32d56d
This commit is contained in:
parent
78772cef68
commit
c02d2f74eb
5
releasenotes/notes/wallaby-fix-deleting-volume.yaml
Normal file
5
releasenotes/notes/wallaby-fix-deleting-volume.yaml
Normal 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.
|
@ -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.
|
||||||
|
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:
|
try:
|
||||||
if self.volume_id:
|
vol.delete()
|
||||||
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:
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user