From 4925d48b1ae2e3dddcdbb43c16653023cc5a98e2 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 7 Feb 2018 06:06:41 -0800 Subject: [PATCH] Fix VLAN_INTERFACE attach issue upon vlan id-name mismatch (#1367) --- src/sonic-config-engine/minigraph.py | 6 ++++++ src/sonic-config-engine/tests/simple-sample-graph.xml | 4 ++-- src/sonic-config-engine/tests/test_cfggen.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 23d02a363e..025fecb35e 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -177,6 +177,8 @@ def parse_dpg(dpg, hname): vlan_attributes['dhcp_servers'] = vdhcpserver_list sonic_vlan_name = "Vlan%s" % vlanid + if sonic_vlan_name != vintfname: + vlan_attributes['alias'] = vintfname vlans[sonic_vlan_name] = vlan_attributes aclintfs = child.find(str(QName(ns, "AclInterfaces"))) @@ -398,9 +400,13 @@ def parse_xml(filename, platform=None, port_config_file=None): phyport_intfs = {} vlan_intfs = {} pc_intfs = {} + vlan_invert_mapping = { v['alias']:k for k,v in vlans.items() if v.has_key('alias') } + for intf in intfs: if intf[0][0:4] == 'Vlan': vlan_intfs[intf] = {} + elif vlan_invert_mapping.has_key(intf[0]): + vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])] = {} elif intf[0][0:11] == 'PortChannel': pc_intfs[intf] = {} else: diff --git a/src/sonic-config-engine/tests/simple-sample-graph.xml b/src/sonic-config-engine/tests/simple-sample-graph.xml index 4062cd7ae0..0201aefd3b 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph.xml @@ -128,7 +128,7 @@ - Vlan1000 + ab1 fortyGigE0/8 192.0.0.1;192.0.0.2 1000 @@ -159,7 +159,7 @@ - Vlan1000 + ab1 192.168.0.1/27 diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 9c9b31abf2..7d0c7b516c 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -89,7 +89,7 @@ class TestCfgGen(TestCase): def test_minigraph_vlans(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN' output = self.run_script(argument) - self.assertEqual(output.strip(), "{'Vlan1000': {'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1000'}}") + self.assertEqual(output.strip(), "{'Vlan1000': {'alias': 'ab1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1000'}}") def test_minigraph_vlan_members(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN_MEMBER'