diff --git a/counterpoll/main.py b/counterpoll/main.py index bdafbfcd4f..4d9262baec 100644 --- a/counterpoll/main.py +++ b/counterpoll/main.py @@ -235,31 +235,15 @@ def show(): click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) -def _update_config_db(state, filename): +def _update_config_db(status, filename): """ Update counter configuration in config_db file """ with open(filename) as config_db_file: config_db = json.load(config_db_file) - counters = [ - "QUEUE_WATERMARK", - "BUFFER_POOL_WATERMARK", - "PFCWD", - "QUEUE", - "PG_WATERMARK", - "PORT_BUFFER_DROP", - "RIF", - "PORT", - ] - - write_config_db = False if "FLEX_COUNTER_TABLE" in config_db: - for counter in counters: - if counter in config_db["FLEX_COUNTER_TABLE"] and \ - "FLEX_COUNTER_STATUS" in config_db["FLEX_COUNTER_TABLE"][counter]: - config_db["FLEX_COUNTER_TABLE"][counter]["FLEX_COUNTER_STATUS"] = state - write_config_db = True + for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items(): + counter_config["FLEX_COUNTER_STATUS"] = status - if write_config_db: with open(filename, 'w') as config_db_file: json.dump(config_db, config_db_file, indent=4) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index e0a32f1672..378ae255d6 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -622,7 +622,7 @@ if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then # Disable counters in config_db.json /usr/local/bin/counterpoll config-db disable $CONFIG_DB_FILE || COUNTERPOLL_DISABLE_RC=$? if [[ COUNTERPOLL_DISABLE_RC -ne 0 ]]; then - error "Failed to disable couterpoll. Exit code: $COUNTERPOLL_DISABLE_RC" + error "Failed to disable counterpoll. Exit code: $COUNTERPOLL_DISABLE_RC" /usr/local/bin/counterpoll config-db enable $CONFIG_DB_FILE || COUNTERPOLL_DISABLE_RC=$? unload_kernel exit "${EXIT_COUNTERPOLL_DISABLE_FAILURE}" diff --git a/tests/counterpoll_test.py b/tests/counterpoll_test.py index 522b028da7..f08695e9bd 100644 --- a/tests/counterpoll_test.py +++ b/tests/counterpoll_test.py @@ -70,20 +70,10 @@ def test_update_counter_config_db_status(self, status, _get_config_db_file): with open(_get_config_db_file) as json_file: config_db = json.load(json_file) - counters = [ - "QUEUE_WATERMARK", - "BUFFER_POOL_WATERMARK", - "PFCWD", - "QUEUE", - "PG_WATERMARK", - "PORT_BUFFER_DROP", - "RIF", - "PORT", - ] - for counter in counters: - if counter in config_db["FLEX_COUNTER_TABLE"] and \ - "FLEX_COUNTER_STATUS" in config_db["FLEX_COUNTER_TABLE"][counter]: - assert config_db["FLEX_COUNTER_TABLE"][counter]["FLEX_COUNTER_STATUS"] == status + + if "FLEX_COUNTER_TABLE" in config_db: + for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items(): + assert counter_config["FLEX_COUNTER_STATUS"] == status @classmethod def teardown_class(cls):