From fe627c50d2e1910b6f5a04024f97e974114875f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 16 Jun 2022 17:29:59 +0200 Subject: [PATCH] Fix deprecations handling in journal logs Currently deprecations log is only created for the first service, as indent is incorrect, so log created only when destination directory does not exist. Additionally flow changed to include deprications in output_files and moving verification of directory existance out of cycle. We also now interate over unique set of services, as before common_log_names and a-r-r were containing duplicates. Change-Id: Iec646c86f314acf825b06917149adcf7ce1e2248 --- scripts/journal_dump.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/journal_dump.py b/scripts/journal_dump.py index 0c94ef514a..ad521c2e69 100755 --- a/scripts/journal_dump.py +++ b/scripts/journal_dump.py @@ -82,9 +82,14 @@ def demux_one_journal(j): j_dir = j_dir + '/' + j['name'] d_dir = d_dir + '/deprecations/' + j['name'] + # Create regular logs directory if not os.path.isdir(j_dir): os.makedirs(j_dir) + # Create deperecations directory + if not os.path.isdir(d_dir): + os.makedirs(d_dir) + output_files = {} # for each journal entry, try to match it with the services we care about @@ -111,10 +116,21 @@ def demux_one_journal(j): continue d_filename = d_dir + s_name - if not os.path.isdir(d_dir): - os.makedirs(d_dir) - with open(d_filename, 'a') as d: - d.write(unit + ' ' + message + "\n") + if d_filename not in output_files: + output_files[d_filename] = open(d_filename, 'w') + output_files[d_filename].write(unit + ' ' + message + "\n") + + for fd in output_files.values(): + fd.close() + + # We created directories regardless if they needed or not. We should drop empty ones. + empty_dirs = set([j_dir, d_dir]) - set([os.path.dirname(fn) for fn in output_files.keys()]) + + for e_dir in empty_dirs: + try: + os.rmdir(e_dir) + except OSError: + continue print(''.join([' Written ' + k + '\n' for k in output_files.keys()])) @@ -144,7 +160,7 @@ if len(sys.argv) > 2: else: common_log_names = [] -service_names = common_log_names + get_ansible_role_names() +service_names = set(common_log_names + get_ansible_role_names()) print("Service names to search for " + str(service_names)) if os.getenv('WORKING_DIR') is not None: