Skip to content

Commit

Permalink
[pfcwd] Add single asic unit tests for show commands (sonic-net#1085)
Browse files Browse the repository at this point in the history
Signed-off-by: Neetha John <nejo@microsoft.com>
  • Loading branch information
neethajohn authored Sep 1, 2020
1 parent 60fcab9 commit 8d6d871
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 1 deletion.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
'mock_tables/*.json',
'mock_tables/asic0/*.json',
'mock_tables/asic1/*.json',
'filter_fdb_input/*']
'filter_fdb_input/*',
'pfcwd_input/*']
},
scripts=[
'scripts/aclshow',
Expand Down
18 changes: 18 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1230,5 +1230,23 @@
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
"POLL_INTERVAL": "10000",
"FLEX_COUNTER_STATUS": "enable"
},
"PFC_WD|Ethernet0": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|Ethernet4": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|Ethernet8": {
"action": "drop",
"detection_time": "600",
"restoration_time": "600"
},
"PFC_WD|GLOBAL": {
"POLL_INTERVAL": "600"
}
}
59 changes: 59 additions & 0 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@
"Ethernet4": "oid:0x1000000000004",
"Ethernet8": "oid:0x1000000000006"
},
"COUNTERS_QUEUE_NAME_MAP": {
"Ethernet0:3": "oid:0x1500000000035b",
"Ethernet4:3": "oid:0x15000000000383",
"Ethernet8:4": "oid:0x150000000003ac"
},
"COUNTERS_LAG_NAME_MAP": {
"PortChannel0001": "oid:0x60000000005a1",
"PortChannel0002": "oid:0x60000000005a2",
Expand All @@ -205,5 +210,59 @@
},
"COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": {
"DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"
},
"COUNTERS:oid:0x1500000000035b": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "1",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "0",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "stormed"
},
"COUNTERS:oid:0x15000000000383": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "2",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "operational"
},
"COUNTERS:oid:0x150000000003ac": {
"PFC_WD_ACTION": "drop",
"PFC_WD_DETECTION_TIME": "600000",
"PFC_WD_DETECTION_TIME_LEFT": "600000",
"PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED": "3",
"PFC_WD_QUEUE_STATS_DEADLOCK_RESTORED": "2",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_RX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_RX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_RX_PACKETS_LAST": "0",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS": "300",
"PFC_WD_QUEUE_STATS_TX_DROPPED_PACKETS_LAST": "200",
"PFC_WD_QUEUE_STATS_TX_PACKETS": "100",
"PFC_WD_QUEUE_STATS_TX_PACKETS_LAST": "0",
"PFC_WD_RESTORATION_TIME": "600000",
"PFC_WD_RESTORATION_TIME_LEFT": "600000",
"PFC_WD_STATUS": "stormed"
}
}
Empty file added tests/pfcwd_input/__init__.py
Empty file.
106 changes: 106 additions & 0 deletions tests/pfcwd_input/pfcwd_test_vectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
pfcwd_show_config_output="""\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 drop 600 600
Ethernet4 drop 600 600
Ethernet8 drop 600 600
"""

pfcwd_show_config_single_port_output="""\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 drop 600 600
"""

pfcwd_show_config_multi_port_output="""\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
--------- -------- ---------------- ------------------
Ethernet0 drop 600 600
Ethernet4 drop 600 600
"""

pfcwd_show_config_invalid_port_output="""\
Changed polling interval to 600ms
PORT ACTION DETECTION TIME RESTORATION TIME
------ -------- ---------------- ------------------
"""

pfcwd_show_stats_output="""\
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
----------- ----------- ------------------------- ------------ ------------ ----------------- -----------------
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
Ethernet4:3 operational 2/2 100/100 100/100 0/0 0/0
Ethernet8:4 stormed 3/2 100/300 100/300 0/200 0/200
"""

pfcwd_show_stats_single_queue_output="""\
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
----------- -------- ------------------------- ------------ ------------ ----------------- -----------------
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
"""

pfcwd_show_stats_multi_queue_output="""\
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
----------- ----------- ------------------------- ------------ ------------ ----------------- -----------------
Ethernet0:3 stormed 1/0 100/300 100/300 0/200 0/200
Ethernet4:3 operational 2/2 100/100 100/100 0/0 0/0
"""

pfcwd_show_stats_invalid_queue_output="""\
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
------- -------- ------------------------- ------------ ------------ ----------------- -----------------
"""

testData = {
'pfcwd_show_config' : [ {'cmd' : ['show', 'config'],
'args': [],
'rc': 0,
'rc_output': pfcwd_show_config_output
}
],
'pfcwd_show_config_single_port' : [ {'cmd' : ['show', 'config'],
'args': ['Ethernet0'],
'rc': 0,
'rc_output': pfcwd_show_config_single_port_output
}
],
'pfcwd_show_config_multi_port' : [ {'cmd' : ['show', 'config'],
'args': ['Ethernet0', 'Ethernet4'],
'rc': 0,
'rc_output': pfcwd_show_config_multi_port_output
}
],
'pfcwd_show_config_invalid_port' : [ {'cmd' : ['show', 'config'],
'args': ['Ethernet400'],
'rc': 0,
'rc_output': pfcwd_show_config_invalid_port_output
}
],
'pfcwd_show_stats' : [ {'cmd' : ['show', 'stats'],
'args': [],
'rc': 0,
'rc_output': pfcwd_show_stats_output
}
],
'pfcwd_show_stats_single_queue' : [ {'cmd' : ['show', 'stats'],
'args': ['Ethernet0:3'],
'rc': 0,
'rc_output': pfcwd_show_stats_single_queue_output
}
],
'pfcwd_show_stats_multi_queue' : [ {'cmd' : ['show', 'stats'],
'args': ['Ethernet0:3', 'Ethernet4:3'],
'rc': 0,
'rc_output': pfcwd_show_stats_multi_queue_output
}
],
'pfcwd_show_stats_invalid_queue' : [ {'cmd' : ['show', 'stats'],
'args': ['Ethernet0:100'],
'rc': 0,
'rc_output': pfcwd_show_stats_invalid_queue_output
}
]
}
82 changes: 82 additions & 0 deletions tests/pfcwd_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import sys

from click.testing import CliRunner
from utilities_common.db import Db

from pfcwd_input.pfcwd_test_vectors import testData

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
scripts_path = os.path.join(modules_path, "pfcwd")
sys.path.insert(0, test_path)
sys.path.insert(0, modules_path)

import pfcwd.main as pfcwd

class TestPfcwd(object):
@classmethod
def setup_class(cls):
os.environ["PATH"] += os.pathsep + scripts_path
os.environ['UTILITIES_UNIT_TESTING'] = "2"
print("SETUP")

def test_pfcwd_show_config(self):
self.executor(testData['pfcwd_show_config'])

def test_pfcwd_show_config_single_port(self):
self.executor(testData['pfcwd_show_config_single_port'])

def test_pfcwd_show_config_multi_port(self):
self.executor(testData['pfcwd_show_config_multi_port'])

def test_pfcwd_show_config_invalid_port(self):
self.executor(testData['pfcwd_show_config_invalid_port'])

def test_pfcwd_show_stats(self):
self.executor(testData['pfcwd_show_stats'])

def test_pfcwd_show_stats_single_queue(self):
self.executor(testData['pfcwd_show_stats_single_queue'])

def test_pfcwd_show_stats_multi_queue(self):
self.executor(testData['pfcwd_show_stats_multi_queue'])

def test_pfcwd_show_stats_invalid_queue(self):
self.executor(testData['pfcwd_show_stats_invalid_queue'])

def executor(self, testcase):
runner = CliRunner()
db = Db()

for input in testcase:
exec_cmd = ""
if len(input['cmd']) == 1:
exec_cmd = pfcwd.cli.commands[input['cmd'][0]]
else:
exec_cmd = pfcwd.cli.commands[input['cmd'][0]].commands[input['cmd'][1]]

if 'db' in input and input['db']:
result = runner.invoke(exec_cmd, input['args'], obj=db)
else:
result = runner.invoke(exec_cmd, input['args'])

print(result.exit_code)
print(result.output)

if input['rc'] == 0:
assert result.exit_code == 0
else:
assert result.exit_code != 0

if 'rc_msg' in input:
assert input['rc_msg'] in result.output

if 'rc_output' in input:
assert result.output == input['rc_output']

@classmethod
def teardown_class(cls):
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ['UTILITIES_UNIT_TESTING'] = "0"
print("TEARDOWN")

0 comments on commit 8d6d871

Please sign in to comment.