|
| 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