From 470be74771f97d0bd771107fb8916e221fbc177d Mon Sep 17 00:00:00 2001 From: utkarshbhatthere Date: Thu, 9 Mar 2023 16:55:29 +0530 Subject: [PATCH] Adds timeout for ceph command calls. Change-Id: I8c81b1f0042181d814d5f268282b082c8a5fc217 func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/989 --- actions/remove_disk.py | 34 ++++++++++++++++---------- unit_tests/test_actions_remove_disk.py | 19 ++++++++++---- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/actions/remove_disk.py b/actions/remove_disk.py index 7e1cae25..154290b0 100755 --- a/actions/remove_disk.py +++ b/actions/remove_disk.py @@ -103,35 +103,43 @@ def map_id_to_device(dev_map, osd_id): return elem['path'] -def safe_to_destroy(osd_id): +def safe_to_destroy(osd_id, timeout=300): """Test whether an OSD id is safe to destroy per the Ceph cluster.""" - ret = subprocess.call(['ceph', '--id', 'osd-removal', - 'osd', 'safe-to-destroy', osd_id]) + ret = subprocess.call([ + 'ceph', '--id', 'osd-removal', + 'osd', 'safe-to-destroy', osd_id + ], timeout=timeout) return ret == 0 -def safe_to_stop(osd_id): +def safe_to_stop(osd_id, timeout=300): """Test whether an OSD is safe to stop.""" - ret = subprocess.call(['ceph', '--id', 'osd-removal', - 'osd', 'ok-to-stop', osd_id]) + ret = subprocess.call([ + 'ceph', '--id', 'osd-removal', + 'osd', 'ok-to-stop', osd_id + ], timeout=timeout) return ret == 0 -def reweight_osd(osd_id): +def reweight_osd(osd_id, timeout=300): """Set the weight of the OSD id to zero.""" - subprocess.check_call(['ceph', '--id', 'osd-removal', - 'osd', 'crush', 'reweight', osd_id, '0']) + subprocess.check_call([ + 'ceph', '--id', 'osd-removal', + 'osd', 'crush', 'reweight', osd_id, '0' + ], timeout=timeout) -def destroy(osd_id, purge=False): +def destroy(osd_id, purge=False, timeout=300): """Destroy or purge an OSD id.""" for _ in range(10): # We might get here before the OSD is marked as down. As such, # retry if the error code is EBUSY. try: - subprocess.check_call(['ceph', '--id', 'osd-removal', 'osd', - 'purge' if purge else 'destroy', - osd_id, '--yes-i-really-mean-it']) + subprocess.check_call([ + 'ceph', '--id', 'osd-removal', 'osd', + 'purge' if purge else 'destroy', + osd_id, '--yes-i-really-mean-it' + ], timeout=timeout) return except subprocess.CalledProcessError as e: if e.returncode != errno.EBUSY: diff --git a/unit_tests/test_actions_remove_disk.py b/unit_tests/test_actions_remove_disk.py index 369d3f1f..b729ab1c 100644 --- a/unit_tests/test_actions_remove_disk.py +++ b/unit_tests/test_actions_remove_disk.py @@ -87,11 +87,20 @@ class RemoveDiskActionTests(CharmTestCase): obj = remove_disk.ActionOSD(dev_map, osd_id='1') obj.remove(True, 1, True) - call.assert_any_call(prefix_args + ['osd', 'safe-to-destroy', 'osd.1']) - check_call.assert_any_call(prefix_args + ['osd', 'purge', 'osd.1', - '--yes-i-really-mean-it']) - check_call.assert_any_call(prefix_args + ['osd', 'crush', 'reweight', - 'osd.1', '0']) + + # Subprocess Call checks + call.assert_any_call( + prefix_args + ['osd', 'safe-to-destroy', 'osd.1'], timeout=300 + ) + check_call.assert_any_call( + prefix_args + ['osd', 'purge', 'osd.1', '--yes-i-really-mean-it'], + timeout=300 + ) + check_call.assert_any_call( + prefix_args + ['osd', 'crush', 'reweight', 'osd.1', '0'], + timeout=300 + ) + bcache_remove.assert_called_with( '/dev/bcache0', '/dev/backing', '/dev/caching') report = obj.report