forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pfcwd] Add single asic unit tests for show commands (sonic-net#1085)
Signed-off-by: Neetha John <nejo@microsoft.com>
- Loading branch information
1 parent
60fcab9
commit 8d6d871
Showing
6 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |