From 56a1ae24dc8f4e2dd2ad8929506ecdc836d3dd7c Mon Sep 17 00:00:00 2001 From: Patrick MacArthur Date: Thu, 17 Aug 2023 12:59:12 -0400 Subject: [PATCH] clear: Fix clear queuecounters to also clear VOQ counters (#2879) 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. --- clear/main.py | 3 + tests/mock_tables/counters_db.json | 54 +++++------ tests/queue_counter_test.py | 147 ++++++++++++++++++++--------- 3 files changed, 131 insertions(+), 73 deletions(-) diff --git a/clear/main.py b/clear/main.py index 6980bb8be..ef3d2cc1a 100755 --- a/clear/main.py +++ b/clear/main.py @@ -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""" diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index f2caba244..c0c37880d 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -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": { diff --git a/tests/queue_counter_test.py b/tests/queue_counter_test.py index b7b363712..404014cbb 100644 --- a/tests/queue_counter_test.py +++ b/tests/queue_counter_test.py @@ -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 @@ -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", @@ -997,7 +1034,7 @@ "totalpacket": "40" } }, - "Ethernet4": { + "testsw|Ethernet4": { "VOQ0": { "dropbytes": "78", "droppacket": "93", @@ -1047,7 +1084,7 @@ "totalpacket": "63" } }, - "Ethernet8": { + "testsw|Ethernet8": { "VOQ0": { "dropbytes": "74", "droppacket": "77", @@ -1101,7 +1138,7 @@ show_queue_port_voq_counters_json = """\ { - "Ethernet0": { + "testsw|Ethernet0": { "VOQ0": { "dropbytes": "74", "droppacket": "56", @@ -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 @@ -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)