Skip to content

Commit a73f156

Browse files
authored
[show][vrf]Fixing show vrf to include vlan subinterface (sonic-net#2158)
* [show][vrf]Fixing show vrf to include vlan subinterface
1 parent 7a06457 commit a73f156

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

doc/Command-Reference.md

+3
Original file line numberDiff line numberDiff line change
@@ -5281,8 +5281,11 @@ If vrf-name is also provided as part of the command, if the vrf is created it wi
52815281
default Vlan20
52825282
Vrf-red Vlan100
52835283
Loopback11
5284+
Eth0.100
52845285
Vrf-blue Loopback100
52855286
Loopback102
5287+
Ethernet0.10
5288+
PortChannel101
52865289
````
52875290
52885291
### VRF config commands

show/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def cli(ctx):
207207
def get_interface_bind_to_vrf(config_db, vrf_name):
208208
"""Get interfaces belong to vrf
209209
"""
210-
tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE']
210+
tables = ['INTERFACE', 'PORTCHANNEL_INTERFACE', 'VLAN_INTERFACE', 'LOOPBACK_INTERFACE', 'VLAN_SUB_INTERFACE']
211211
data = []
212212
for table_name in tables:
213213
interface_dict = config_db.get_table(table_name)

tests/show_vrf_test.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import sys
3+
from click.testing import CliRunner
4+
from swsscommon.swsscommon import SonicV2Connector
5+
from utilities_common.db import Db
6+
7+
import show.main as show
8+
9+
test_path = os.path.dirname(os.path.abspath(__file__))
10+
mock_db_path = os.path.join(test_path, "vrf_input")
11+
12+
class TestShowVrf(object):
13+
@classmethod
14+
def setup_class(cls):
15+
print("SETUP")
16+
os.environ["UTILITIES_UNIT_TESTING"] = "1"
17+
18+
def test_vrf_show(self):
19+
from .mock_tables import dbconnector
20+
jsonfile_config = os.path.join(mock_db_path, "config_db")
21+
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config
22+
runner = CliRunner()
23+
db = Db()
24+
expected_output = """\
25+
VRF Interfaces
26+
------ ---------------
27+
Vrf1
28+
Vrf101 Ethernet0.10
29+
Vrf102 PortChannel0002
30+
Vlan40
31+
Eth32.10
32+
Vrf103 Ethernet4
33+
Loopback0
34+
"""
35+
36+
result = runner.invoke(show.cli.commands['vrf'], [], obj=db)
37+
dbconnector.dedicated_dbs = {}
38+
assert result.exit_code == 0
39+
assert result.output == expected_output

tests/vrf_input/config_db.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"VLAN_SUB_INTERFACE|Ethernet0.10": {
3+
"vrf_name": "Vrf101",
4+
"admin_status": "up"
5+
},
6+
"VLAN_SUB_INTERFACE|Eth32.10": {
7+
"vrf_name": "Vrf102",
8+
"admin_status": "up",
9+
"vlan": "100"
10+
},
11+
"VLAN_INTERFACE|Vlan40": {
12+
"vrf_name": "Vrf102"
13+
},
14+
"PORTCHANNEL_INTERFACE|PortChannel0002": {
15+
"vrf_name": "Vrf102"
16+
},
17+
"INTERFACE|Ethernet4": {
18+
"vrf_name": "Vrf103"
19+
},
20+
"LOOPBACK_INTERFACE|Loopback0": {
21+
"vrf_name": "Vrf103"
22+
},
23+
"VRF|Vrf1": {
24+
"fallback": "false"
25+
},
26+
"VRF|Vrf101": {
27+
"NULL": "NULL"
28+
},
29+
"VRF|Vrf102": {
30+
"NULL": "NULL"
31+
},
32+
"VRF|Vrf103": {
33+
"NULL": "NULL"
34+
}
35+
}

0 commit comments

Comments
 (0)