]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/python: simple task to run python code
authorSage Weil <sage@newdream.net>
Thu, 15 Jul 2021 20:33:48 +0000 (15:33 -0500)
committerSage Weil <sage@newdream.net>
Mon, 26 Jul 2021 20:23:06 +0000 (16:23 -0400)
Signed-off-by: Sage Weil <sage@newdream.net>
qa/tasks/python.py [new file with mode: 0644]

diff --git a/qa/tasks/python.py b/qa/tasks/python.py
new file mode 100644 (file)
index 0000000..8dccd87
--- /dev/null
@@ -0,0 +1,45 @@
+import logging
+from teuthology import misc as teuthology
+from tasks.vip import subst_vip
+
+log = logging.getLogger(__name__)
+
+
+def task(ctx, config):
+    """
+    Execute some python code.
+      tasks:
+      - python:
+          host.a: |
+            import boto3
+            c = boto3.resource(...)
+
+    or
+
+      tasks:
+      - python:
+          sudo: true
+          host.b: |
+            import boto3
+            c = boto3.resource(...)
+
+    The provided dict is normally indexed by role.  However, you can also include a 
+    'sudo: true' key to run the code with sudo.
+    """
+    assert isinstance(config, dict), "task python got invalid config"
+
+    testdir = teuthology.get_testdir(ctx)
+
+    sudo = config.pop('sudo', False)
+
+    for role, code in config.items():
+        (remote,) = ctx.cluster.only(role).remotes.keys()
+        log.info('Running python on role %s host %s', role, remote.name)
+        log.info(code)
+        args=[
+            'TESTDIR={tdir}'.format(tdir=testdir),
+            'python3',
+        ]
+        remote.run(args=args, stdin=subst_vip(ctx, code))
+