From 834d693a17614bd29de20b480b0b20aef45cf88c Mon Sep 17 00:00:00 2001 From: Vivek Date: Wed, 13 Jul 2022 06:22:18 -0700 Subject: [PATCH] [202205][Auto-Techsupport] Fix the coredump_gen_handler Exception when the History table is empty (#2265) coredump_gen_handler script is throwing exception currently when the history table is empty. Fix this issue and add a UT Signed-off-by: Vivek Reddy Karri Signed-off-by: Stepan Blyschak --- tests/coredump_gen_handler_test.py | 19 +++++++++++++++++++ utilities_common/auto_techsupport_helper.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/coredump_gen_handler_test.py b/tests/coredump_gen_handler_test.py index 807eaa5a94..49ed16e4ab 100644 --- a/tests/coredump_gen_handler_test.py +++ b/tests/coredump_gen_handler_test.py @@ -450,3 +450,22 @@ def mock_cmd(cmd, env): cls = cdump_mod.CriticalProcCoreDumpHandle("orchagent.12345.123.core.gz", "swss", redis_mock) cls.handle_core_dump_creation_event() + def test_auto_ts_empty_state_db(self): + """ + Scenario: Check if the techsupport is called as expected even when the history table in empty + and container cooloff is non-zero + """ + db_wrap = Db() + redis_mock = db_wrap.db + set_auto_ts_cfg(redis_mock, state="enabled", since_cfg="2 days ago") + set_feature_table_cfg(redis_mock, state="enabled", rate_limit_interval="300") + with Patcher() as patcher: + def mock_cmd(cmd, env): + cmd_str = " ".join(cmd) + if "show techsupport" in cmd_str and cmd_str != TS_DEFAULT_CMD: + assert False, "Expected TS_CMD: {}, Recieved: {}".format(TS_DEFAULT_CMD, cmd_str) + return 0, AUTO_TS_STDOUT, "" + ts_helper.subprocess_exec = mock_cmd + patcher.fs.create_file("/var/core/orchagent.12345.123.core.gz") + cls = cdump_mod.CriticalProcCoreDumpHandle("orchagent.12345.123.core.gz", "swss", redis_mock) + cls.handle_core_dump_creation_event() diff --git a/utilities_common/auto_techsupport_helper.py b/utilities_common/auto_techsupport_helper.py index 019ffb54e6..f9382bf2af 100644 --- a/utilities_common/auto_techsupport_helper.py +++ b/utilities_common/auto_techsupport_helper.py @@ -257,7 +257,7 @@ def get_ts_map(db): ts_map = {} ts_keys = db.keys(STATE_DB, TS_MAP+"*") if not ts_keys: - return + return ts_map for ts_key in ts_keys: data = db.get_all(STATE_DB, ts_key) if not data: