Adds timeout for ceph command calls.

Change-Id: I8c81b1f0042181d814d5f268282b082c8a5fc217
func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/989
This commit is contained in:
utkarshbhatthere 2023-03-09 16:55:29 +05:30
parent 1fe0aa07d3
commit 470be74771
No known key found for this signature in database
GPG Key ID: 8AFC279E7CD87430
2 changed files with 35 additions and 18 deletions

View File

@ -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:

View File

@ -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