]> 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)
committerShraddha Agrawal <shraddha.agrawal000@gmail.com>
Fri, 21 Aug 2020 10:16:08 +0000 (15:46 +0530)
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 0ddd2e8368aa61ecd334329c2672bdc110ed54ae..e444a9a9180d25dc7e8e5d63a65c2e6757a1dd40 100644 (file)
@@ -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
index a73bc02f38c0dac3ca8b1aaf5560e1105bad629a..e072a974160fc3ba373b540d67fd5a0b1c84e3c7 100644 (file)
@@ -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