Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show][vrf]Fixing show vrf to include vlan subinterface #2158

Merged
merged 2 commits into from
May 10, 2022
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
3 changes: 3 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions tests/show_vrf_test.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions tests/vrf_input/config_db.json
Original file line number Diff line number Diff line change
@@ -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"
}
}