]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
refactor func that adds remote dirs to archive
authorShraddha Agrawal <shraddha.agrawal000@gmail.com>
Fri, 21 Aug 2020 10:16:08 +0000 (15:46 +0530)
committerJosh Durgin <jdurgin@redhat.com>
Sat, 16 Jan 2021 21:36:26 +0000 (16:36 -0500)
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 <shraddha.agrawal000@gmail.com>
teuthology/misc.py
teuthology/task/internal/__init__.py

index 4d6cfd5b5950cd86715522faa951111b0478d67e..45b5c5207644a610a98bcdbf78b5189387260bb1 100644 (file)
@@ -1324,3 +1324,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
index aa898c9b64fa3af9da5426b77e2254eb1964dc2d..b54c6110d214f0c141a6bde555132ef57b0cd512 100644 (file)
@@ -361,14 +361,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