[minigraph] Check for null VLAN MAC (#7854)

Explicitly check for null VLAN MAC in minigraph parser before setting it - if it is null, do not set the VLAN MAC attribute
This commit is contained in:
Lawrence Lee 2021-06-15 11:15:55 -07:00 committed by GitHub
parent 7162532ddf
commit c41a98e222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View File

@ -557,7 +557,7 @@ def parse_dpg(dpg, hname):
vlan_attributes['dhcp_servers'] = vdhcpserver_list
vlanmac = vintf.find(str(QName(ns, "MacAddress")))
if vlanmac != None:
if vlanmac is not None and vlanmac.text is not None:
vlan_attributes['mac'] = vlanmac.text
sonic_vlan_name = "Vlan%s" % vlanid

View File

@ -139,6 +139,14 @@
<Subnets>192.168.0.0/27</Subnets>
<MacAddress>00:aa:bb:cc:dd:ee</MacAddress>
</VlanInterface>
<VlanInterface>
<Name>ab2</Name>
<AttachTo>fortyGigE0/4</AttachTo>
<DhcpRelays>192.0.0.1</DhcpRelays>
<VlanID>2000</VlanID>
<Tag>2000</Tag>
<MacAddress i:nil="true"/>
</VlanInterface>
</VlanInterfaces>
<IPInterfaces>
<IPInterface>

View File

@ -92,15 +92,38 @@ class TestCfgGenCaseInsensitive(TestCase):
def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument)
expected = {
'Vlan1000': {
'alias': 'ab1',
'dhcp_servers': ['192.0.0.1', '192.0.0.2'],
'vlanid': '1000',
'mac': '00:aa:bb:cc:dd:ee',
'members': ['Ethernet8']
},
'Vlan2000': {
'alias': 'ab2',
'dhcp_servers': ['192.0.0.1'],
'members': ['Ethernet4'],
'vlanid': '2000'
}
}
self.assertEqual(
utils.to_dict(output.strip()),
utils.to_dict("{'Vlan1000': {'alias': 'ab1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1000', 'mac': '00:aa:bb:cc:dd:ee', 'members': ['Ethernet8'] }}")
expected
)
def test_minigraph_vlan_members(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN_MEMBER'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}}")
expected = {
'Vlan1000|Ethernet8': {'tagging_mode': 'untagged'},
'Vlan2000|Ethernet4': {'tagging_mode': 'untagged'}
}
self.assertEqual(
utils.to_dict(output.strip()),
expected
)
def test_minigraph_vlan_interfaces_keys(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()|list"'