diff --git a/counterpoll/main.py b/counterpoll/main.py index ad15c8c248..c3316b857d 100644 --- a/counterpoll/main.py +++ b/counterpoll/main.py @@ -14,10 +14,16 @@ DEFLT_10_SEC= "default (10000)" DEFLT_1_SEC = "default (1000)" + @click.group() -def cli(): +@click.pass_context +def cli(ctx): """ SONiC Static Counter Poll configurations """ + ctx.obj = ConfigDBConnector() + ctx.obj.connect() + + # Queue counter commands @cli.group() def queue(): @@ -382,6 +388,19 @@ def disable(ctx): fc_info['FLEX_COUNTER_STATUS'] = 'disable' ctx.obj.mod_entry("FLEX_COUNTER_TABLE", "FLOW_CNT_ROUTE", fc_info) + +@cli.command() +@click.pass_context +def delay(ctx): + """ Delays all counters for next boot """ + config_db = ctx.obj + + for key in config_db.get_keys('FLEX_COUNTER_TABLE'): + entry = config_db.get_entry('FLEX_COUNTER_TABLE', key) + entry['FLEX_COUNTER_DELAY_STATUS'] = 'true' + config_db.mod_entry('FLEX_COUNTER_TABLE', key, entry) + + @cli.command() def show(): """ Show the counter configuration """ diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 2eeca11112..0751cdde55 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -5,7 +5,6 @@ REBOOT_TIME=$(date) REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt" WARM_DIR=/host/warmboot REDIS_FILE=dump.rdb -CONFIG_DB_FILE=/etc/sonic/config_db.json REBOOT_SCRIPT_NAME=$(basename $0) REBOOT_TYPE="${REBOOT_SCRIPT_NAME}" SHUTDOWN_ORDER_FILE="/etc/sonic/${REBOOT_TYPE}_order" @@ -722,8 +721,8 @@ fi if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then COUNTERPOLL_DELAY_RC=0 - # Delay counters in config_db.json - /usr/local/bin/counterpoll config-db delay $CONFIG_DB_FILE || COUNTERPOLL_DELAY_RC=$? + # Delay counters in CONFIG_DB + /usr/local/bin/counterpoll delay || COUNTERPOLL_DELAY_RC=$? if [[ COUNTERPOLL_DELAY_RC -ne 0 ]]; then error "Failed to delay counterpoll. Exit code: $COUNTERPOLL_DELAY_RC" unload_kernel diff --git a/tests/counterpoll_test.py b/tests/counterpoll_test.py index 4a4da07ee9..caee62a89c 100644 --- a/tests/counterpoll_test.py +++ b/tests/counterpoll_test.py @@ -221,6 +221,21 @@ def test_update_route_counter_interval(self): assert result.exit_code == 2 assert expected in result.output + def test_delay(self): + runner = CliRunner() + db = Db() + + for key in db.cfgdb.get_keys('FLEX_COUNTER_TABLE'): + entry = db.cfgdb.get_entry('FLEX_COUNTER_TABLE', key) + assert 'FLEX_COUNTER_DELAY_STATUS' not in entry + + result = runner.invoke(counterpoll.cli.commands["delay"], [], obj=db.cfgdb) + print(result.exit_code, result.output) + assert result.exit_code == 0 + + for key in db.cfgdb.get_keys('FLEX_COUNTER_TABLE'): + entry = db.cfgdb.get_entry('FLEX_COUNTER_TABLE', key) + assert entry['FLEX_COUNTER_DELAY_STATUS'] == 'true' @classmethod def teardown_class(cls):