]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
teuthology: run the ship_utilities task only once 1590/head
authorXiubo Li <xiubli@redhat.com>
Tue, 15 Dec 2020 02:49:28 +0000 (10:49 +0800)
committerXiubo Li <xiubli@redhat.com>
Wed, 16 Dec 2020 15:25:33 +0000 (23:25 +0800)
This will make sure that the utilities won't removed until the last
user is unwound.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
teuthology/task/install/util.py

index 64268221fd89d4f135400ce54b6611607b5bcf5a..dce71ec2b6e28ec7f64a049bbe470c9357e54f8e 100644 (file)
@@ -51,18 +51,14 @@ def get_flavor(config):
                 flavor = 'gcov'
     return flavor
 
-
-@contextlib.contextmanager
-def ship_utilities(ctx, config):
+def _ship_utilities(ctx):
     """
     Write a copy of valgrind.supp to each of the remote sites.  Set executables
     used by Ceph in /usr/local/bin.  When finished (upon exit of the teuthology
     run), remove these files.
 
     :param ctx: Context
-    :param config: Configuration
     """
-    assert config is None
     testdir = teuthology.get_testdir(ctx)
     filenames = []
 
@@ -109,19 +105,49 @@ def ship_utilities(ctx, config):
                         dst,
                     ],
                 )
+    return filenames
 
-    try:
+def _remove_utilities(ctx, filenames):
+    """
+    Remove the shipped utilities.
+
+    :param ctx: Context
+    :param filenames: The utilities install paths
+    """
+    log.info('Removing shipped files: %s...', ' '.join(filenames))
+    if filenames == []:
+        return
+    run.wait(
+        ctx.cluster.run(
+            args=[
+                'sudo',
+                'rm',
+                '-f',
+                '--',
+            ] + list(filenames),
+            wait=False,
+        ),
+    )
+
+@contextlib.contextmanager
+def ship_utilities(ctx, config):
+    """
+    Ship utilities during the first call, and skip it in the following ones.
+    See also `_ship_utilities`.
+
+    :param ctx: Context
+    :param config: Configuration
+    """
+    assert config is None
+
+    do_ship_utilities = ctx.get('do_ship_utilities', True)
+    if do_ship_utilities:
+        ctx['do_ship_utilities'] = False
+        filenames = _ship_utilities(ctx)
+        try:
+            yield
+        finally:
+            _remove_utilities(ctx, filenames)
+    else:
+        log.info('Utilities already shipped, skip it...')
         yield
-    finally:
-        log.info('Removing shipped files: %s...', ' '.join(filenames))
-        run.wait(
-            ctx.cluster.run(
-                args=[
-                    'sudo',
-                    'rm',
-                    '-f',
-                    '--',
-                ] + list(filenames),
-                wait=False,
-            ),
-        )