From: Sage Weil Date: Tue, 13 Apr 2021 16:52:49 +0000 (-0400) Subject: qa/tasks/cephadm: add wait_for_service X-Git-Tag: v17.1.0~2221^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ced2f7fe4a04ebaa09896376c342b7b866ab5bc7;p=ceph.git qa/tasks/cephadm: add wait_for_service Signed-off-by: Sage Weil --- diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 699fc7f6e3fa7..721b4b0871bb1 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -1004,6 +1004,49 @@ def apply(ctx, config): ) +def wait_for_service(ctx, config): + """ + Wait for a service to be fully started + + tasks: + - cephadm.wait_for_service: + service: rgw.foo + timeout: 60 # defaults to 300 + + """ + cluster_name = config.get('cluster', 'ceph') + timeout = config.get('timeout', 300) + service = config.get('service') + assert service + + log.info( + f'Waiting for {cluster_name} service {service} to start (timeout {timeout})...' + ) + 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()) + svc = None + for s in j: + if s['service_name'] == service: + svc = s + break + if svc: + log.info( + f"{service} has {s['status']['running']}/{s['status']['size']}" + ) + if s['status']['running'] == s['status']['size']: + break + + @contextlib.contextmanager def tweaked_option(ctx, config): """