diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 748a273d85..4beef0cafa 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -5281,8 +5281,11 @@ If vrf-name is also provided as part of the command, if the vrf is created it wi default Vlan20 Vrf-red Vlan100 Loopback11 + Eth0.100 Vrf-blue Loopback100 Loopback102 + Ethernet0.10 + PortChannel101 ```` ### VRF config commands diff --git a/show/main.py b/show/main.py index 1821f6c9d8..198940bc3e 100755 --- a/show/main.py +++ b/show/main.py @@ -207,7 +207,7 @@ def cli(ctx): def get_interface_bind_to_vrf(config_db, vrf_name): """Get interfaces belong to vrf """ - tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE'] + tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE', 'VLAN_SUB_INTERFACE'] data = [] for table_name in tables: interface_dict = config_db.get_table(table_name) diff --git a/tests/show_vrf_test.py b/tests/show_vrf_test.py new file mode 100644 index 0000000000..3c6d1c5b36 --- /dev/null +++ b/tests/show_vrf_test.py @@ -0,0 +1,39 @@ +import os +import sys +from click.testing import CliRunner +from swsscommon.swsscommon import SonicV2Connector +from utilities_common.db import Db + +import show.main as show + +test_path = os.path.dirname(os.path.abspath(__file__)) +mock_db_path = os.path.join(test_path, "vrf_input") + +class TestShowVrf(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_vrf_show(self): + from .mock_tables import dbconnector + jsonfile_config = os.path.join(mock_db_path, "config_db") + dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config + runner = CliRunner() + db = Db() + expected_output = """\ +VRF Interfaces +------ --------------- +Vrf1 +Vrf101 Ethernet0.10 +Vrf102 PortChannel0002 + Vlan40 + Eth32.10 +Vrf103 Ethernet4 + Loopback0 +""" + + result = runner.invoke(show.cli.commands['vrf'], [], obj=db) + dbconnector.dedicated_dbs = {} + assert result.exit_code == 0 + assert result.output == expected_output diff --git a/tests/vrf_input/config_db.json b/tests/vrf_input/config_db.json new file mode 100644 index 0000000000..6d646f2f2b --- /dev/null +++ b/tests/vrf_input/config_db.json @@ -0,0 +1,35 @@ +{ + "VLAN_SUB_INTERFACE|Ethernet0.10": { + "vrf_name": "Vrf101", + "admin_status": "up" + }, + "VLAN_SUB_INTERFACE|Eth32.10": { + "vrf_name": "Vrf102", + "admin_status": "up", + "vlan": "100" + }, + "VLAN_INTERFACE|Vlan40": { + "vrf_name": "Vrf102" + }, + "PORTCHANNEL_INTERFACE|PortChannel0002": { + "vrf_name": "Vrf102" + }, + "INTERFACE|Ethernet4": { + "vrf_name": "Vrf103" + }, + "LOOPBACK_INTERFACE|Loopback0": { + "vrf_name": "Vrf103" + }, + "VRF|Vrf1": { + "fallback": "false" + }, + "VRF|Vrf101": { + "NULL": "NULL" + }, + "VRF|Vrf102": { + "NULL": "NULL" + }, + "VRF|Vrf103": { + "NULL": "NULL" + } +}