Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmed-dev committed Oct 17, 2020
1 parent 51c0b96 commit d627998
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
22 changes: 3 additions & 19 deletions counterpoll/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
18 changes: 4 additions & 14 deletions tests/counterpoll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d627998

Please sign in to comment.