Fix VLAN_INTERFACE attach issue upon vlan id-name mismatch (#1367)

This commit is contained in:
Taoyu Li 2018-02-07 06:06:41 -08:00 committed by lguohan
parent d0dd80c6d3
commit 4925d48b1a
3 changed files with 9 additions and 3 deletions

View File

@ -177,6 +177,8 @@ def parse_dpg(dpg, hname):
vlan_attributes['dhcp_servers'] = vdhcpserver_list vlan_attributes['dhcp_servers'] = vdhcpserver_list
sonic_vlan_name = "Vlan%s" % vlanid sonic_vlan_name = "Vlan%s" % vlanid
if sonic_vlan_name != vintfname:
vlan_attributes['alias'] = vintfname
vlans[sonic_vlan_name] = vlan_attributes vlans[sonic_vlan_name] = vlan_attributes
aclintfs = child.find(str(QName(ns, "AclInterfaces"))) aclintfs = child.find(str(QName(ns, "AclInterfaces")))
@ -398,9 +400,13 @@ def parse_xml(filename, platform=None, port_config_file=None):
phyport_intfs = {} phyport_intfs = {}
vlan_intfs = {} vlan_intfs = {}
pc_intfs = {} pc_intfs = {}
vlan_invert_mapping = { v['alias']:k for k,v in vlans.items() if v.has_key('alias') }
for intf in intfs: for intf in intfs:
if intf[0][0:4] == 'Vlan': if intf[0][0:4] == 'Vlan':
vlan_intfs[intf] = {} 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': elif intf[0][0:11] == 'PortChannel':
pc_intfs[intf] = {} pc_intfs[intf] = {}
else: else:

View File

@ -128,7 +128,7 @@
</PortChannelInterfaces> </PortChannelInterfaces>
<VlanInterfaces> <VlanInterfaces>
<VlanInterface> <VlanInterface>
<Name>Vlan1000</Name> <Name>ab1</Name>
<AttachTo>fortyGigE0/8</AttachTo> <AttachTo>fortyGigE0/8</AttachTo>
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays> <DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
<VlanID>1000</VlanID> <VlanID>1000</VlanID>
@ -159,7 +159,7 @@
</IPInterface> </IPInterface>
<IPInterface> <IPInterface>
<Name i:nil="true"/> <Name i:nil="true"/>
<AttachTo>Vlan1000</AttachTo> <AttachTo>ab1</AttachTo>
<Prefix>192.168.0.1/27</Prefix> <Prefix>192.168.0.1/27</Prefix>
</IPInterface> </IPInterface>
</IPInterfaces> </IPInterfaces>

View File

@ -89,7 +89,7 @@ class TestCfgGen(TestCase):
def test_minigraph_vlans(self): def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument) 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): def test_minigraph_vlan_members(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN_MEMBER' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN_MEMBER'