[minigraph]: Adding new secondary field to VLAN_INTERFACE table (#16827)
This is change taken as part of the HLD: sonic-net/SONiC#1470. In this PR we add the logic to parse the SecondarySubnets field in the minigraph and add a flag in "secondary" in the vlan_interface table of the config db. Microsoft ADO (number only): 16784946 How I did it Made changes in the minigraph.py to parse the xml entry and add the parsed value to the config db How to verify it Added python tests in the sonic-config-engine folder to test the config db entries.
This commit is contained in:
parent
c0963db5a3
commit
fad1081b2f
@ -686,6 +686,17 @@ def parse_dpg(dpg, hname):
|
||||
if vlanmac is not None and vlanmac.text is not None:
|
||||
vlan_attributes['mac'] = vlanmac.text
|
||||
|
||||
vintf_node = vintf.find(str(QName(ns, "SecondarySubnets")))
|
||||
if vintf_node is not None and vintf_node.text is not None:
|
||||
subnets = vintf_node.text.split(';')
|
||||
for subnet in subnets:
|
||||
if sys.version_info >= (3, 0):
|
||||
network_def = ipaddress.ip_network(subnet, strict=False)
|
||||
else:
|
||||
network_def = ipaddress.ip_network(unicode(subnet), strict=False)
|
||||
prefix = str(network_def[1]) + "/" + str(network_def.prefixlen)
|
||||
intfs[(vintfname, prefix)]["secondary"] = "true"
|
||||
|
||||
sonic_vlan_name = "Vlan%s" % vlanid
|
||||
if sonic_vlan_name != vintfname:
|
||||
vlan_attributes['alias'] = vintfname
|
||||
@ -1729,6 +1740,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
|
||||
if intf[0][0:4] == 'Vlan':
|
||||
vlan_intfs[intf] = {}
|
||||
|
||||
if "secondary" in intfs[intf]:
|
||||
vlan_intfs[intf]["secondary"] = "true"
|
||||
|
||||
if bool(results['PEER_SWITCH']):
|
||||
vlan_intfs[intf[0]] = {
|
||||
'proxy_arp': 'enabled',
|
||||
@ -1739,6 +1753,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
|
||||
elif intf[0] in vlan_invert_mapping:
|
||||
vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])] = {}
|
||||
|
||||
if "secondary" in intfs[intf]:
|
||||
vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])]["secondary"] = "true"
|
||||
|
||||
if bool(results['PEER_SWITCH']):
|
||||
vlan_intfs[vlan_invert_mapping[intf[0]]] = {
|
||||
'proxy_arp': 'enabled',
|
||||
|
@ -138,6 +138,7 @@
|
||||
<VlanID>1000</VlanID>
|
||||
<Tag>1000</Tag>
|
||||
<Subnets>192.168.0.0/27</Subnets>
|
||||
<SecondarySubnets>192.168.1.0/27</SecondarySubnets>
|
||||
<MacAddress>00:aa:bb:cc:dd:ee</MacAddress>
|
||||
</VlanInterface>
|
||||
<VlanInterface>
|
||||
@ -176,6 +177,11 @@
|
||||
<AttachTo>ab1</AttachTo>
|
||||
<Prefix>192.168.0.1/27</Prefix>
|
||||
</IPInterface>
|
||||
<IPInterface>
|
||||
<Name i:nil="true"/>
|
||||
<AttachTo>ab1</AttachTo>
|
||||
<Prefix>192.168.1.1/27</Prefix>
|
||||
</IPInterface>
|
||||
</IPInterfaces>
|
||||
<DataAcls/>
|
||||
<AclInterfaces>
|
||||
|
@ -139,7 +139,10 @@ class TestCfgGenCaseInsensitive(TestCase):
|
||||
def test_minigraph_vlan_interfaces_keys(self):
|
||||
argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', "VLAN_INTERFACE.keys()|list"]
|
||||
output = self.run_script(argument)
|
||||
self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27'), 'Vlan1000']")
|
||||
expected_list_dict = {
|
||||
'list': ['Vlan1000', 'Vlan1000|192.168.0.1/27', 'Vlan1000|192.168.1.1/27']
|
||||
}
|
||||
self.assertEqual(utils.liststr_to_dict(output.strip()), expected_list_dict)
|
||||
|
||||
def test_minigraph_vlan_interfaces(self):
|
||||
argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', "VLAN_INTERFACE"]
|
||||
@ -149,6 +152,9 @@ class TestCfgGenCaseInsensitive(TestCase):
|
||||
'Vlan1000': {
|
||||
'proxy_arp': 'enabled',
|
||||
'grat_arp': 'enabled'
|
||||
},
|
||||
'Vlan1000|192.168.1.1/27': {
|
||||
'secondary': 'true'
|
||||
}
|
||||
}
|
||||
self.assertEqual(utils.to_dict(output.strip()), expected_table)
|
||||
|
@ -158,6 +158,11 @@ module sonic-vlan {
|
||||
(contains(../ip-prefix, '.') and current()='IPv4')";
|
||||
type stypes:ip-family;
|
||||
}
|
||||
|
||||
leaf secondary {
|
||||
description "Optional field to specify if the prefix is secondary subnet";
|
||||
type boolean;
|
||||
}
|
||||
}
|
||||
/* end of VLAN_INTERFACE_LIST */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user