]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/tasks/cephadm: add a wait_for_service_not_present task func
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 23 Apr 2024 12:16:19 +0000 (08:16 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 25 Apr 2024 23:10:39 +0000 (19:10 -0400)
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 <jmulligan@redhat.com>
qa/tasks/cephadm.py

index aa67bd7e39d47f8b1a8ebfc102cfbbcd27af0ada..d5ec55a78d1aeae0a0d874502a43c8116cb200ae 100644 (file)
@@ -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):
     """