]> review.fuel-infra Code Review - tools/sustaining.git/commitdiff
Cycle all attachments while cleaninig up volumes 05/41905/2
authorVladimir Khlyunev <vkhlyunev@mirantis.com>
Mon, 25 Apr 2022 17:21:33 +0000 (21:21 +0400)
committerVladimir Khlyunev <vkhlyunev@mirantis.com>
Mon, 25 Apr 2022 17:25:04 +0000 (21:25 +0400)
Change-Id: I12f6dffae4b3daaab0c7055588d49ae0390bba8b

os_cloud_cleaner/os_connector.py

index d45779e94598d465630c50399db715d96131ca47..2277014ec715b9f46df6d4b1ad4d8d85bcd1a17d 100644 (file)
@@ -122,6 +122,10 @@ class OpenStackActions(object):
     def get_volume(self, uuid):
         return self.cinder.volumes.get(uuid)
 
+    def get_volume_attachments(self, volume_uuid):
+        volume = self.cinder.volumes.get(volume_uuid)
+        return volume.attachments
+
     def get_keypairs(self):
         keypairs = self.nova.keypairs.list()
         resp = []
@@ -381,8 +385,9 @@ class OpenStackActions(object):
                 existing_volumes.append(uuid)
         for uuid in existing_volumes:
             if self.check_volume_attached(uuid):
-                logger.info("Detaching volume {}".format(uuid))
-                self.cinder.volumes.detach(uuid)
+                for attachment in self.get_volume_attachments(uuid):
+                    logger.info("Detaching volume {}".format(uuid))
+                    self.cinder.volumes.detach(uuid, attachment['attachment_id'])
         try:
             helpers.wait_false(self.check_any_volume_attached,
                                interval=3,