From 54954eed256b51033e5f52214ae077f6f112a920 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 23 Apr 2024 08:16:19 -0400 Subject: [PATCH] qa/tasks/cephadm: add a wait_for_service_not_present task func Add a wait_for_service_not_present task function that will wait until a given service name is not present in the list of running cephadm services. This is intended for testing service cleanup operations. Signed-off-by: John Mulligan --- qa/tasks/cephadm.py | 47 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index aa67bd7e39d..d5ec55a78d1 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -1556,6 +1556,20 @@ def apply(ctx, config): ) + +def _orch_ls(ctx, cluster_name): + r = _shell( + ctx=ctx, + cluster_name=cluster_name, + remote=ctx.ceph[cluster_name].bootstrap_remote, + args=[ + 'ceph', 'orch', 'ls', '-f', 'json', + ], + stdout=StringIO(), + ) + return json.loads(r.stdout.getvalue()) + + def wait_for_service(ctx, config): """ Wait for a service to be fully started @@ -1576,16 +1590,7 @@ def wait_for_service(ctx, config): ) with contextutil.safe_while(sleep=1, tries=timeout) as proceed: while proceed(): - r = _shell( - ctx=ctx, - cluster_name=cluster_name, - remote=ctx.ceph[cluster_name].bootstrap_remote, - args=[ - 'ceph', 'orch', 'ls', '-f', 'json', - ], - stdout=StringIO(), - ) - j = json.loads(r.stdout.getvalue()) + j = _orch_ls(ctx, cluster_name) svc = None for s in j: if s['service_name'] == service: @@ -1599,6 +1604,28 @@ def wait_for_service(ctx, config): break +def wait_for_service_not_present(ctx, config): + """Wait for a service to not be present. + Note that this doesn't ensure that the service was previously present. + """ + cluster_name = config.get('cluster', 'ceph') + timeout = config.get('timeout', 120) + service = config.get('service') + assert service + + log.info( + f'Waiting for {cluster_name} service {service} to be not present' + ' in service list' + ) + with contextutil.safe_while(sleep=1, tries=timeout) as proceed: + while proceed(): + j = _orch_ls(ctx, cluster_name) + services = {s['service_name'] for s in j} + log.debug('checking if %r in %r', service, services) + if service not in services: + break + + @contextlib.contextmanager def tweaked_option(ctx, config): """ -- 2.39.5