Skip to content

Commit 9e30871

Browse files
authored
[Auto Techsupport] Event driven Techsupport Bug Fixes (sonic-net#1986)
- What I did Two bugs were found related to this feature. This PR included fixes for this. 1. non-default since argument is not being applied. Happening because subprocess_exec(["date", "--date='{}'".format(since_cfg)]) is failing. Replacing this with subprocess_exec(["date", "--date={}".format(since_cfg)]) solved the problem. 2. core_cleanup is not working because of the unnecessary recent_file_creation check. - How I did it Remove '' from date - How to verify it Run manual test flow which found the issue Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
1 parent fbd565d commit 9e30871

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

scripts/coredump_gen_handler.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020

2121
def handle_coredump_cleanup(dump_name, db):
22-
file_path = os.path.join(CORE_DUMP_DIR, dump_name)
23-
if not verify_recent_file_creation(file_path):
24-
return
25-
2622
_, num_bytes = get_stats(os.path.join(CORE_DUMP_DIR, CORE_DUMP_PTRN))
2723

2824
if db.get(CFG_DB, AUTO_TS, CFG_STATE) != "enabled":
@@ -57,11 +53,6 @@ def __init__(self, core_name, container_name, db):
5753
self.core_ts_map = {}
5854

5955
def handle_core_dump_creation_event(self):
60-
file_path = os.path.join(CORE_DUMP_DIR, self.core_name)
61-
if not verify_recent_file_creation(file_path):
62-
syslog.syslog(syslog.LOG_INFO, "Spurious Invocation. {} is not created within last {} sec".format(file_path, TIME_BUF))
63-
return
64-
6556
if self.db.get(CFG_DB, AUTO_TS, CFG_STATE) != "enabled":
6657
syslog.syslog(syslog.LOG_NOTICE, "auto_invoke_ts is disabled. No cleanup is performed: core {}".format(self.core_name))
6758
return
@@ -106,7 +97,7 @@ def get_since_arg(self):
10697
since_cfg = self.db.get(CFG_DB, AUTO_TS, CFG_SINCE)
10798
if not since_cfg:
10899
return SINCE_DEFAULT
109-
rc, _, stderr = subprocess_exec(["date", "--date='{}'".format(since_cfg)], env=ENV_VAR)
100+
rc, _, stderr = subprocess_exec(["date", "--date={}".format(since_cfg)], env=ENV_VAR)
110101
if rc == 0:
111102
return since_cfg
112103
return SINCE_DEFAULT
@@ -124,8 +115,8 @@ def invoke_ts_cmd(self, since_cfg):
124115
cmd_opts = ["show", "techsupport", "--silent", "--since", since_cfg]
125116
cmd = " ".join(cmd_opts)
126117
rc, stdout, stderr = subprocess_exec(cmd_opts, env=ENV_VAR)
127-
if not rc:
128-
syslog.syslog(syslog.LOG_ERR, "show techsupport failed with exit code {}, stderr:{}".format(rc, stderr))
118+
if rc:
119+
syslog.syslog(syslog.LOG_ERR, "show techsupport failed with exit code {}, stderr: {}".format(rc, stderr))
129120
new_dump = self.parse_ts_dump_name(stdout)
130121
if not new_dump:
131122
syslog.syslog(syslog.LOG_ERR, "{} was run, but no techsupport dump is found".format(cmd))
@@ -183,6 +174,10 @@ def main():
183174
db = SonicV2Connector(use_unix_socket_path=True)
184175
db.connect(CFG_DB)
185176
db.connect(STATE_DB)
177+
file_path = os.path.join(CORE_DUMP_DIR, args.name)
178+
if not verify_recent_file_creation(file_path):
179+
syslog.syslog(syslog.LOG_INFO, "Spurious Invocation. {} is not created within last {} sec".format(file_path, TIME_BUF))
180+
return
186181
cls = CriticalProcCoreDumpHandle(args.name, args.container, db)
187182
cls.handle_core_dump_creation_event()
188183
handle_coredump_cleanup(args.name, db)

tests/coredump_gen_handler_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def mock_cmd(cmd, env):
267267
if "--since '4 days ago'" in cmd_str:
268268
patcher.fs.create_file(ts_dump)
269269
return 0, AUTO_TS_STDOUT + ts_dump, ""
270-
elif "date --date='4 days ago'" in cmd_str:
270+
elif "date --date=4 days ago" in cmd_str:
271271
return 0, "", ""
272272
else:
273273
return 1, "", "Invalid Command"
@@ -334,7 +334,7 @@ def mock_cmd(cmd, env):
334334
patcher.fs.create_file(ts_dump)
335335
print(AUTO_TS_STDOUT + ts_dump)
336336
return 0, AUTO_TS_STDOUT + ts_dump, ""
337-
elif "date --date='whatever'" in cmd_str:
337+
elif "date --date=whatever" in cmd_str:
338338
return 1, "", "Invalid Date Format"
339339
else:
340340
return 1, "", ""

0 commit comments

Comments
 (0)