Skip to content

Commit 008a078

Browse files
authored
Add Unit Test for portstat (#3564)
added a unit test for scenarios where a LC's counter DB is N/A.
1 parent 66b41e5 commit 008a078

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"CHASSIS_MODULE_HOSTNAME_TABLE|LINE-CARD0": {
3+
"module_hostname": "sonic-lc1"
4+
},
5+
"CHASSIS_MODULE_HOSTNAME_TABLE|LINE-CARD1": {
6+
"module_hostname": "sonic-lc2"
7+
},
8+
"CHASSIS_MODULE_HOSTNAME_TABLE|LINE-CARD2": {
9+
"module_hostname": "sonic-lc3"
10+
},
11+
"LINECARD_PORT_STAT_MARK_TABLE|sonic-lc1": {
12+
"timestamp": "2020-07-01 00:00:00"
13+
},
14+
"LINECARD_PORT_STAT_MARK_TABLE|sonic-lc3": {
15+
"timestamp": "2020-07-01 00:00:00"
16+
},
17+
"LINECARD_PORT_STAT_TABLE|Ethernet1/1": {
18+
"state": "U",
19+
"rx_ok": 100,
20+
"rx_bps": 10,
21+
"rx_pps": 1,
22+
"rx_util": 0,
23+
"rx_err": 0,
24+
"rx_drop": 0,
25+
"rx_ovr": 0,
26+
"tx_ok": 100,
27+
"tx_bps": 10,
28+
"tx_pps": 1,
29+
"tx_util": 0,
30+
"tx_err": 0,
31+
"tx_drop": 0,
32+
"tx_ovr": 0
33+
},
34+
"LINECARD_PORT_STAT_TABLE|Ethernet2/1": {
35+
"state": "U",
36+
"rx_ok": 100,
37+
"rx_bps": 10,
38+
"rx_pps": 1,
39+
"rx_util": 0,
40+
"rx_err": 0,
41+
"rx_drop": 0,
42+
"rx_ovr": 0,
43+
"tx_ok": 100,
44+
"tx_bps": 10,
45+
"tx_pps": 1,
46+
"tx_util": 0,
47+
"tx_err": 0,
48+
"tx_drop": 0,
49+
"tx_ovr": 0
50+
},
51+
"LINECARD_PORT_STAT_TABLE|Ethernet11/1": {
52+
"state": "N/A",
53+
"rx_ok": "N/A",
54+
"rx_bps": "N/A",
55+
"rx_pps": "N/A",
56+
"rx_util": "N/A",
57+
"rx_err": "N/A",
58+
"rx_drop": "N/A",
59+
"rx_ovr": "N/A",
60+
"tx_ok": "N/A",
61+
"tx_bps": "N/A",
62+
"tx_pps": "N/A",
63+
"tx_util": "N/A",
64+
"tx_err": "N/A",
65+
"tx_drop": "N/A",
66+
"tx_ovr": "N/A"
67+
}
68+
}

tests/portstat_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@
272272

273273
intf_counters_on_sup_partial_lc = "Not all linecards have published their counter values.\n"
274274

275+
intf_counters_on_sup_na = """\
276+
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL\
277+
TX_ERR TX_DRP TX_OVR
278+
------------ ------- ------- --------- --------- -------- -------- -------- ------- --------- ---------\
279+
-------- -------- --------
280+
Ethernet1/1 U 100 10.00 B/s 0.00% 0 0 0 100 10.00 B/s 0.00%\
281+
0 0 0
282+
Ethernet2/1 U 100 10.00 B/s 0.00% 0 0 0 100 10.00 B/s 0.00%\
283+
0 0 0
284+
Ethernet11/1 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A\
285+
N/A N/A N/A
286+
"""
287+
275288
TEST_PERIOD = 3
276289

277290

@@ -512,6 +525,31 @@ def test_show_intf_counters_on_sup_partial_lc(self):
512525
os.system("cp /tmp/chassis_state_db.json {}"
513526
.format(os.path.join(test_path, "mock_tables/chassis_state_db.json")))
514527

528+
def test_show_intf_counters_on_sup_na(self):
529+
remove_tmp_cnstat_file()
530+
os.system("cp {} /tmp/".format(os.path.join(test_path, "mock_tables/chassis_state_db.json")))
531+
os.system("cp {} {}".format(os.path.join(test_path, "portstat_db/on_sup_na/chassis_state_db.json"),
532+
os.path.join(test_path, "mock_tables/chassis_state_db.json")))
533+
os.environ["UTILITIES_UNIT_TESTING_IS_SUP"] = "1"
534+
535+
runner = CliRunner()
536+
result = runner.invoke(
537+
show.cli.commands["interfaces"].commands["counters"], [])
538+
print(result.exit_code)
539+
print(result.output)
540+
assert result.exit_code == 0
541+
assert result.output == intf_counters_on_sup_na
542+
543+
return_code, result = get_result_and_return_code(['portstat'])
544+
print("return_code: {}".format(return_code))
545+
print("result = {}".format(result))
546+
assert return_code == 0
547+
assert result == intf_counters_on_sup_na
548+
549+
os.environ["UTILITIES_UNIT_TESTING_IS_SUP"] = "0"
550+
os.system("cp /tmp/chassis_state_db.json {}"
551+
.format(os.path.join(test_path, "mock_tables/chassis_state_db.json")))
552+
515553
@classmethod
516554
def teardown_class(cls):
517555
print("TEARDOWN")

0 commit comments

Comments
 (0)