]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/ceph: extract update_archive_setting() 46149/head
authorLaura Flores <lflores@redhat.com>
Tue, 10 May 2022 15:44:15 +0000 (10:44 -0500)
committerLaura Flores <lflores@redhat.com>
Tue, 10 May 2022 15:44:15 +0000 (10:44 -0500)
for better readability

also update the comment in `ceph_crash()` to reflect the changed
settings

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 43f2738a0e748e5bb280ad011b7a17db9ce2d0e3)

qa/tasks/ceph.py

index 2f98dbd39371fb857bfcaf3d65f12f069754963e..4e27fac815d592bd2c2597f94a33255d2f49ed60 100644 (file)
@@ -73,21 +73,25 @@ def generate_caps(type_):
         yield capability
 
 
+def update_archive_setting(ctx, key, value):
+    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' in info_yaml:
+            info_yaml['archive'][key] = value
+        else:
+            info_yaml['archive'] = {key: value}
+        yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
+
+
 @contextlib.contextmanager
 def ceph_crash(ctx, config):
     """
     Gather crash dumps from /var/lib/ceph/crash
     """
 
-    # Add logs directory to job's info log file
-    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'] = {'crash': '/var/lib/ceph/crash'}
-        else:
-            info_yaml['archive']['crash'] = '/var/lib/ceph/crash'
-        yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
+    # Add crash directory to job's archive
+    update_archive_setting(ctx, 'crash', '/var/lib/ceph/crash')
 
     try:
         yield
@@ -159,14 +163,7 @@ def ceph_log(ctx, config):
     )
 
     # Add logs directory to job's info log file
-    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'] = {'log': '/var/log/ceph'}
-        else:
-            info_yaml['archive']['log'] = '/var/log/ceph'
-        yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
+    update_archive_setting(ctx, 'log', '/var/log/ceph')
 
     class Rotater(object):
         stop_event = gevent.event.Event()