Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,10 @@ def show_session(self, session_name):
val.get("monitor_port", ""), val.get("src_port", ""), val.get("direction", "").lower()])

print("ERSPAN Sessions")
erspan_data = natsorted(erspan_data)
print(tabulate.tabulate(erspan_data, headers=erspan_header, tablefmt="simple", missingval=""))
print("\nSPAN Sessions")
span_data = natsorted(span_data)
print(tabulate.tabulate(span_data, headers=span_header, tablefmt="simple", missingval=""))

def show_policer(self, policer_name):
Expand Down
43 changes: 43 additions & 0 deletions tests/show_mirror_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import sys
from swsscommon.swsscommon import SonicV2Connector
from click.testing import CliRunner
from utilities_common.db import Db

import acl_loader.main as acl_loader_show
from acl_loader import *
from acl_loader.main import *

class TestShowMirror(object):
def test_mirror_show(self):
runner = CliRunner()
aclloader = AclLoader()
aclloader.configdb.set_entry("MIRROR_SESSION", "session1", {"direction": "BOTH", "dst_port": "Ethernet30", "src_port": "Ethernet40", "type": "SPAN"})
aclloader.configdb.set_entry("MIRROR_SESSION", "session2", {"direction": "BOTH", "dst_port": "Ethernet7", "src_port": "Ethernet8", "type": "SPAN"})
aclloader.configdb.set_entry("MIRROR_SESSION", "session11", {"direction": "RX", "dst_port": "Ethernet9", "src_port": "Ethernet10", "type": "SPAN"})
aclloader.configdb.set_entry("MIRROR_SESSION", "session15", {"direction": "TX", "dst_port": "Ethernet2", "src_port": "Ethernet3", "type": "SPAN"})
aclloader.read_sessions_info()
context = {
"acl_loader": aclloader
}
expected_output = """\
ERSPAN Sessions
Name Status SRC IP DST IP GRE DSCP TTL Queue Policer Monitor Port SRC Port Direction
---------------- -------- -------- -------- ----- ------ ----- ------- --------- -------------- --------------------- -----------
test_session_db1 active Ethernet40,Ethernet48 rx

SPAN Sessions
Name Status DST Port SRC Port Direction Queue Policer
--------- -------- ---------- ---------- ----------- ------- ---------
session1 active Ethernet30 Ethernet40 both
session2 active Ethernet7 Ethernet8 both
session11 active Ethernet9 Ethernet10 rx
session15 active Ethernet2 Ethernet3 tx
"""
result = runner.invoke(acl_loader_show.cli.commands['show'].commands['session'], [], obj=context)
assert result.exit_code == 0
print (result.output)
#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.
result_output = result.output.replace('error', 'active')
result_output = result_output.replace('inactive', 'active')
assert result_output == expected_output