From 9273a55fb4aec49fa1689d480abd6f449f9824d3 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Thu, 25 Aug 2022 08:43:30 -0600 Subject: [PATCH 1/9] CORTX-33043: removing rgw startup log file Signed-off-by: Sachitanand Shelake --- src/rgw/setup/radosgw_start | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rgw/setup/radosgw_start b/src/rgw/setup/radosgw_start index 6da18df..7569522 100644 --- a/src/rgw/setup/radosgw_start +++ b/src/rgw/setup/radosgw_start @@ -11,6 +11,5 @@ echo "Change RGW CWD to dir $RGW_CWD, to retain core files in there" cd $RGW_CWD set -o pipefail; -/usr/bin/radosgw -f --name client.rgw-$INDEX -c $CONFIG_FILE --no-mon-config 2>&1 \ - | while read line; do printf "%s %s\n" "$(date +'[%Y-%m-%d %H:%M:%S,%03N]')" "$line"; done | tee $LOG_FILE +/usr/bin/radosgw -f --name client.rgw-$INDEX -c $CONFIG_FILE --no-mon-config exit $? From 3ec71992185717c1b6e66e92ffcb8d220ee20e93 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Thu, 25 Aug 2022 08:55:39 -0600 Subject: [PATCH 2/9] added more fixes Signed-off-by: Sachitanand Shelake --- src/rgw/setup/radosgw_start | 3 +-- src/rgw/setup/rgw.py | 3 +-- src/rgw/setup/rgw_service.py | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rgw/setup/radosgw_start b/src/rgw/setup/radosgw_start index 7569522..76692e3 100644 --- a/src/rgw/setup/radosgw_start +++ b/src/rgw/setup/radosgw_start @@ -2,8 +2,7 @@ INDEX=$1 CONFIG_FILE=$2 -LOG_FILE=$3 -RGW_CWD=$4 +RGW_CWD=$3 [ -z "$RGW_CWD" ] && RGW_CWD="$PWD" diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index df712f7..cd52cf1 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -161,9 +161,8 @@ def start(conf: MappedConf, index: str): os.makedirs(rgw_core_dir, exist_ok=True) Log.info('Starting radosgw service.') - log_file = os.path.join(log_path, f'{const.COMPONENT_NAME}_startup.log') - RgwService.start(conf, config_file, log_file, motr_trace_dir, addb_dir, rgw_core_dir, index) + RgwService.start(conf, config_file, motr_trace_dir, addb_dir, rgw_core_dir, index) Log.info("Started radosgw service.") return 0 diff --git a/src/rgw/setup/rgw_service.py b/src/rgw/setup/rgw_service.py index 1ee1f3e..0ed70e7 100755 --- a/src/rgw/setup/rgw_service.py +++ b/src/rgw/setup/rgw_service.py @@ -27,7 +27,7 @@ class RgwService: """Entrypoint class for RGW.""" @staticmethod - def start(conf: MappedConf, config_file, log_file, motr_trace_dir, addb_dir, rgw_cwd, index: str = '1',): + def start(conf: MappedConf, config_file, motr_trace_dir, addb_dir, rgw_cwd, index: str = '1',): """Start rgw service independently.""" try: os.environ['M0_TRACE_DIR'] = motr_trace_dir @@ -35,7 +35,7 @@ def start(conf: MappedConf, config_file, log_file, motr_trace_dir, addb_dir, rgw cmd = os.path.join(INSTALL_PATH, COMPONENT_NAME, 'bin/radosgw_start') sys.stdout.flush() sys.stderr.flush() - os.execl(cmd, cmd, index, config_file, log_file, rgw_cwd) + os.execl(cmd, cmd, index, config_file, rgw_cwd) except OSError as e: Log.error(f"Failed to start radosgw service:{e}") raise SetupError(e.errno, "Failed to start radosgw service. %s", e) From c95c6aa8ac81bcc275827bedb5b28d63d117ba3c Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Mon, 29 Aug 2022 06:07:03 -0600 Subject: [PATCH 3/9] logic for update addb, m0trace log path in cron file Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index cd52cf1..3704a70 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -831,6 +831,7 @@ def _logrotate_generic(conf: MappedConf): except Exception as e: Log.error(f"Failed to configure core file's logrotate for {const.COMPONENT_NAME}. ERROR:{e}") + Rgw._update_motr_log_rotate_scripts(conf, log_file_path) # start cron.d service try: os.system(f"chmod +x {const.CRON_LOGROTATE}") @@ -838,6 +839,53 @@ def _logrotate_generic(conf: MappedConf): except Exception as e: Log.error(f"Failed to start the crond service for {const.COMPONENT_NAME}. ERROR:{e}") + @staticmethod + def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): + """"Update correct PVC path of m0trace, addb log directory for motr log rotate script""" + motr_addb_file_fid = Conf.get(Rgw._conf_idx, const.MOTR_ADMIN_FID_KEY) + addb_log_dir_path = os.path.join(svc_log_dir, f'addb_files-{motr_addb_file_fid}') + addb_log_rotate_script = os.path.join(const.CRON_DIR, 'm0addb_logrotate.sh') + motr_trace_log_path = os.path.join(svc_log_dir, 'motr_trace_files') + motr_trace_rotate_script = os.path.join(const.CRON_DIR, 'm0trace_logrotate.sh') + + if not os.path.exists(addb_log_rotate_script) or not os.path.exists(motr_trace_rotate_script): + Log.info(f'WARNING:: {const.CRON_DIR} does not has addb/m0trace motr log rotate scripts.') + return + # Handle m0trace log rotate script path. + try: + with open(motr_trace_rotate_script, 'r') as f: + content = f.read() + for line in content : + if line.startswith("M0TR_M0D_TRACE_DIR="): + line_key = line.split("=")[0] + new_line = line_key + "=" + motr_trace_log_path + content = content.replace(line, new_line) + break + + with open(motr_trace_rotate_script, 'w') as f: + f.write(content) + Log.info(f'{motr_trace_rotate_script} file updated with log path {motr_trace_log_path}') + except Exception as e: + Log.error(f"Failed to update m0trace log rotation script path. ERROR:{e}") + + # Handle addb trace log rotate script path. + try: + with open(addb_log_rotate_script, 'r') as f: + content = f.read() + for line in content : + if line.startswith("ADDB_RECORD_DIR="): + line_key = line.split("=")[0] + new_line = line_key + "=" + addb_log_dir_path + content = content.replace(line, new_line) + break + + with open(addb_log_rotate_script, 'w') as f: + f.write(content) + Log.info(f'{addb_log_rotate_script} file updated with log path {addb_log_dir_path}') + except Exception as e: + Log.error(f"Failed to update m0addb log rotation script path. ERROR:{e}") + + @staticmethod def _verify_backend_store_value(conf: MappedConf): """Verify backed store value as motr.""" From 17770c97c7f7e0177a4f0960c652ae0ab2bc9874 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Mon, 29 Aug 2022 07:51:32 -0600 Subject: [PATCH 4/9] refactoing code Signed-off-by: Sachitanand Shelake --- src/rgw/const.py | 3 +++ src/rgw/setup/rgw.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/rgw/const.py b/src/rgw/const.py index 18b4c9b..0974f4a 100644 --- a/src/rgw/const.py +++ b/src/rgw/const.py @@ -59,6 +59,9 @@ FREQUENCY='hourly' CRON_DIR = f'/etc/cron.{FREQUENCY}' CRON_LOGROTATE = f'{CRON_DIR}/logrotate' +M0TRACE_LOG_ROTATE_FILE = f'{CRON_DIR}/m0trace_logrotate.sh' +ADDB_LOG_ROTATE_FILE = f'{CRON_DIR}/m0addb_logrotate.sh' + REQUIRED_RPMS = ['cortx-hare', 'cortx-py-utils', 'ceph-radosgw'] ADMIN_PARAMETERS = {'MOTR_ADMIN_FID':'motr admin fid', 'MOTR_ADMIN_ENDPOINT':'motr admin endpoint', 'RGW_FRONTENDS': 'rgw frontends'} diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index 3704a70..cb6949e 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -844,16 +844,15 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): """"Update correct PVC path of m0trace, addb log directory for motr log rotate script""" motr_addb_file_fid = Conf.get(Rgw._conf_idx, const.MOTR_ADMIN_FID_KEY) addb_log_dir_path = os.path.join(svc_log_dir, f'addb_files-{motr_addb_file_fid}') - addb_log_rotate_script = os.path.join(const.CRON_DIR, 'm0addb_logrotate.sh') motr_trace_log_path = os.path.join(svc_log_dir, 'motr_trace_files') - motr_trace_rotate_script = os.path.join(const.CRON_DIR, 'm0trace_logrotate.sh') - if not os.path.exists(addb_log_rotate_script) or not os.path.exists(motr_trace_rotate_script): + if not os.path.exists(const.ADDB_LOG_ROTATE_FILE) or \ + not os.path.exists(const.M0TRACE_LOG_ROTATE_FILE): Log.info(f'WARNING:: {const.CRON_DIR} does not has addb/m0trace motr log rotate scripts.') return # Handle m0trace log rotate script path. try: - with open(motr_trace_rotate_script, 'r') as f: + with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f: content = f.read() for line in content : if line.startswith("M0TR_M0D_TRACE_DIR="): @@ -862,15 +861,15 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): content = content.replace(line, new_line) break - with open(motr_trace_rotate_script, 'w') as f: + with open(const.M0TRACE_LOG_ROTATE_FILE, 'w') as f: f.write(content) - Log.info(f'{motr_trace_rotate_script} file updated with log path {motr_trace_log_path}') + Log.info(f'{const.M0TRACE_LOG_ROTATE_FILE} file updated with log path {motr_trace_log_path}') except Exception as e: Log.error(f"Failed to update m0trace log rotation script path. ERROR:{e}") # Handle addb trace log rotate script path. try: - with open(addb_log_rotate_script, 'r') as f: + with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f: content = f.read() for line in content : if line.startswith("ADDB_RECORD_DIR="): @@ -879,9 +878,9 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): content = content.replace(line, new_line) break - with open(addb_log_rotate_script, 'w') as f: + with open(const.ADDB_LOG_ROTATE_FILE, 'w') as f: f.write(content) - Log.info(f'{addb_log_rotate_script} file updated with log path {addb_log_dir_path}') + Log.info(f'{const.ADDB_LOG_ROTATE_FILE} file updated with log path {addb_log_dir_path}') except Exception as e: Log.error(f"Failed to update m0addb log rotation script path. ERROR:{e}") From 4733e1494832ae55a14e83bad598bf903647483d Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Tue, 30 Aug 2022 01:04:34 -0600 Subject: [PATCH 5/9] fixing config phase issue Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index cb6949e..bd89644 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -842,6 +842,10 @@ def _logrotate_generic(conf: MappedConf): @staticmethod def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): """"Update correct PVC path of m0trace, addb log directory for motr log rotate script""" + config_file = Rgw._get_rgw_config_path(conf) + confstore_url = const.CONFSTORE_FILE_HANDLER + config_file + Rgw._load_rgw_config(Rgw._conf_idx, confstore_url) + motr_addb_file_fid = Conf.get(Rgw._conf_idx, const.MOTR_ADMIN_FID_KEY) addb_log_dir_path = os.path.join(svc_log_dir, f'addb_files-{motr_addb_file_fid}') motr_trace_log_path = os.path.join(svc_log_dir, 'motr_trace_files') From d4d06ca677b88dce1be802c39e9ac1aaf612e2c9 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Tue, 30 Aug 2022 06:54:48 -0600 Subject: [PATCH 6/9] fixed path updation issue Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index bd89644..f50ef50 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -857,16 +857,17 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): # Handle m0trace log rotate script path. try: with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f: - content = f.read() - for line in content : - if line.startswith("M0TR_M0D_TRACE_DIR="): - line_key = line.split("=")[0] - new_line = line_key + "=" + motr_trace_log_path - content = content.replace(line, new_line) - break - - with open(const.M0TRACE_LOG_ROTATE_FILE, 'w') as f: - f.write(content) + lines=f.readlines() + tmp_file = "/tmp/tmp_m0trace.sh" + with open(tmp_file, 'w') as tmp_file: + for line in lines : + if line.startswith("M0TR_M0D_TRACE_DIR="): + trace_dir_val = line.split("=")[1] + line = line.replace(trace_dir_val, motr_trace_log_path) + tmp_file.write(line) + + shutil.copyfile(tmp_file, const.M0TRACE_LOG_ROTATE_FILE) + os.remove(tmp_file) Log.info(f'{const.M0TRACE_LOG_ROTATE_FILE} file updated with log path {motr_trace_log_path}') except Exception as e: Log.error(f"Failed to update m0trace log rotation script path. ERROR:{e}") @@ -874,16 +875,18 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): # Handle addb trace log rotate script path. try: with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f: - content = f.read() - for line in content : - if line.startswith("ADDB_RECORD_DIR="): - line_key = line.split("=")[0] - new_line = line_key + "=" + addb_log_dir_path - content = content.replace(line, new_line) - break - - with open(const.ADDB_LOG_ROTATE_FILE, 'w') as f: - f.write(content) + lines=f.readlines() + tmp_file = "/tmp/tmp_m0addb_log.sh" + with open(tmp_file, 'w') as tmp_file: + for line in lines : + if line.startswith("ADDB_RECORD_DIR="): + addb_dir_val = line.split("=")[1] + line = line.replace(addb_dir_val, addb_log_dir_path) + tmp_file.write(line) + + shutil.copyfile(tmp_file, const.ADDB_LOG_ROTATE_FILE) + os.remove(tmp_file) + Log.info(f'{const.ADDB_LOG_ROTATE_FILE} file updated with log path {addb_log_dir_path}') except Exception as e: Log.error(f"Failed to update m0addb log rotation script path. ERROR:{e}") From 69bcd6dea0c207bf54e4482d887a6dde02dd85d3 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Tue, 30 Aug 2022 08:18:13 -0600 Subject: [PATCH 7/9] more fixes Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index f50ef50..0d6bfcc 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -857,14 +857,15 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): # Handle m0trace log rotate script path. try: with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f: - lines=f.readlines() + lines = f.readlines() tmp_file = "/tmp/tmp_m0trace.sh" - with open(tmp_file, 'w') as tmp_file: - for line in lines : + with open(tmp_file, 'w') as tmp_fout: + for idx, line in enumerate(lines): if line.startswith("M0TR_M0D_TRACE_DIR="): - trace_dir_val = line.split("=")[1] - line = line.replace(trace_dir_val, motr_trace_log_path) - tmp_file.write(line) + trace_key_name = line.split("=")[0] + updated_line = trace_key_name + "=" + f'\"{motr_trace_log_path}\"' + "\n" + lines[idx] = updated_line + tmp_fout.write(lines[idx]) shutil.copyfile(tmp_file, const.M0TRACE_LOG_ROTATE_FILE) os.remove(tmp_file) @@ -875,14 +876,15 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): # Handle addb trace log rotate script path. try: with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f: - lines=f.readlines() + lines = f.readlines() tmp_file = "/tmp/tmp_m0addb_log.sh" - with open(tmp_file, 'w') as tmp_file: - for line in lines : + with open(tmp_file, 'w') as tmp_fout: + for idx, line in enumerate(lines): if line.startswith("ADDB_RECORD_DIR="): - addb_dir_val = line.split("=")[1] - line = line.replace(addb_dir_val, addb_log_dir_path) - tmp_file.write(line) + addb_dir_key = line.split("=")[0] + updated_line = addb_dir_key + "=" + f'\"{addb_log_dir_path}\"' + "\n" + lines[idx] = updated_line + tmp_fout.write(lines[idx]) shutil.copyfile(tmp_file, const.ADDB_LOG_ROTATE_FILE) os.remove(tmp_file) From 938fe36f938e51111e8ca8b5f423142c7f87f5a7 Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Tue, 30 Aug 2022 08:24:12 -0600 Subject: [PATCH 8/9] codacy warning Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index 0d6bfcc..3e73975 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -858,7 +858,7 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): try: with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f: lines = f.readlines() - tmp_file = "/tmp/tmp_m0trace.sh" + tmp_file = os.path.join('/tmp', 'tmp_m0trace.sh') with open(tmp_file, 'w') as tmp_fout: for idx, line in enumerate(lines): if line.startswith("M0TR_M0D_TRACE_DIR="): @@ -877,7 +877,7 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): try: with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f: lines = f.readlines() - tmp_file = "/tmp/tmp_m0addb_log.sh" + tmp_file = os.path.join('/tmp', 'tmp_m0addb_log.sh') with open(tmp_file, 'w') as tmp_fout: for idx, line in enumerate(lines): if line.startswith("ADDB_RECORD_DIR="): From 54dd2da8c964ea0e3886a69e3f165e58f26a096f Mon Sep 17 00:00:00 2001 From: Sachitanand Shelake Date: Tue, 30 Aug 2022 08:57:23 -0600 Subject: [PATCH 9/9] fixing codacy warning Signed-off-by: Sachitanand Shelake --- src/rgw/setup/rgw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rgw/setup/rgw.py b/src/rgw/setup/rgw.py index 3e73975..d89fdf4 100644 --- a/src/rgw/setup/rgw.py +++ b/src/rgw/setup/rgw.py @@ -858,7 +858,7 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): try: with open(const.M0TRACE_LOG_ROTATE_FILE, 'r') as f: lines = f.readlines() - tmp_file = os.path.join('/tmp', 'tmp_m0trace.sh') + tmp_file = os.path.join(const.CRON_DIR, 'tmp_m0trace.sh') with open(tmp_file, 'w') as tmp_fout: for idx, line in enumerate(lines): if line.startswith("M0TR_M0D_TRACE_DIR="): @@ -877,7 +877,7 @@ def _update_motr_log_rotate_scripts(conf: MappedConf, svc_log_dir: str): try: with open(const.ADDB_LOG_ROTATE_FILE, 'r') as f: lines = f.readlines() - tmp_file = os.path.join('/tmp', 'tmp_m0addb_log.sh') + tmp_file = os.path.join(const.CRON_DIR, 'tmp_m0addb_log.sh') with open(tmp_file, 'w') as tmp_fout: for idx, line in enumerate(lines): if line.startswith("ADDB_RECORD_DIR="):