]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: improve wipefs retry logic in lvm.zap
authorGuillaume Abrioux <gabrioux@ibm.com>
Wed, 8 Jan 2025 12:17:16 +0000 (12:17 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Mon, 24 Feb 2025 11:53:01 +0000 (11:53 +0000)
- Simplify the initialization of `tries` and `interval` variables for clarity.
- Adjust the retry logic in the `wipefs` function to:
  - Include the attempt count in the warning message for better debugging.
  - Start the retry loop at 1 and increment up to `tries`.
- Remove unnecessary unpacking of `stdout` and `stderr` since they were unused.
- Update the loop to increment `tries` by 1 to reflect the intended number of attempts.

This change improves code readability and makes retry behavior more transparent.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
(cherry picked from commit 297aa57ca5ff9e7822d94b504b776f12407a1854)

src/ceph-volume/ceph_volume/devices/lvm/zap.py

index a6d82c7f0fa3e9df08c81aae85211c8b8a027291..92cc13714f9ae1810b6cbd4ce0877512f390c9f6 100644 (file)
@@ -52,30 +52,25 @@ def wipefs(path):
     * ``CEPH_VOLUME_WIPEFS_INTERVAL``: Defaults to 5
 
     """
-    tries = str_to_int(
-        os.environ.get('CEPH_VOLUME_WIPEFS_TRIES', 8)
-    )
-    interval = str_to_int(
-        os.environ.get('CEPH_VOLUME_WIPEFS_INTERVAL', 5)
-    )
-
-    for trying in range(tries):
-        stdout, stderr, exit_code = process.call([
+    tries = str_to_int(os.environ.get('CEPH_VOLUME_WIPEFS_TRIES', 8)) + 1
+    interval = str_to_int(os.environ.get('CEPH_VOLUME_WIPEFS_INTERVAL', 5))
+
+    for attempt in range(1, tries):
+        _, _, exit_code = process.call([
             'wipefs',
             '--all',
             path
         ])
-        if exit_code != 0:
-            # this could narrow the retry by poking in the stderr of the output
-            # to verify that 'probing initialization failed' appears, but
-            # better to be broad in this retry to prevent missing on
-            # a different message that needs to be retried as well
-            terminal.warning(
-                'failed to wipefs device, will try again to workaround probable race condition'
-            )
-            time.sleep(interval)
-        else:
+        if not exit_code:
             return
+        # this could narrow the retry by poking in the stderr of the output
+        # to verify that 'probing initialization failed' appears, but
+        # better to be broad in this retry to prevent missing on
+        # a different message that needs to be retried as well
+        terminal.warning(
+            f'failed to wipefs device, will try again ({attempt}/{tries}) to workaround probable race condition'
+        )
+        time.sleep(interval)
     raise RuntimeError("could not complete wipefs on device: %s" % path)