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] Fix delaying counters: apply config to running CONFIG_DB #89

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 20 additions & 1 deletion counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 """
Expand Down
5 changes: 2 additions & 3 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/counterpoll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading