Skip to content

Commit

Permalink
[Auto Techsupport] Event driven Techsupport Bug Fixes (sonic-net#1986)
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
vivekrnv authored Jan 2, 2022
1 parent fbd565d commit 9e30871
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions scripts/coredump_gen_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/coredump_gen_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, "", ""
Expand Down

0 comments on commit 9e30871

Please sign in to comment.