From: Kefu Chai Date: Tue, 3 Nov 2020 03:57:34 +0000 (+0800) Subject: qa/tasks/ceph: extract update_archive_setting() X-Git-Tag: v16.1.0~648^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=43f2738a0e748e5bb280ad011b7a17db9ce2d0e3;p=ceph.git qa/tasks/ceph: extract update_archive_setting() for better readability also update the comment in `ceph_crash()` to reflect the changed settings Signed-off-by: Kefu Chai --- diff --git a/qa/tasks/ceph.py b/qa/tasks/ceph.py index 7b77f7588d2b..b088902706cf 100644 --- a/qa/tasks/ceph.py +++ b/qa/tasks/ceph.py @@ -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()