From dab9c6983cb72180571b9eea8e4a360d9694c52f Mon Sep 17 00:00:00 2001 From: kellyyeh <42761586+kellyyeh@users.noreply.github.com> Date: Fri, 20 Aug 2021 09:18:48 -0700 Subject: [PATCH] Changed DHCP table name to DHCP_RELAY (#8476) * Changed DHCP table name to DHCP_RELAY --- src/sonic-config-engine/minigraph.py | 38 +++++-------------- .../tests/simple-sample-graph-case.xml | 14 +------ src/sonic-config-engine/tests/test_cfggen.py | 6 +-- .../tests/test_minigraph_case.py | 12 +++--- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index fffe1af896..756743f85e 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -526,6 +526,7 @@ def parse_dpg(dpg, hname): vlanintfs = child.find(str(QName(ns, "VlanInterfaces"))) vlans = {} vlan_members = {} + dhcp_relay_table = {} vlantype_name = "" intf_vlan_mbr = defaultdict(list) for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))): @@ -553,6 +554,7 @@ def parse_dpg(dpg, hname): vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'untagged'} vlan_attributes = {'vlanid': vlanid, 'members': vmbr_list } + dhcp_attributes = {} # If this VLAN requires a DHCP relay agent, it will contain a element # containing a list of DHCP server IPs @@ -567,6 +569,9 @@ 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 vlanmac = vintf.find(str(QName(ns, "MacAddress"))) if vlanmac is not None and vlanmac.text is not None: @@ -577,29 +582,6 @@ def parse_dpg(dpg, hname): 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 - acls = {} for aclintf in aclintfs.findall(str(QName(ns, "AclInterface"))): if aclintf.find(str(QName(ns, "InAcl"))) is not None: @@ -714,7 +696,7 @@ def parse_dpg(dpg, hname): if mg_key in mg_tunnel.attrib: tunnelintfs[tunnel_type][tunnel_name][table_key] = mg_tunnel.attrib[mg_key] - return intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnelintfs, dpg_ecmp_content + return intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_relay_table, pcs, pc_members, acls, vni, tunnelintfs, dpg_ecmp_content return None, None, None, None, None, None, None, None, None, None, None, None, None def parse_host_loopback(dpg, hname): @@ -1182,7 +1164,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw tunnel_intfs = None vlans = None vlan_members = None - dhcp_table = None + dhcp_relay_table = None pcs = None mgmt_intf = None voq_inband_intfs = None @@ -1241,7 +1223,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw for child in root: if asic_name is None: if child.tag == str(QName(ns, "DpgDec")): - (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, hostname) + (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_relay_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) elif child.tag == str(QName(ns, "PngDec")): @@ -1256,7 +1238,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw (port_speeds_default, port_descriptions, sys_ports) = parse_deviceinfo(child, hwsku) else: if child.tag == str(QName(ns, "DpgDec")): - (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, asic_name) + (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_relay_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, asic_name) host_lo_intfs = parse_host_loopback(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, asic_name, local_devices) @@ -1604,7 +1586,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key in {device['name'] for device in neighbors.values()} } 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) results['ACL_TABLE'] = filter_acl_table_bindings(acls, neighbors, pcs, sub_role) 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 95398e6913..78e81bd6df 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph-case.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph-case.xml @@ -134,6 +134,7 @@ ab1 fortyGigE0/8 192.0.0.1;192.0.0.2 + fc02:2000::1;fc02:2000::2 1000 1000 192.168.0.0/27 @@ -143,23 +144,12 @@ ab2 fortyGigE0/4 192.0.0.1 + fc02:2000::3;fc02:2000::4 2000 2000 - - - 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 868e1ebb99..5be4bb7b75 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -822,13 +822,13 @@ class TestCfgGen(TestCase): ) 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( utils.to_dict(output.strip()), utils.to_dict( - "{'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'}}" + "{'Vlan1000': {'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2']}, " + "'Vlan2000': {'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4']}}" ) ) diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 97c88b2f32..0f736998dd 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -102,6 +102,7 @@ class TestCfgGenCaseInsensitive(TestCase): 'Vlan1000': { 'alias': 'ab1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], + 'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2'], 'vlanid': '1000', 'mac': '00:aa:bb:cc:dd:ee', 'members': ['Ethernet8'] @@ -109,6 +110,7 @@ class TestCfgGenCaseInsensitive(TestCase): 'Vlan2000': { 'alias': 'ab2', 'dhcp_servers': ['192.0.0.1'], + 'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4'], 'members': ['Ethernet4'], 'vlanid': '2000' } @@ -359,21 +361,19 @@ class TestCfgGenCaseInsensitive(TestCase): ) 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': { + 'Vlan2000': { 'dhcpv6_servers': [ "fc02:2000::3", "fc02:2000::4" - ], - 'dhcpv6_option|rfc6939_support': 'false' + ] } } output = self.run_script(argument)