Skip to content

Commit 569edf3

Browse files
Fix display disorder problem of show mirror_session (sonic-net#2447)
* Fix display disorder problem of mirror_session
1 parent daaf0ff commit 569edf3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

acl_loader/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,10 @@ def show_session(self, session_name):
842842
val.get("monitor_port", ""), val.get("src_port", ""), val.get("direction", "").lower()])
843843

844844
print("ERSPAN Sessions")
845+
erspan_data = natsorted(erspan_data)
845846
print(tabulate.tabulate(erspan_data, headers=erspan_header, tablefmt="simple", missingval=""))
846847
print("\nSPAN Sessions")
848+
span_data = natsorted(span_data)
847849
print(tabulate.tabulate(span_data, headers=span_header, tablefmt="simple", missingval=""))
848850

849851
def show_policer(self, policer_name):

tests/show_mirror_test.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
from swsscommon.swsscommon import SonicV2Connector
4+
from click.testing import CliRunner
5+
from utilities_common.db import Db
6+
7+
import acl_loader.main as acl_loader_show
8+
from acl_loader import *
9+
from acl_loader.main import *
10+
11+
class TestShowMirror(object):
12+
def test_mirror_show(self):
13+
runner = CliRunner()
14+
aclloader = AclLoader()
15+
aclloader.configdb.set_entry("MIRROR_SESSION", "session1", {"direction": "BOTH", "dst_port": "Ethernet30", "src_port": "Ethernet40", "type": "SPAN"})
16+
aclloader.configdb.set_entry("MIRROR_SESSION", "session2", {"direction": "BOTH", "dst_port": "Ethernet7", "src_port": "Ethernet8", "type": "SPAN"})
17+
aclloader.configdb.set_entry("MIRROR_SESSION", "session11", {"direction": "RX", "dst_port": "Ethernet9", "src_port": "Ethernet10", "type": "SPAN"})
18+
aclloader.configdb.set_entry("MIRROR_SESSION", "session15", {"direction": "TX", "dst_port": "Ethernet2", "src_port": "Ethernet3", "type": "SPAN"})
19+
aclloader.read_sessions_info()
20+
context = {
21+
"acl_loader": aclloader
22+
}
23+
expected_output = """\
24+
ERSPAN Sessions
25+
Name Status SRC IP DST IP GRE DSCP TTL Queue Policer Monitor Port SRC Port Direction
26+
---------------- -------- -------- -------- ----- ------ ----- ------- --------- -------------- --------------------- -----------
27+
test_session_db1 active Ethernet40,Ethernet48 rx
28+
29+
SPAN Sessions
30+
Name Status DST Port SRC Port Direction Queue Policer
31+
--------- -------- ---------- ---------- ----------- ------- ---------
32+
session1 active Ethernet30 Ethernet40 both
33+
session2 active Ethernet7 Ethernet8 both
34+
session11 active Ethernet9 Ethernet10 rx
35+
session15 active Ethernet2 Ethernet3 tx
36+
"""
37+
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['session'], [], obj=context)
38+
assert result.exit_code == 0
39+
print (result.output)
40+
#The state of mirror_session depends on the state_db table entry. This case does not care about the state and is uniformly set to active.
41+
result_output = result.output.replace('error', 'active')
42+
result_output = result_output.replace('inactive', 'active')
43+
assert result_output == expected_output

0 commit comments

Comments
 (0)