From e5b7b8c05ef768f59eeb38a3b1e4e001c6559cef Mon Sep 17 00:00:00 2001 From: kellyyeh Date: Thu, 14 Oct 2021 23:43:46 +0000 Subject: [PATCH] Changed DHCP table name to DHCP_RELAY --- src/sonic-config-engine/minigraph.py | 36 +++++-------------- .../tests/simple-sample-graph-case.xml | 13 +------ src/sonic-config-engine/tests/test_cfggen.py | 4 +-- .../tests/test_minigraph_case.py | 22 ++---------- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index f656bfa800..97848782b9 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -204,6 +204,7 @@ def parse_dpg(dpg, hname): vlan_intfs = [] vlans = {} vlan_members = {} + dhcp_relay_table = {} for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))): vintfname = vintf.find(str(QName(ns, "Name"))).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_attributes = {'vlanid': vlanid} + dhcp_attributes = {} # If this VLAN requires a DHCP relay agent, it will contain a element # containing a list of DHCP server IPs @@ -229,34 +231,14 @@ def parse_dpg(dpg, hname): vintfdhcpservers = vintf_node.text vdhcpserver_list = vintfdhcpservers.split(';') 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 if sonic_vlan_name != vintfname: vlan_attributes['alias'] = vintfname 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"))) acls = {} @@ -343,7 +325,7 @@ def parse_dpg(dpg, hname): except: 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 @@ -555,7 +537,7 @@ def parse_xml(filename, platform=None, port_config_file=None): pc_intfs = None vlans = None vlan_members = None - dhcp_table = None + dhcp_relay_table = None pcs = None mgmt_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) for child in root: 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")): (bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) 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['SYSLOG_SERVER'] = dict((item, {}) for item in syslog_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['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers) diff --git a/src/sonic-config-engine/tests/simple-sample-graph-case.xml b/src/sonic-config-engine/tests/simple-sample-graph-case.xml index c571a1df71..3074e1cabe 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph-case.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph-case.xml @@ -131,23 +131,12 @@ ab1 fortyGigE0/8 192.0.0.1;192.0.0.2 + fc02:2000::1;fc02:2000::2 1000 1000 192.168.0.0/27 - - - Vlan1000 - fc02:2000::1;fc02:2000::2 - true - - - Vlan2000 - fc02:2000::3;fc02:2000::4 - false - - diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 3405c8d8c1..8bc011f976 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -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'}}") 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) self.assertEqual( 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']}}" ) \ No newline at end of file diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 35fd2be7f9..a89747ae54 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -73,7 +73,7 @@ class TestCfgGenCaseInsensitive(TestCase): def test_minigraph_vlans(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN' 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): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN_MEMBER' @@ -140,27 +140,11 @@ class TestCfgGenCaseInsensitive(TestCase): ) def test_dhcp_table(self): - argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DHCP"' - 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' - } - } + argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DHCP_RELAY"' output = self.run_script(argument) self.assertEqual( 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']}}" )