From: Xiubo Li Date: Tue, 15 Dec 2020 02:49:28 +0000 (+0800) Subject: teuthology: run the ship_utilities task only once X-Git-Tag: 1.1.0~25^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1590%2Fhead;p=teuthology.git teuthology: run the ship_utilities task only once This will make sure that the utilities won't removed until the last user is unwound. Signed-off-by: Xiubo Li --- diff --git a/teuthology/task/install/util.py b/teuthology/task/install/util.py index 64268221f..dce71ec2b 100644 --- a/teuthology/task/install/util.py +++ b/teuthology/task/install/util.py @@ -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, - ), - )