diff --git a/scripts/coredump_gen_handler.py b/scripts/coredump_gen_handler.py index eaa972bdca1e..33d661e3dacf 100644 --- a/scripts/coredump_gen_handler.py +++ b/scripts/coredump_gen_handler.py @@ -19,10 +19,6 @@ def handle_coredump_cleanup(dump_name, db): - file_path = os.path.join(CORE_DUMP_DIR, dump_name) - if not verify_recent_file_creation(file_path): - return - _, num_bytes = get_stats(os.path.join(CORE_DUMP_DIR, CORE_DUMP_PTRN)) if db.get(CFG_DB, AUTO_TS, CFG_STATE) != "enabled": @@ -57,11 +53,6 @@ def __init__(self, core_name, container_name, db): self.core_ts_map = {} def handle_core_dump_creation_event(self): - file_path = os.path.join(CORE_DUMP_DIR, self.core_name) - if not verify_recent_file_creation(file_path): - syslog.syslog(syslog.LOG_INFO, "Spurious Invocation. {} is not created within last {} sec".format(file_path, TIME_BUF)) - return - if self.db.get(CFG_DB, AUTO_TS, CFG_STATE) != "enabled": syslog.syslog(syslog.LOG_NOTICE, "auto_invoke_ts is disabled. No cleanup is performed: core {}".format(self.core_name)) return @@ -106,7 +97,7 @@ def get_since_arg(self): since_cfg = self.db.get(CFG_DB, AUTO_TS, CFG_SINCE) if not since_cfg: return SINCE_DEFAULT - rc, _, stderr = subprocess_exec(["date", "--date='{}'".format(since_cfg)], env=ENV_VAR) + rc, _, stderr = subprocess_exec(["date", "--date={}".format(since_cfg)], env=ENV_VAR) if rc == 0: return since_cfg return SINCE_DEFAULT @@ -124,8 +115,8 @@ def invoke_ts_cmd(self, since_cfg): cmd_opts = ["show", "techsupport", "--silent", "--since", since_cfg] cmd = " ".join(cmd_opts) rc, stdout, stderr = subprocess_exec(cmd_opts, env=ENV_VAR) - if not rc: - syslog.syslog(syslog.LOG_ERR, "show techsupport failed with exit code {}, stderr:{}".format(rc, stderr)) + if rc: + syslog.syslog(syslog.LOG_ERR, "show techsupport failed with exit code {}, stderr: {}".format(rc, stderr)) new_dump = self.parse_ts_dump_name(stdout) if not new_dump: syslog.syslog(syslog.LOG_ERR, "{} was run, but no techsupport dump is found".format(cmd)) @@ -183,6 +174,10 @@ def main(): db = SonicV2Connector(use_unix_socket_path=True) db.connect(CFG_DB) db.connect(STATE_DB) + file_path = os.path.join(CORE_DUMP_DIR, args.name) + if not verify_recent_file_creation(file_path): + syslog.syslog(syslog.LOG_INFO, "Spurious Invocation. {} is not created within last {} sec".format(file_path, TIME_BUF)) + return cls = CriticalProcCoreDumpHandle(args.name, args.container, db) cls.handle_core_dump_creation_event() handle_coredump_cleanup(args.name, db) diff --git a/tests/coredump_gen_handler_test.py b/tests/coredump_gen_handler_test.py index 10a470b6b020..e5270460ebf1 100644 --- a/tests/coredump_gen_handler_test.py +++ b/tests/coredump_gen_handler_test.py @@ -267,7 +267,7 @@ def mock_cmd(cmd, env): if "--since '4 days ago'" in cmd_str: patcher.fs.create_file(ts_dump) return 0, AUTO_TS_STDOUT + ts_dump, "" - elif "date --date='4 days ago'" in cmd_str: + elif "date --date=4 days ago" in cmd_str: return 0, "", "" else: return 1, "", "Invalid Command" @@ -334,7 +334,7 @@ def mock_cmd(cmd, env): patcher.fs.create_file(ts_dump) print(AUTO_TS_STDOUT + ts_dump) return 0, AUTO_TS_STDOUT + ts_dump, "" - elif "date --date='whatever'" in cmd_str: + elif "date --date=whatever" in cmd_str: return 1, "", "Invalid Date Format" else: return 1, "", ""