Changed DHCP table name to DHCP_RELAY

This commit is contained in:
kellyyeh 2021-10-14 23:43:46 +00:00 committed by Ying Xie
parent aa8eecb5ed
commit e5b7b8c05e
4 changed files with 15 additions and 60 deletions

View File

@ -204,6 +204,7 @@ def parse_dpg(dpg, hname):
vlan_intfs = [] vlan_intfs = []
vlans = {} vlans = {}
vlan_members = {} vlan_members = {}
dhcp_relay_table = {}
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))): for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
vintfname = vintf.find(str(QName(ns, "Name"))).text vintfname = vintf.find(str(QName(ns, "Name"))).text
vlanid = vintf.find(str(QName(ns, "VlanID"))).text vlanid = vintf.find(str(QName(ns, "VlanID"))).text
@ -215,6 +216,7 @@ def parse_dpg(dpg, hname):
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'untagged'} vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'untagged'}
vlan_attributes = {'vlanid': vlanid} vlan_attributes = {'vlanid': vlanid}
dhcp_attributes = {}
# If this VLAN requires a DHCP relay agent, it will contain a <DhcpRelays> element # If this VLAN requires a DHCP relay agent, it will contain a <DhcpRelays> element
# containing a list of DHCP server IPs # containing a list of DHCP server IPs
@ -229,34 +231,14 @@ def parse_dpg(dpg, hname):
vintfdhcpservers = vintf_node.text vintfdhcpservers = vintf_node.text
vdhcpserver_list = vintfdhcpservers.split(';') vdhcpserver_list = vintfdhcpservers.split(';')
vlan_attributes['dhcpv6_servers'] = vdhcpserver_list vlan_attributes['dhcpv6_servers'] = vdhcpserver_list
dhcp_attributes['dhcpv6_servers'] = vdhcpserver_list
sonic_vlan_member_name = "Vlan%s" % (vlanid)
dhcp_relay_table[sonic_vlan_member_name] = dhcp_attributes
sonic_vlan_name = "Vlan%s" % vlanid sonic_vlan_name = "Vlan%s" % vlanid
if sonic_vlan_name != vintfname: if sonic_vlan_name != vintfname:
vlan_attributes['alias'] = vintfname vlan_attributes['alias'] = vintfname
vlans[sonic_vlan_name] = vlan_attributes vlans[sonic_vlan_name] = vlan_attributes
dhcp = child.find(str(QName(ns, "Dhcp")))
dhcp_table = {}
if dhcp is not None:
for vintf in dhcp.findall(str(QName(ns, "VlanInterface"))):
vintfname = vintf.find(str(QName(ns, "Name"))).text
dhcp_attributes = {}
dhcp_node = vintf.find(str(QName(ns, "Dhcpv6Relays")))
if dhcp_node is not None and dhcp_node.text is not None:
dhcpservers = dhcp_node.text
vdhcpserver_list = dhcpservers.split(';')
dhcp_attributes['dhcpv6_servers'] = vdhcpserver_list
option_linklayer_addr = vintf.find(str(QName(ns, "Dhcpv6OptionRfc6939")))
if option_linklayer_addr is not None and option_linklayer_addr.text == "true":
dhcp_attributes['dhcpv6_option|rfc6939_support'] = "true"
elif option_linklayer_addr is not None and option_linklayer_addr.text == "false":
dhcp_attributes['dhcpv6_option|rfc6939_support'] = "false"
dhcp_table[vintfname] = dhcp_attributes
aclintfs = child.find(str(QName(ns, "AclInterfaces"))) aclintfs = child.find(str(QName(ns, "AclInterfaces")))
acls = {} acls = {}
@ -343,7 +325,7 @@ def parse_dpg(dpg, hname):
except: except:
print >> sys.stderr, "Warning: Ignoring Control Plane ACL %s without type" % aclname print >> sys.stderr, "Warning: Ignoring Control Plane ACL %s without type" % aclname
return intfs, lo_intfs, mgmt_intf, vlans, vlan_members, dhcp_table, pcs, pc_members, acls return intfs, lo_intfs, mgmt_intf, vlans, vlan_members, dhcp_relay_table, pcs, pc_members, acls
return None, None, None, None, None, None, None return None, None, None, None, None, None, None
@ -555,7 +537,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
pc_intfs = None pc_intfs = None
vlans = None vlans = None
vlan_members = None vlan_members = None
dhcp_table = None dhcp_relay_table = None
pcs = None pcs = None
mgmt_intf = None mgmt_intf = None
lo_intf = None lo_intf = None
@ -593,7 +575,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
port_alias_map.update(alias_map) port_alias_map.update(alias_map)
for child in root: for child in root:
if child.tag == str(QName(ns, "DpgDec")): if child.tag == str(QName(ns, "DpgDec")):
(intfs, lo_intfs, mgmt_intf, vlans, vlan_members, dhcp_table, pcs, pc_members, acls) = parse_dpg(child, hostname) (intfs, lo_intfs, mgmt_intf, vlans, vlan_members, dhcp_relay_table, pcs, pc_members, acls) = parse_dpg(child, hostname)
elif child.tag == str(QName(ns, "CpgDec")): elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) (bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname)
elif child.tag == str(QName(ns, "PngDec")): elif child.tag == str(QName(ns, "PngDec")):
@ -767,7 +749,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key.lower() != hostname.lower() } results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key.lower() != hostname.lower() }
results['SYSLOG_SERVER'] = dict((item, {}) for item in syslog_servers) results['SYSLOG_SERVER'] = dict((item, {}) for item in syslog_servers)
results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers) results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers)
results['DHCP'] = dhcp_table results['DHCP_RELAY'] = dhcp_relay_table
results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers) results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers)
results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers) results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers)

View File

@ -131,23 +131,12 @@
<Name>ab1</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>
<Dhcpv6Relays>fc02:2000::1;fc02:2000::2</Dhcpv6Relays>
<VlanID>1000</VlanID> <VlanID>1000</VlanID>
<Tag>1000</Tag> <Tag>1000</Tag>
<Subnets>192.168.0.0/27</Subnets> <Subnets>192.168.0.0/27</Subnets>
</VlanInterface> </VlanInterface>
</VlanInterfaces> </VlanInterfaces>
<Dhcp>
<VlanInterface>
<Name>Vlan1000</Name>
<Dhcpv6Relays>fc02:2000::1;fc02:2000::2</Dhcpv6Relays>
<Dhcpv6OptionRfc6939>true</Dhcpv6OptionRfc6939>
</VlanInterface>
<VlanInterface>
<Name>Vlan2000</Name>
<Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays>
<Dhcpv6OptionRfc6939>false</Dhcpv6OptionRfc6939>
</VlanInterface>
</Dhcp>
<IPInterfaces> <IPInterfaces>
<IPInterface> <IPInterface>
<Name i:nil="true"/> <Name i:nil="true"/>

View File

@ -336,10 +336,10 @@ class TestCfgGen(TestCase):
self.assertEqual(output.strip(), "{'10.20.30.40': {'rrclient': 0, 'name': 'BGPMonitor', 'local_addr': '10.1.0.32', 'nhopself': 0, 'holdtime': '10', 'asn': '0', 'keepalive': '3'}}") self.assertEqual(output.strip(), "{'10.20.30.40': {'rrclient': 0, 'name': 'BGPMonitor', 'local_addr': '10.1.0.32', 'nhopself': 0, 'holdtime': '10', 'asn': '0', 'keepalive': '3'}}")
def test_minigraph_dhcp(self): def test_minigraph_dhcp(self):
argument = '-m "' + self.sample_graph_simple_case + '" -p "' + self.port_config + '" -v DHCP' argument = '-m "' + self.sample_graph_simple_case + '" -p "' + self.port_config + '" -v DHCP_RELAY'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual( self.assertEqual(
output.strip(), output.strip(),
"{'Vlan1000': {'dhcpv6_option|rfc6939_support': 'true', 'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}, 'Vlan2000': {'dhcpv6_option|rfc6939_support': 'false', 'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4']}}" "{'Vlan1000': {'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}}"
) )

View File

@ -73,7 +73,7 @@ class TestCfgGenCaseInsensitive(TestCase):
def test_minigraph_vlans(self): def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN' argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'Vlan1000': {'alias': 'ab1', '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', 'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}}")
def test_minigraph_vlan_members(self): def test_minigraph_vlan_members(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN_MEMBER' argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN_MEMBER'
@ -140,27 +140,11 @@ class TestCfgGenCaseInsensitive(TestCase):
) )
def test_dhcp_table(self): def test_dhcp_table(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DHCP"' argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DHCP_RELAY"'
expected = {
'Vlan1000': {
'dhcpv6_servers': [
"fc02:2000::1",
"fc02:2000::2"
],
'dhcpv6_option|rfc6939_support': 'true'
},
'Vlan2000': {
'dhcpv6_servers': [
"fc02:2000::3",
"fc02:2000::4"
],
'dhcpv6_option|rfc6939_support': 'false'
}
}
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual( self.assertEqual(
output.strip(), output.strip(),
"{'Vlan1000': {'dhcpv6_option|rfc6939_support': 'true', 'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}, 'Vlan2000': {'dhcpv6_option|rfc6939_support': 'false', 'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4']}}" "{'Vlan1000': {'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}}"
) )