Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fast-reboot] Set flex counters delay indicator to prevent flex counters enablement after fast-reboot #1768

Merged
merged 6 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

shlomibitton marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -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):
shlomibitton marked this conversation as resolved.
Show resolved Hide resolved
""" Delay counters in config_db file """
_update_config_db_flex_counter_table("delay", filename)
14 changes: 13 additions & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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=$?
Expand Down Expand Up @@ -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
Expand Down