Skip to content

Commit

Permalink
clear: Fix clear queuecounters to also clear VOQ counters (#2879)
Browse files Browse the repository at this point in the history
The `sonic-clear queuecounters` command does not currently clear VOQ
counters. Fix it and add a unit test to verify that the VOQ counters
were actually cleared.

The unit test changes required some updates to the VOQ counters tests,
because on an actual DUT the VOQ counter uses fully-qualified
interface names (dut|asic|port) whereas the queue counters just use
the port name. The unit tests had kept the names the same but this
meant that the saved counters for VOQ and non-VOQ counters would
overwrite each other when the counters were cleared during the unit
tests. Qualify the interface names used in the VOQ unit tests to avoid
this.
  • Loading branch information
patrickmacarthur authored Aug 17, 2023
1 parent 0f001c5 commit 56a1ae2
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 73 deletions.
3 changes: 3 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def queuecounters():
command = "queuestat -c"
run_command(command)

command = "queuestat -c --voq"
run_command(command)

@cli.command()
def pfccounters():
"""Clear pfc counters"""
Expand Down
54 changes: 27 additions & 27 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1059,36 +1059,36 @@
},

"COUNTERS_SYSTEM_PORT_NAME_MAP": {
"Ethernet0": "oid:0x1000000000042",
"Ethernet4": "oid:0x1000000000043",
"Ethernet8": "oid:0x1000000000044"
"testsw|Ethernet0": "oid:0x1000000000042",
"testsw|Ethernet4": "oid:0x1000000000043",
"testsw|Ethernet8": "oid:0x1000000000044"
},

"COUNTERS_VOQ_NAME_MAP": {
"Ethernet0:0": "oid:0x15000000000657",
"Ethernet0:1": "oid:0x15000000000658",
"Ethernet0:2": "oid:0x15000000000659",
"Ethernet0:3": "oid:0x1500000000065a",
"Ethernet0:4": "oid:0x1500000000065b",
"Ethernet0:5": "oid:0x1500000000065c",
"Ethernet0:6": "oid:0x1500000000065d",
"Ethernet0:7": "oid:0x1500000000065e",
"Ethernet4:0": "oid:0x15000000000667",
"Ethernet4:1": "oid:0x15000000000668",
"Ethernet4:2": "oid:0x15000000000669",
"Ethernet4:3": "oid:0x1500000000066a",
"Ethernet4:4": "oid:0x1500000000066b",
"Ethernet4:5": "oid:0x1500000000066c",
"Ethernet4:6": "oid:0x1500000000066d",
"Ethernet4:7": "oid:0x1500000000066e",
"Ethernet8:0": "oid:0x15000000000677",
"Ethernet8:1": "oid:0x15000000000678",
"Ethernet8:2": "oid:0x15000000000679",
"Ethernet8:3": "oid:0x1500000000067a",
"Ethernet8:4": "oid:0x1500000000067b",
"Ethernet8:5": "oid:0x1500000000067c",
"Ethernet8:6": "oid:0x1500000000067d",
"Ethernet8:7": "oid:0x1500000000067e"
"testsw|Ethernet0:0": "oid:0x15000000000657",
"testsw|Ethernet0:1": "oid:0x15000000000658",
"testsw|Ethernet0:2": "oid:0x15000000000659",
"testsw|Ethernet0:3": "oid:0x1500000000065a",
"testsw|Ethernet0:4": "oid:0x1500000000065b",
"testsw|Ethernet0:5": "oid:0x1500000000065c",
"testsw|Ethernet0:6": "oid:0x1500000000065d",
"testsw|Ethernet0:7": "oid:0x1500000000065e",
"testsw|Ethernet4:0": "oid:0x15000000000667",
"testsw|Ethernet4:1": "oid:0x15000000000668",
"testsw|Ethernet4:2": "oid:0x15000000000669",
"testsw|Ethernet4:3": "oid:0x1500000000066a",
"testsw|Ethernet4:4": "oid:0x1500000000066b",
"testsw|Ethernet4:5": "oid:0x1500000000066c",
"testsw|Ethernet4:6": "oid:0x1500000000066d",
"testsw|Ethernet4:7": "oid:0x1500000000066e",
"testsw|Ethernet8:0": "oid:0x15000000000677",
"testsw|Ethernet8:1": "oid:0x15000000000678",
"testsw|Ethernet8:2": "oid:0x15000000000679",
"testsw|Ethernet8:3": "oid:0x1500000000067a",
"testsw|Ethernet8:4": "oid:0x1500000000067b",
"testsw|Ethernet8:5": "oid:0x1500000000067c",
"testsw|Ethernet8:6": "oid:0x1500000000067d",
"testsw|Ethernet8:7": "oid:0x1500000000067e"
},

"COUNTERS_PORT_NAME_MAP": {
Expand Down
147 changes: 101 additions & 46 deletions tests/queue_counter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .mock_tables import dbconnector

import show.main as show
import clear.main as clear
from utilities_common.cli import json_dump
from utilities_common.db import Db

Expand Down Expand Up @@ -896,58 +897,94 @@
}"""

show_queue_voq_counters = """\
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
--------- ----- -------------- --------------- ----------- ------------
Ethernet0 VOQ0 68 30 56 74
Ethernet0 VOQ1 60 43 39 1
Ethernet0 VOQ2 82 7 39 21
Ethernet0 VOQ3 11 59 12 94
Ethernet0 VOQ4 36 62 35 40
Ethernet0 VOQ5 49 91 2 88
Ethernet0 VOQ6 33 17 94 74
Ethernet0 VOQ7 40 71 95 33
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet0 VOQ0 68 30 56 74
testsw|Ethernet0 VOQ1 60 43 39 1
testsw|Ethernet0 VOQ2 82 7 39 21
testsw|Ethernet0 VOQ3 11 59 12 94
testsw|Ethernet0 VOQ4 36 62 35 40
testsw|Ethernet0 VOQ5 49 91 2 88
testsw|Ethernet0 VOQ6 33 17 94 74
testsw|Ethernet0 VOQ7 40 71 95 33
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
--------- ----- -------------- --------------- ----------- ------------
Ethernet4 VOQ0 54 8 93 78
Ethernet4 VOQ1 83 96 74 9
Ethernet4 VOQ2 15 60 61 31
Ethernet4 VOQ3 45 52 82 94
Ethernet4 VOQ4 55 88 89 52
Ethernet4 VOQ5 14 70 95 79
Ethernet4 VOQ6 68 60 66 81
Ethernet4 VOQ7 63 4 48 76
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet4 VOQ0 54 8 93 78
testsw|Ethernet4 VOQ1 83 96 74 9
testsw|Ethernet4 VOQ2 15 60 61 31
testsw|Ethernet4 VOQ3 45 52 82 94
testsw|Ethernet4 VOQ4 55 88 89 52
testsw|Ethernet4 VOQ5 14 70 95 79
testsw|Ethernet4 VOQ6 68 60 66 81
testsw|Ethernet4 VOQ7 63 4 48 76
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
--------- ----- -------------- --------------- ----------- ------------
Ethernet8 VOQ0 41 73 77 74
Ethernet8 VOQ1 60 21 56 54
Ethernet8 VOQ2 57 31 12 39
Ethernet8 VOQ3 41 96 70 98
Ethernet8 VOQ4 18 49 63 36
Ethernet8 VOQ5 99 90 3 15
Ethernet8 VOQ6 8 84 82 94
Ethernet8 VOQ7 83 15 75 92
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet8 VOQ0 41 73 77 74
testsw|Ethernet8 VOQ1 60 21 56 54
testsw|Ethernet8 VOQ2 57 31 12 39
testsw|Ethernet8 VOQ3 41 96 70 98
testsw|Ethernet8 VOQ4 18 49 63 36
testsw|Ethernet8 VOQ5 99 90 3 15
testsw|Ethernet8 VOQ6 8 84 82 94
testsw|Ethernet8 VOQ7 83 15 75 92
"""

show_queue_voq_counters_with_clear = ["""\
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet0 VOQ0 0 0 0 0
testsw|Ethernet0 VOQ1 0 0 0 0
testsw|Ethernet0 VOQ2 0 0 0 0
testsw|Ethernet0 VOQ3 0 0 0 0
testsw|Ethernet0 VOQ4 0 0 0 0
testsw|Ethernet0 VOQ5 0 0 0 0
testsw|Ethernet0 VOQ6 0 0 0 0
testsw|Ethernet0 VOQ7 0 0 0 0
""", """\
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet4 VOQ0 0 0 0 0
testsw|Ethernet4 VOQ1 0 0 0 0
testsw|Ethernet4 VOQ2 0 0 0 0
testsw|Ethernet4 VOQ3 0 0 0 0
testsw|Ethernet4 VOQ4 0 0 0 0
testsw|Ethernet4 VOQ5 0 0 0 0
testsw|Ethernet4 VOQ6 0 0 0 0
testsw|Ethernet4 VOQ7 0 0 0 0
""", """\
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet8 VOQ0 0 0 0 0
testsw|Ethernet8 VOQ1 0 0 0 0
testsw|Ethernet8 VOQ2 0 0 0 0
testsw|Ethernet8 VOQ3 0 0 0 0
testsw|Ethernet8 VOQ4 0 0 0 0
testsw|Ethernet8 VOQ5 0 0 0 0
testsw|Ethernet8 VOQ6 0 0 0 0
testsw|Ethernet8 VOQ7 0 0 0 0
"""
]

show_queue_port_voq_counters = """\
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
--------- ----- -------------- --------------- ----------- ------------
Ethernet0 VOQ0 68 30 56 74
Ethernet0 VOQ1 60 43 39 1
Ethernet0 VOQ2 82 7 39 21
Ethernet0 VOQ3 11 59 12 94
Ethernet0 VOQ4 36 62 35 40
Ethernet0 VOQ5 49 91 2 88
Ethernet0 VOQ6 33 17 94 74
Ethernet0 VOQ7 40 71 95 33
Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes
---------------- ----- -------------- --------------- ----------- ------------
testsw|Ethernet0 VOQ0 68 30 56 74
testsw|Ethernet0 VOQ1 60 43 39 1
testsw|Ethernet0 VOQ2 82 7 39 21
testsw|Ethernet0 VOQ3 11 59 12 94
testsw|Ethernet0 VOQ4 36 62 35 40
testsw|Ethernet0 VOQ5 49 91 2 88
testsw|Ethernet0 VOQ6 33 17 94 74
testsw|Ethernet0 VOQ7 40 71 95 33
"""

show_queue_voq_counters_json = """\
{
"Ethernet0": {
"testsw|Ethernet0": {
"VOQ0": {
"dropbytes": "74",
"droppacket": "56",
Expand Down Expand Up @@ -997,7 +1034,7 @@
"totalpacket": "40"
}
},
"Ethernet4": {
"testsw|Ethernet4": {
"VOQ0": {
"dropbytes": "78",
"droppacket": "93",
Expand Down Expand Up @@ -1047,7 +1084,7 @@
"totalpacket": "63"
}
},
"Ethernet8": {
"testsw|Ethernet8": {
"VOQ0": {
"dropbytes": "74",
"droppacket": "77",
Expand Down Expand Up @@ -1101,7 +1138,7 @@

show_queue_port_voq_counters_json = """\
{
"Ethernet0": {
"testsw|Ethernet0": {
"VOQ0": {
"dropbytes": "74",
"droppacket": "56",
Expand Down Expand Up @@ -1220,11 +1257,29 @@ def test_queue_voq_counters(self):
assert result.exit_code == 0
assert result.output == show_queue_voq_counters

def test_queue_voq_counters_with_clear(self):
runner = CliRunner()
result = runner.invoke(clear.cli.commands['queuecounters'], [])
assert result.exit_code == 0
result = runner.invoke(
show.cli.commands["queue"].commands["counters"],
["--voq"]
)
print(result.output)
show.run_command(['queuestat -d --voq'])
assert result.exit_code == 0
assert "Ethernet0 Last cached time was" in result.output and \
"Ethernet4 Last cached time was" in result.output and \
"Ethernet8 Last cached time was" in result.output
assert show_queue_voq_counters_with_clear[0] in result.output and \
show_queue_voq_counters_with_clear[1] in result.output and \
show_queue_voq_counters_with_clear[2] in result.output

def test_queue_port_voq_counters(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["queue"].commands["counters"],
["Ethernet0 --voq"]
["testsw\\|Ethernet0 --voq"]
)
print(result.output)
assert result.exit_code == 0
Expand All @@ -1251,7 +1306,7 @@ def test_queue_voq_counters_port_json(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["queue"].commands["counters"],
["Ethernet0", "--voq", "--json"]
["testsw\\|Ethernet0", "--voq", "--json"]
)
assert result.exit_code == 0
print(result.output)
Expand Down

0 comments on commit 56a1ae2

Please sign in to comment.