From: Guillaume Abrioux Date: Wed, 8 Jan 2025 12:17:16 +0000 (+0000) Subject: ceph-volume: improve wipefs retry logic in lvm.zap X-Git-Tag: v19.2.3~349^2~22 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9bafa3eb403c1ca19cba6623874194f108beb569;p=ceph.git ceph-volume: improve wipefs retry logic in lvm.zap - 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 (cherry picked from commit 297aa57ca5ff9e7822d94b504b776f12407a1854) --- diff --git a/src/ceph-volume/ceph_volume/devices/lvm/zap.py b/src/ceph-volume/ceph_volume/devices/lvm/zap.py index a6d82c7f0fa3e..92cc13714f9ae 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/zap.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/zap.py @@ -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)