Skip to content

Commit 8d6d871

Browse files
authored
[pfcwd] Add single asic unit tests for show commands (sonic-net#1085)
Signed-off-by: Neetha John <nejo@microsoft.com>
1 parent 60fcab9 commit 8d6d871

File tree

6 files changed

+267
-1
lines changed

6 files changed

+267
-1
lines changed

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
'mock_tables/*.json',
6565
'mock_tables/asic0/*.json',
6666
'mock_tables/asic1/*.json',
67-
'filter_fdb_input/*']
67+
'filter_fdb_input/*',
68+
'pfcwd_input/*']
6869
},
6970
scripts=[
7071
'scripts/aclshow',

tests/mock_tables/config_db.json

+18
Original file line numberDiff line numberDiff line change
@@ -1230,5 +1230,23 @@
12301230
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
12311231
"POLL_INTERVAL": "10000",
12321232
"FLEX_COUNTER_STATUS": "enable"
1233+
},
1234+
"PFC_WD|Ethernet0": {
1235+
"action": "drop",
1236+
"detection_time": "600",
1237+
"restoration_time": "600"
1238+
},
1239+
"PFC_WD|Ethernet4": {
1240+
"action": "drop",
1241+
"detection_time": "600",
1242+
"restoration_time": "600"
1243+
},
1244+
"PFC_WD|Ethernet8": {
1245+
"action": "drop",
1246+
"detection_time": "600",
1247+
"restoration_time": "600"
1248+
},
1249+
"PFC_WD|GLOBAL": {
1250+
"POLL_INTERVAL": "600"
12331251
}
12341252
}

tests/mock_tables/counters_db.json

+59
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@
193193
"Ethernet4": "oid:0x1000000000004",
194194
"Ethernet8": "oid:0x1000000000006"
195195
},
196+
"COUNTERS_QUEUE_NAME_MAP": {
197+
"Ethernet0:3": "oid:0x1500000000035b",
198+
"Ethernet4:3": "oid:0x15000000000383",
199+
"Ethernet8:4": "oid:0x150000000003ac"
200+
},
196201
"COUNTERS_LAG_NAME_MAP": {
197202
"PortChannel0001": "oid:0x60000000005a1",
198203
"PortChannel0002": "oid:0x60000000005a2",
@@ -205,5 +210,59 @@
205210
},
206211
"COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": {
207212
"DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"
213+
},
214+
"COUNTERS:oid:0x1500000000035b": {
215+
"PFC_WD_ACTION": "drop",
216+
"PFC_WD_DETECTION_TIME": "600000",
217+
"PFC_WD_DETECTION_TIME_LEFT": "600000",
218+
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "1",
219+
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "0",
220+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
221+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
222+
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
223+
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
224+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
225+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
226+
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
227+
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
228+
"PFC_WD_RESTORATION_TIME": "600000",
229+
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
230+
"PFC_WD_STATUS": "stormed"
231+
},
232+
"COUNTERS:oid:0x15000000000383": {
233+
"PFC_WD_ACTION": "drop",
234+
"PFC_WD_DETECTION_TIME": "600000",
235+
"PFC_WD_DETECTION_TIME_LEFT": "600000",
236+
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "2",
237+
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
238+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "100",
239+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "0",
240+
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
241+
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
242+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "100",
243+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "0",
244+
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
245+
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
246+
"PFC_WD_RESTORATION_TIME": "600000",
247+
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
248+
"PFC_WD_STATUS": "operational"
249+
},
250+
"COUNTERS:oid:0x150000000003ac": {
251+
"PFC_WD_ACTION": "drop",
252+
"PFC_WD_DETECTION_TIME": "600000",
253+
"PFC_WD_DETECTION_TIME_LEFT": "600000",
254+
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "3",
255+
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
256+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
257+
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
258+
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
259+
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
260+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
261+
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
262+
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
263+
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
264+
"PFC_WD_RESTORATION_TIME": "600000",
265+
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
266+
"PFC_WD_STATUS": "stormed"
208267
}
209268
}

tests/pfcwd_input/__init__.py

Whitespace-only changes.
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
pfcwd_show_config_output="""\
2+
Changed polling interval to 600ms
3+
PORT ACTION DETECTION TIME RESTORATION TIME
4+
--------- -------- ---------------- ------------------
5+
Ethernet0 drop 600 600
6+
Ethernet4 drop 600 600
7+
Ethernet8 drop 600 600
8+
"""
9+
10+
pfcwd_show_config_single_port_output="""\
11+
Changed polling interval to 600ms
12+
PORT ACTION DETECTION TIME RESTORATION TIME
13+
--------- -------- ---------------- ------------------
14+
Ethernet0 drop 600 600
15+
"""
16+
17+
pfcwd_show_config_multi_port_output="""\
18+
Changed polling interval to 600ms
19+
PORT ACTION DETECTION TIME RESTORATION TIME
20+
--------- -------- ---------------- ------------------
21+
Ethernet0 drop 600 600
22+
Ethernet4 drop 600 600
23+
"""
24+
25+
pfcwd_show_config_invalid_port_output="""\
26+
Changed polling interval to 600ms
27+
PORT ACTION DETECTION TIME RESTORATION TIME
28+
------ -------- ---------------- ------------------
29+
"""
30+
31+
pfcwd_show_stats_output="""\
32+
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
33+
----------- ----------- ------------------------- ------------ ------------ ----------------- -----------------
34+
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
35+
Ethernet4:3 operational 2/2 100/100 100/100 0/0 0/0
36+
Ethernet8:4 stormed 3/2 100/300 100/300 0/200 0/200
37+
"""
38+
39+
pfcwd_show_stats_single_queue_output="""\
40+
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
41+
----------- -------- ------------------------- ------------ ------------ ----------------- -----------------
42+
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
43+
"""
44+
45+
pfcwd_show_stats_multi_queue_output="""\
46+
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
47+
----------- ----------- ------------------------- ------------ ------------ ----------------- -----------------
48+
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
49+
Ethernet4:3 operational 2/2 100/100 100/100 0/0 0/0
50+
"""
51+
52+
pfcwd_show_stats_invalid_queue_output="""\
53+
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
54+
------- -------- ------------------------- ------------ ------------ ----------------- -----------------
55+
"""
56+
57+
testData = {
58+
'pfcwd_show_config' : [ {'cmd' : ['show', 'config'],
59+
'args': [],
60+
'rc': 0,
61+
'rc_output': pfcwd_show_config_output
62+
}
63+
],
64+
'pfcwd_show_config_single_port' : [ {'cmd' : ['show', 'config'],
65+
'args': ['Ethernet0'],
66+
'rc': 0,
67+
'rc_output': pfcwd_show_config_single_port_output
68+
}
69+
],
70+
'pfcwd_show_config_multi_port' : [ {'cmd' : ['show', 'config'],
71+
'args': ['Ethernet0', 'Ethernet4'],
72+
'rc': 0,
73+
'rc_output': pfcwd_show_config_multi_port_output
74+
}
75+
],
76+
'pfcwd_show_config_invalid_port' : [ {'cmd' : ['show', 'config'],
77+
'args': ['Ethernet400'],
78+
'rc': 0,
79+
'rc_output': pfcwd_show_config_invalid_port_output
80+
}
81+
],
82+
'pfcwd_show_stats' : [ {'cmd' : ['show', 'stats'],
83+
'args': [],
84+
'rc': 0,
85+
'rc_output': pfcwd_show_stats_output
86+
}
87+
],
88+
'pfcwd_show_stats_single_queue' : [ {'cmd' : ['show', 'stats'],
89+
'args': ['Ethernet0:3'],
90+
'rc': 0,
91+
'rc_output': pfcwd_show_stats_single_queue_output
92+
}
93+
],
94+
'pfcwd_show_stats_multi_queue' : [ {'cmd' : ['show', 'stats'],
95+
'args': ['Ethernet0:3', 'Ethernet4:3'],
96+
'rc': 0,
97+
'rc_output': pfcwd_show_stats_multi_queue_output
98+
}
99+
],
100+
'pfcwd_show_stats_invalid_queue' : [ {'cmd' : ['show', 'stats'],
101+
'args': ['Ethernet0:100'],
102+
'rc': 0,
103+
'rc_output': pfcwd_show_stats_invalid_queue_output
104+
}
105+
]
106+
}

tests/pfcwd_test.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import sys
3+
4+
from click.testing import CliRunner
5+
from utilities_common.db import Db
6+
7+
from pfcwd_input.pfcwd_test_vectors import testData
8+
9+
test_path = os.path.dirname(os.path.abspath(__file__))
10+
modules_path = os.path.dirname(test_path)
11+
scripts_path = os.path.join(modules_path, "pfcwd")
12+
sys.path.insert(0, test_path)
13+
sys.path.insert(0, modules_path)
14+
15+
import pfcwd.main as pfcwd
16+
17+
class TestPfcwd(object):
18+
@classmethod
19+
def setup_class(cls):
20+
os.environ["PATH"] += os.pathsep + scripts_path
21+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
22+
print("SETUP")
23+
24+
def test_pfcwd_show_config(self):
25+
self.executor(testData['pfcwd_show_config'])
26+
27+
def test_pfcwd_show_config_single_port(self):
28+
self.executor(testData['pfcwd_show_config_single_port'])
29+
30+
def test_pfcwd_show_config_multi_port(self):
31+
self.executor(testData['pfcwd_show_config_multi_port'])
32+
33+
def test_pfcwd_show_config_invalid_port(self):
34+
self.executor(testData['pfcwd_show_config_invalid_port'])
35+
36+
def test_pfcwd_show_stats(self):
37+
self.executor(testData['pfcwd_show_stats'])
38+
39+
def test_pfcwd_show_stats_single_queue(self):
40+
self.executor(testData['pfcwd_show_stats_single_queue'])
41+
42+
def test_pfcwd_show_stats_multi_queue(self):
43+
self.executor(testData['pfcwd_show_stats_multi_queue'])
44+
45+
def test_pfcwd_show_stats_invalid_queue(self):
46+
self.executor(testData['pfcwd_show_stats_invalid_queue'])
47+
48+
def executor(self, testcase):
49+
runner = CliRunner()
50+
db = Db()
51+
52+
for input in testcase:
53+
exec_cmd = ""
54+
if len(input['cmd']) == 1:
55+
exec_cmd = pfcwd.cli.commands[input['cmd'][0]]
56+
else:
57+
exec_cmd = pfcwd.cli.commands[input['cmd'][0]].commands[input['cmd'][1]]
58+
59+
if 'db' in input and input['db']:
60+
result = runner.invoke(exec_cmd, input['args'], obj=db)
61+
else:
62+
result = runner.invoke(exec_cmd, input['args'])
63+
64+
print(result.exit_code)
65+
print(result.output)
66+
67+
if input['rc'] == 0:
68+
assert result.exit_code == 0
69+
else:
70+
assert result.exit_code != 0
71+
72+
if 'rc_msg' in input:
73+
assert input['rc_msg'] in result.output
74+
75+
if 'rc_output' in input:
76+
assert result.output == input['rc_output']
77+
78+
@classmethod
79+
def teardown_class(cls):
80+
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
81+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
82+
print("TEARDOWN")

0 commit comments

Comments
 (0)