From 793b84722a00efc10f5271634985b1936cf8d1d5 Mon Sep 17 00:00:00 2001 From: Andriy Yurkiv <70649192+ayurkiv-nvda@users.noreply.github.com> Date: Fri, 2 Jul 2021 09:40:06 +0300 Subject: [PATCH] [show priority-group drop counters] Remove backup with cached PG drop counters after 'config reload' (#1679) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - What I did Explanation how show/clear counters works: Suppose we got from SDK some count of dropped packets for priority group (№3) per interface (Ehernet4). (for example Ethernet4 PG-3 123 packets) Stats can be shown via show priority-group drop counters Then we run sonic-clear priority-group drop counters. This command will save data "Ethernet4 PG-3 123 packets" to backup. It saved in /tmp/dropstat-{user_id} folder When we run show priority-group drop counters again, script will take data from SDK and data saved from backup. In backup it will find 123. In SDK it may still be number 123 for Ethernet4 (like in backup) or bigger (for example 126.) Our sonic-clear priority-group drop counters command does not change anything in SDK. It just show difference beetwen SDK data and last saved data. So if in SDK data is 123, show priority-group drop counters will show 0 (123 minus 123) - data is cleared If in SDK data is bigger than saved 124, or higher show priority-group drop counters will show 1 (124 minus 123) FIX After config reload all counters drop counters data retrieved from SDK become cleared. All counters become zeros. In this case show priority-group drop counters will show -123 ( 0 (from SDK) minus 123 (saved backup)) So we don't need backup after config reload - How I did it remove /tmp/dropstat-{user_id} folders with counters backup Signed-off-by: Andriy Yurkiv --- config/main.py | 5 +++++ tests/pgdropstat_test.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/config/main.py b/config/main.py index 937933f85255..471a8f920a55 100644 --- a/config/main.py +++ b/config/main.py @@ -1253,6 +1253,11 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach if multi_asic.is_multi_asic(): num_cfg_file += num_asic + # Remove cached PG drop counters data + dropstat_dir_prefix = '/tmp/dropstat' + command = "rm -rf {}-*".format(dropstat_dir_prefix) + clicommon.run_command(command, display_cmd=True) + # If the user give the filename[s], extract the file names. if filename is not None: cfg_files = filename.split(',') diff --git a/tests/pgdropstat_test.py b/tests/pgdropstat_test.py index e896ded81174..ee156b7588e7 100644 --- a/tests/pgdropstat_test.py +++ b/tests/pgdropstat_test.py @@ -3,6 +3,7 @@ import show.main as show import clear.main as clear +import config.main as config from click.testing import CliRunner @@ -62,6 +63,20 @@ def executor(self, clear_before_show): assert result.exit_code == 0 assert result.output == show_output + def test_show_pg_drop_config_reload(self): + runner = CliRunner() + self.test_show_pg_drop_clear() + + # simulate 'config reload' to provoke counters recalculation (remove backup from /tmp folder) + result = runner.invoke(config.config.commands["reload"], [ "--no_service_restart", "-y"]) + + print(result.exit_code) + print(result.output) + + assert result.exit_code == 0 + + self.test_show_pg_drop_show() + @classmethod def teardown_class(cls): os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])