diff --git a/counterpoll/main.py b/counterpoll/main.py index cc0060d9915b..7c062e9d747f 100644 --- a/counterpoll/main.py +++ b/counterpoll/main.py @@ -276,18 +276,24 @@ def show(): click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) -def _update_config_db(status, filename): +def _update_config_db_flex_counter_table(status, filename): """ Update counter configuration in config_db file """ with open(filename) as config_db_file: config_db = json.load(config_db_file) write_config_db = False if "FLEX_COUNTER_TABLE" in config_db: - for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items(): - if "FLEX_COUNTER_STATUS" in counter_config and \ - counter_config["FLEX_COUNTER_STATUS"] is not status: - counter_config["FLEX_COUNTER_STATUS"] = status - write_config_db = True + if status != "delay": + for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items(): + if "FLEX_COUNTER_STATUS" in counter_config and \ + counter_config["FLEX_COUNTER_STATUS"] is not status: + counter_config["FLEX_COUNTER_STATUS"] = status + write_config_db = True + + elif status == "delay": + write_config_db = True + for key in config_db["FLEX_COUNTER_TABLE"].keys(): + config_db["FLEX_COUNTER_TABLE"][key].update({"FLEX_COUNTER_DELAY_STATUS":"true"}) if write_config_db: with open(filename, 'w') as config_db_file: @@ -302,11 +308,16 @@ def config_db(): @click.argument("filename", default="/etc/sonic/config_db.json", type=click.Path(exists=True)) def enable(filename): """ Enable counter configuration in config_db file """ - _update_config_db("enable", filename) + _update_config_db_flex_counter_table("enable", filename) @config_db.command() @click.argument("filename", default="/etc/sonic/config_db.json", type=click.Path(exists=True)) def disable(filename): """ Disable counter configuration in config_db file """ - _update_config_db("disable", filename) + _update_config_db_flex_counter_table("disable", filename) +@config_db.command() +@click.argument("filename", default="/etc/sonic/config_db.json", type=click.Path(exists=True)) +def delay(filename): + """ Delay counters in config_db file """ + _update_config_db_flex_counter_table("delay", filename) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 2abdb985b062..aa28954b4698 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -5,6 +5,7 @@ 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" @@ -36,6 +37,7 @@ EXIT_ORCHAGENT_SHUTDOWN=10 EXIT_SYNCD_SHUTDOWN=11 EXIT_FAST_REBOOT_DUMP_FAILURE=12 EXIT_FILTER_FDB_ENTRIES_FAILURE=13 +EXIT_COUNTERPOLL_DELAY_FAILURE=14 EXIT_NO_CONTROL_PLANE_ASSISTANT=20 EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21 @@ -513,7 +515,6 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then # Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6 # into /host/fast-reboot DUMP_DIR=/host/fast-reboot - CONFIG_DB_FILE=/etc/sonic/config_db.json mkdir -p $DUMP_DIR FAST_REBOOT_DUMP_RC=0 /usr/local/bin/fast-reboot-dump.py -t $DUMP_DIR || FAST_REBOOT_DUMP_RC=$? @@ -554,6 +555,17 @@ if [[ "$REBOOT_TYPE" = "warm-reboot" || "$REBOOT_TYPE" = "fastfast-reboot" ]]; t fi 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=$? + if [[ COUNTERPOLL_DELAY_RC -ne 0 ]]; then + error "Failed to delay counterpoll. Exit code: $COUNTERPOLL_DELAY_RC" + unload_kernel + exit "${EXIT_COUNTERPOLL_DELAY_FAILURE}" + fi +fi + # We are fully committed to reboot from this point on because critical # service will go down and we cannot recover from it. set +e