Skip to content

Commit

Permalink
Support multi-asic clear command
Browse files Browse the repository at this point in the history
Multi-asic counter clear is supported by unconditionally caching
counters from all namespaces. Also add new UTs to cover changes.
  • Loading branch information
kenneth-arista committed Jun 30, 2024
1 parent a4344a3 commit b963c4e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 10 deletions.
34 changes: 27 additions & 7 deletions scripts/dropstat
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class DropStat(object):

dropstat_dir = get_dropstat_dir()
self.port_drop_stats_file = os.path.join(dropstat_dir, 'port-stats')
self.switch_drop_stats_file = os.path.join(dropstat_dir + 'switch-stats')
self.switch_std_drop_stats_file = os.path.join(dropstat_dir, 'switch-std-drop-stats')
self.switch_drop_stats_file = os.path.join(dropstat_dir, 'switch-stats')
self.switch_std_drop_stats_file = os.path.join(dropstat_dir, 'switch-std-drop-stats')

self.stat_lookup = {}
self.reverse_stat_lookup = {}
Expand All @@ -128,16 +128,36 @@ class DropStat(object):
Clears the current drop counts.
"""

try:
json.dump(self.get_counts_table(self.gather_counters(std_port_rx_counters + std_port_tx_counters, DEBUG_COUNTER_PORT_STAT_MAP), COUNTERS_PORT_NAME_MAP),
open(self.port_drop_stats_file, 'w+'))
counters_port_drop = {}
counters_switch_drop = {}
counters_switch_std_drop = {}
for ns in self.namespaces:
self.config_db = multi_asic.connect_config_db_for_ns(ns)
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)

counts = self.get_counts_table(self.gather_counters(std_port_rx_counters + std_port_tx_counters, DEBUG_COUNTER_PORT_STAT_MAP), COUNTERS_PORT_NAME_MAP)
if counts:
counters_port_drop.update(counts)

counters = self.gather_counters([], DEBUG_COUNTER_SWITCH_STAT_MAP)
if counters:
json.dump(self.get_counts(counters, self.get_switch_id()), open(self.switch_drop_stats_file, 'w+'))
counts = self.get_counts(counters, self.get_switch_id())
counters_switch_drop.update(counts)

counters = self.get_configured_counters(DEBUG_COUNTER_SWITCH_STAT_MAP, True)
if counters:
json.dump(self.get_counts(counters, self.get_switch_id()), open(self.switch_std_drop_stats_file, 'w+'))
counts = self.get_counts(counters, self.get_switch_id())
counters_switch_std_drop.update(counts)

try:
if counters_port_drop:
json.dump(counters_port_drop, open(self.port_drop_stats_file, 'w+'))

if counters_switch_drop:
json.dump(counters_switch_drop, open(self.switch_drop_stats_file, 'w+'))

if counters_switch_std_drop:
json.dump(counters_switch_std_drop, open(self.switch_std_drop_stats_file, 'w+'))
except IOError as e:
print(e)
sys.exit(e.errno)
Expand Down
68 changes: 65 additions & 3 deletions tests/multi_asic_dropstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

dropstat_path = "/tmp/dropstat-27"

dropstat_masic_result = """\
dropstat_masic_result_asic0 = """\
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS DEBUG_0 DEBUG_2
------------ ------- -------- ---------- -------- ---------- --------- ---------
Ethernet0 U 10 100 0 0 80 20
Expand All @@ -24,6 +24,38 @@
sonic_drops_test 1000
"""

dropstat_masic_result_asic1 = """\
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS DEBUG_0 DEBUG_2
-------------- ------- -------- ---------- -------- ---------- --------- ---------
Ethernet-BP256 U 10 100 0 0 80 20
Ethernet-BP260 U 0 1000 0 0 800 100
DEVICE DEBUG_1
---------------- ---------
sonic_drops_test 1000
"""

dropstat_masic_result_clear_all = """\
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS DEBUG_0 DEBUG_2
------------ ------- -------- ---------- -------- ---------- --------- ---------
Ethernet0 U 0 0 0 0 0 0
Ethernet4 U 0 0 0 0 0 0
Ethernet-BP0 U 0 0 0 0 0 0
Ethernet-BP4 U 0 0 0 0 0 0
DEVICE DEBUG_1
---------------- ---------
sonic_drops_test 0
IFACE STATE RX_ERR RX_DROPS TX_ERR TX_DROPS DEBUG_0 DEBUG_2
-------------- ------- -------- ---------- -------- ---------- --------- ---------
Ethernet-BP256 U 0 0 0 0 0 0
Ethernet-BP260 U 0 0 0 0 0 0
DEVICE DEBUG_1
---------------- ---------
sonic_drops_test 0
"""


class TestMultiAsicDropstat(object):
@classmethod
Expand All @@ -35,14 +67,36 @@ def setup_class(cls):
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
print("SETUP")

def test_show_pg_drop_masic(self):
def test_show_pg_drop_masic_asic0(self):
return_code, result = get_result_and_return_code([
'dropstat', '-c', 'show', '-n', 'asic0'
])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert result == dropstat_masic_result_asic0 and return_code == 0

def test_show_pg_drop_masic_all_and_clear(self):
return_code, result = get_result_and_return_code([
'dropstat', '-c', 'show'
])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert result == dropstat_masic_result_asic0 + dropstat_masic_result_asic1
assert return_code == 0
assert result == dropstat_masic_result

return_code, result = get_result_and_return_code([
'dropstat', '-c', 'clear'
])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert result == 'Cleared drop counters\n' and return_code == 0

return_code, result = get_result_and_return_code([
'dropstat', '-c', 'show'
])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert result == dropstat_masic_result_clear_all and return_code == 0

def test_show_pg_drop_masic_invalid_ns(self):
return_code, result = get_result_and_return_code([
Expand All @@ -53,6 +107,14 @@ def test_show_pg_drop_masic_invalid_ns(self):
assert return_code == 2
assert "asic5' is not one of" in result

def test_show_pg_drop_version(self):
return_code, result = get_result_and_return_code([
'dropstat', '--version'
])
print("return_code: {}".format(return_code))
print("result = {}".format(result))
assert return_code == 0

@classmethod
def teardown_class(cls):
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
Expand Down

0 comments on commit b963c4e

Please sign in to comment.