From: Shraddha Agrawal Date: Fri, 21 Aug 2020 10:16:08 +0000 (+0530) Subject: refactor func that adds remote dirs to archive X-Git-Tag: 1.1.0~17^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d913ddf2ce63a4d3b33173b9175943844d4299c2;p=teuthology.git refactor func that adds remote dirs to archive This commit extracts function that adds key/value pair to job's info.yaml. These key/value pairs are used to archive logs in case of job timeout. Signed-off-by: Shraddha Agrawal --- diff --git a/teuthology/misc.py b/teuthology/misc.py index 0ddd2e836..e444a9a91 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -1345,3 +1345,18 @@ def sh(command, log_limit=1024, cwd=None, env=None): output=output ) return output + + +def add_remote_path(ctx, local_dir, remote_dir): + """ + Add key/value pair (local_dir: remote_dir) to job's info.yaml. + These key/value pairs are read to archive them in case of job timeout. + """ + with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file: + info_yaml = yaml.safe_load(info_file) + info_file.seek(0) + if 'archive' not in info_yaml: + info_yaml['archive'] = {local_dir: remote_dir} + else: + info_yaml['archive'][local_dir] = remote_dir + yaml.safe_dump(info_yaml, info_file, default_flow_style=False) \ No newline at end of file diff --git a/teuthology/task/internal/__init__.py b/teuthology/task/internal/__init__.py index a73bc02f3..e072a9741 100644 --- a/teuthology/task/internal/__init__.py +++ b/teuthology/task/internal/__init__.py @@ -348,14 +348,8 @@ def archive(ctx, config): ) ) - with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file: - info_yaml = yaml.safe_load(info_file) - info_file.seek(0) - if 'archive' not in info_yaml: - info_yaml['archive'] = {'init': archive_dir} - else: - info_yaml['archive']['init'] = archive_dir - yaml.safe_dump(info_yaml, info_file, default_flow_style=False) + # Add logs directory to job's info log file + misc.add_remote_path(ctx, 'init', archive_dir) try: yield