]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/cephadm: add wait_for_service
authorSage Weil <sage@newdream.net>
Tue, 13 Apr 2021 16:52:49 +0000 (12:52 -0400)
committerSage Weil <sage@newdream.net>
Fri, 16 Apr 2021 14:49:45 +0000 (09:49 -0500)
Signed-off-by: Sage Weil <sage@newdream.net>
qa/tasks/cephadm.py

index 699fc7f6e3fa7fbb35dd6b7a6670238834acc230..721b4b0871bb16924e39b65e51f5382edf6f1a64 100644 (file)
@@ -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):
     """