diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index b29c277ee2e..3eff15307e8 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -46,6 +46,10 @@ FRONTEND_ASIC_SUB_ROLE = 'FrontEnd' BACKEND_ASIC_SUB_ROLE = 'BackEnd' +DEFAULT_DHCP_SERVER_LEASE_TIME = 900 +DEFAULT_DHCP_SERVER_MODE = "PORT" +RACK_MGMT_MAP = "rack_mgmt_map" +DHCP_SERVER_IP = "240.127.1.2" dualtor_cable_types = ["active-active", "active-standby"] @@ -219,6 +223,7 @@ def parse_png(png, hname, dpg_ecmp_content = None): mux_cable_ports = {} port_device_map = {} png_ecmp_content = {} + link_ports = {} FG_NHG_MEMBER = {} FG_NHG = {} NEIGH = {} @@ -262,6 +267,11 @@ def parse_png(png, hname, dpg_ecmp_content = None): startport = link.find(str(QName(ns, "StartPort"))).text bandwidth_node = link.find(str(QName(ns, "Bandwidth"))) bandwidth = bandwidth_node.text if bandwidth_node is not None else None + if linktype == "DeviceMgmtLink": + # To get port - device map + link_device = enddevice if startdevice.lower() == hname.lower() else startdevice + link_port = startport if startdevice.lower() == hname.lower() else endport + link_ports[link_port] = link_device if enddevice.lower() == hname.lower(): if endport in port_alias_map: endport = port_alias_map[endport] @@ -338,7 +348,7 @@ def parse_png(png, hname, dpg_ecmp_content = None): png_ecmp_content = {"FG_NHG_MEMBER": FG_NHG_MEMBER, "FG_NHG": FG_NHG, "NEIGH": NEIGH} - return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content) + return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content, link_ports) def parse_asic_external_link(link, asic_name, hostname): @@ -1441,6 +1451,63 @@ def select_mmu_profiles(profile, platform, hwsku): base_file = os.path.join(path, file_item) exec_cmd(["sudo", "cp", file_in_dir, base_file]) + +def generate_ipv4_dhcp_server_config(devices, link_ports, port_alias_map, vlan_intfs, vlan_members, rack_mgmt_map): + """ + Generate IPv4 DHCP Server related config + """ + dhcp_server_ipv4 = {} + dhcp_server_ipv4_port = {} + dhcp_server_ipv4_customized_options = {} + + # Use option 223 in DHCP packet to send rack_mgmt_map + if rack_mgmt_map is not None: + dhcp_server_ipv4_customized_options = { + RACK_MGMT_MAP: { + "id": 223, + "type": "text", + "value": rack_mgmt_map + } + } + + alias_port_map = dict((v, k) for k, v in port_alias_map.items()) + # Generate DHCP_SERVER_IPV4 part + for vlan_intf in list(vlan_intfs.keys()): + if not isinstance(vlan_intf, tuple): + continue + + vlan_name = vlan_intf[0] + vlan_intf_str = vlan_intf[1] + vlan_network = ipaddress.ip_network(UNICODE_TYPE(vlan_intf_str), False) + if vlan_network.version != 4: + continue + dhcp_server_ipv4[vlan_name] = { + "gateway": vlan_intf_str.split("/")[0], + "lease_time": DEFAULT_DHCP_SERVER_LEASE_TIME, + "mode": DEFAULT_DHCP_SERVER_MODE, + "netmask": str(vlan_network.netmask), + "state": "enabled" + } + if rack_mgmt_map is not None: + dhcp_server_ipv4[vlan_name]["customized_options"] = [RACK_MGMT_MAP] + + # Generate DHCP_SERVER_IPV4_PORT part + for vlan_member in list(vlan_members.keys()): + interface = vlan_member[1] + if interface not in alias_port_map or alias_port_map[interface] not in link_ports: + continue + neighbor_device = link_ports[alias_port_map[interface]] + if not neighbor_device.endswith("BMC"): + continue + mgmt_ip_str = devices[neighbor_device]["mgmt_addr"] + dhcp_server_ipv4_port[vlan_member] = { + "ips": [ + mgmt_ip_str.split("/")[0] + ] + } + return dhcp_server_ipv4, dhcp_server_ipv4_port, dhcp_server_ipv4_customized_options + + ############################################################################### # # Main functions @@ -1521,6 +1588,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw redundancy_type = None qos_profile = None rack_mgmt_map = None + dhcp_server_ipv4 = None + dhcp_server_ipv4_port = None + dhcp_server_ipv4_customized_options = None hwsku_qn = QName(ns, "HwSku") hostname_qn = QName(ns, "Hostname") @@ -1549,9 +1619,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw elif child.tag == str(QName(ns, "CpgDec")): (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors, bgp_sentinel_sessions) = parse_cpg(child, hostname) elif child.tag == str(QName(ns, "PngDec")): - (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, png_ecmp_content) = parse_png(child, hostname, dpg_ecmp_content) + (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, png_ecmp_content, link_ports) = parse_png(child, hostname, dpg_ecmp_content) elif child.tag == str(QName(ns, "UngDec")): - (u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname, None) + (u_neighbors, u_devices, _, _, _, _, _, _, _) = parse_png(child, hostname, None) elif child.tag == str(QName(ns, "MetadataDeclaration")): (syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map) = parse_meta(child, hostname) elif child.tag == str(QName(ns, "LinkMetadataDeclaration")): @@ -2010,7 +2080,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw else: 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) + # For BmcMgmtToRRouter, treat docker ip as new dhcp_server + results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers) \ + if devices[hostname]["type"] != "BmcMgmtToRRouter" else {DHCP_SERVER_IP: {}} results['DHCP_RELAY'] = dhcp_relay_table results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers) # Set default DNS nameserver from dns.j2 @@ -2068,6 +2140,18 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw 'client_crt_cname': 'client.restapi.sonic' } } + if devices[hostname]["type"] == "BmcMgmtToRRouter": + dhcp_server_ipv4, dhcp_server_ipv4_port, dhcp_server_ipv4_customized_options = \ + generate_ipv4_dhcp_server_config(devices, link_ports, port_alias_map, vlan_intfs, vlan_members, + rack_mgmt_map) + for vlan_name, _ in results["VLAN"].items(): + # For BmcMgmtToRRouter, treat docker ip as new dhcp_server + results["VLAN"][vlan_name]["dhcp_servers"] = [DHCP_SERVER_IP] + if dhcp_server_ipv4 is not None: + results['DHCP_SERVER_IPV4'] = dhcp_server_ipv4 + if dhcp_server_ipv4_customized_options: + results['DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS'] = dhcp_server_ipv4_customized_options + results['DHCP_SERVER_IPV4_PORT'] = dhcp_server_ipv4_port if len(png_ecmp_content): results['FG_NHG_MEMBER'] = png_ecmp_content['FG_NHG_MEMBER'] diff --git a/src/sonic-config-engine/tests/sample-nokia-7215-port-config.ini b/src/sonic-config-engine/tests/sample-nokia-7215-port-config.ini new file mode 100644 index 00000000000..5bea7fb561e --- /dev/null +++ b/src/sonic-config-engine/tests/sample-nokia-7215-port-config.ini @@ -0,0 +1,53 @@ +# name lanes alias +Ethernet0 1 etp1 +Ethernet1 2 etp2 +Ethernet2 3 etp3 +Ethernet3 4 etp4 +Ethernet4 5 etp5 +Ethernet5 6 etp6 +Ethernet6 7 etp7 +Ethernet7 8 etp8 +Ethernet8 9 etp9 +Ethernet9 10 etp10 +Ethernet10 11 etp11 +Ethernet11 12 etp12 +Ethernet12 13 etp13 +Ethernet13 14 etp14 +Ethernet14 15 etp15 +Ethernet15 16 etp16 +Ethernet16 17 etp17 +Ethernet17 18 etp18 +Ethernet18 19 etp19 +Ethernet19 20 etp20 +Ethernet20 21 etp21 +Ethernet21 22 etp22 +Ethernet22 23 etp23 +Ethernet23 24 etp24 +Ethernet24 25 etp25 +Ethernet25 26 etp26 +Ethernet26 27 etp27 +Ethernet27 28 etp28 +Ethernet28 29 etp29 +Ethernet29 30 etp30 +Ethernet30 31 etp31 +Ethernet31 32 etp32 +Ethernet32 33 etp33 +Ethernet33 34 etp34 +Ethernet34 35 etp35 +Ethernet35 36 etp36 +Ethernet36 37 etp37 +Ethernet37 38 etp38 +Ethernet38 39 etp39 +Ethernet39 40 etp40 +Ethernet40 41 etp41 +Ethernet41 42 etp42 +Ethernet42 43 etp43 +Ethernet43 44 etp44 +Ethernet44 45 etp45 +Ethernet45 46 etp46 +Ethernet46 47 etp47 +Ethernet47 48 etp48 +Ethernet48 49 etp49 +Ethernet49 50 etp50 +Ethernet50 51 etp51 +Ethernet51 52 etp52 diff --git a/src/sonic-config-engine/tests/simple-sample-graph-7215-mx.xml b/src/sonic-config-engine/tests/simple-sample-graph-7215-mx.xml new file mode 100644 index 00000000000..5411ca73d7d --- /dev/null +++ b/src/sonic-config-engine/tests/simple-sample-graph-7215-mx.xml @@ -0,0 +1,1370 @@ + + + + + + false + switch-mx + 10.0.0.64 + ARISTA01M0 + 10.0.0.65 + 1 + 10 + 3 + + + switch-mx + FC00::81 + ARISTA01M0 + FC00::82 + 1 + 10 + 3 + + + false + switch-mx + 10.0.0.66 + ARISTA02M0 + 10.0.0.67 + 1 + 10 + 3 + + + switch-mx + FC00::85 + ARISTA02M0 + FC00::86 + 1 + 10 + 3 + + + + + 64001 + switch-mx + + +
10.0.0.65
+ + + +
+ +
10.0.0.67
+ + + +
+ + BGPPeer +
10.1.0.32
+ + + + BGPSLBPassive + 10.255.0.0/25 +
+ + BGPPeer +
10.1.0.32
+ + + + BGPVac + 192.168.0.0/21 +
+
+ +
+ + 65100 + ARISTA01M0 + + + + 65100 + ARISTA02M0 + + +
+
+ + + + + + HostIP + Loopback0 + + 10.1.0.32/32 + + 10.1.0.32/32 + + + HostIP1 + Loopback0 + + FC00:1::32/128 + + FC00:1::32/128 + + + + + HostIP + eth0 + + 10.0.0.100/23 + + 10.0.0.100/23 + + + V6HostIP + eth0 + + FC00:2::32/64 + + FC00:2::32/64 + + + + + + + switch-mx + + + + + Vlan1000 + etp1;etp2;etp3;etp4;etp5;etp6;etp7;etp8;etp9;etp10;etp11;etp12;etp13;etp14;etp15;etp16;etp17;etp18;etp19;etp20;etp21;etp22;etp23;etp24;etp25;etp26;etp27;etp28;etp29;etp30;etp31;etp32;etp33;etp34;etp35;etp36;etp37;etp38;etp39;etp40;etp41;etp42;etp43;etp44;etp45;etp46 + False + 0.0.0.0/0 + 192.0.0.1;192.0.0.2;192.0.0.3;192.0.0.4;192.0.0.5;192.0.0.6;192.0.0.7;192.0.0.8;192.0.0.9;192.0.0.10;192.0.0.11;192.0.0.12;192.0.0.13;192.0.0.14;192.0.0.15;192.0.0.16;192.0.0.17;192.0.0.18;192.0.0.19;192.0.0.20;192.0.0.21;192.0.0.22;192.0.0.23;192.0.0.24;192.0.0.25;192.0.0.26;192.0.0.27;192.0.0.28;192.0.0.29;192.0.0.30;192.0.0.31;192.0.0.32;192.0.0.33;192.0.0.34;192.0.0.35;192.0.0.36;192.0.0.37;192.0.0.38;192.0.0.39;192.0.0.40;192.0.0.41;192.0.0.42;192.0.0.43;192.0.0.44;192.0.0.45;192.0.0.46;192.0.0.47;192.0.0.48 + fc02:2000::1;fc02:2000::2;fc02:2000::3;fc02:2000::4 + 1000 + 1000 + 192.168.0.0/24 + + + + + + etp47 + 10.0.0.64/31 + + + + etp47 + FC00::81/126 + + + + etp48 + 10.0.0.66/31 + + + + etp48 + FC00::85/126 + + + + Vlan1000 + 192.168.0.1/24 + + + + Vlan1000 + fc02:1000::1/64 + + + + + + NTP_ACL + NTP + NTP + + + SNMP_ACL + SNMP + SNMP + + + VTY_LINE + ssh-only + SSH + + + ERSPAN + Everflow + Everflow + + + ERSPANV6 + EverflowV6 + EverflowV6 + + + etp47;etp48 + DataAcl + DataPlane + + + + + + + + + + DeviceInterfaceLink + ARISTA01M0 + Ethernet1 + switch-mx + etp47 + 1000 + + + DeviceInterfaceLink + ARISTA02M0 + Ethernet1 + switch-mx + etp48 + 1000 + + + DeviceMgmtLink + switch-mx + etp1 + TEST01BMC + eth0 + + + DeviceMgmtLink + switch-mx + etp2 + TEST02BMC + eth0 + + + DeviceInterfaceLink + switch-mx + etp3 + Servers2 + eth0 + + + DeviceInterfaceLink + switch-mx + etp4 + Servers3 + eth0 + + + DeviceInterfaceLink + switch-mx + etp5 + Servers4 + eth0 + + + DeviceInterfaceLink + switch-mx + etp6 + Servers5 + eth0 + + + DeviceInterfaceLink + switch-mx + etp7 + Servers6 + eth0 + + + DeviceInterfaceLink + switch-mx + etp8 + Servers7 + eth0 + + + DeviceInterfaceLink + switch-mx + etp9 + Servers8 + eth0 + + + DeviceInterfaceLink + switch-mx + etp10 + Servers9 + eth0 + + + DeviceInterfaceLink + switch-mx + etp11 + Servers10 + eth0 + + + DeviceInterfaceLink + switch-mx + etp12 + Servers11 + eth0 + + + DeviceInterfaceLink + switch-mx + etp13 + Servers12 + eth0 + + + DeviceInterfaceLink + switch-mx + etp14 + Servers13 + eth0 + + + DeviceInterfaceLink + switch-mx + etp15 + Servers14 + eth0 + + + DeviceInterfaceLink + switch-mx + etp16 + Servers15 + eth0 + + + DeviceInterfaceLink + switch-mx + etp17 + Servers16 + eth0 + + + DeviceInterfaceLink + switch-mx + etp18 + Servers17 + eth0 + + + DeviceInterfaceLink + switch-mx + etp19 + Servers18 + eth0 + + + DeviceInterfaceLink + switch-mx + etp20 + Servers19 + eth0 + + + DeviceInterfaceLink + switch-mx + etp21 + Servers20 + eth0 + + + DeviceInterfaceLink + switch-mx + etp22 + Servers21 + eth0 + + + DeviceInterfaceLink + switch-mx + etp23 + Servers22 + eth0 + + + DeviceInterfaceLink + switch-mx + etp24 + Servers23 + eth0 + + + DeviceInterfaceLink + switch-mx + etp25 + Servers24 + eth0 + + + DeviceInterfaceLink + switch-mx + etp26 + Servers25 + eth0 + + + DeviceInterfaceLink + switch-mx + etp27 + Servers26 + eth0 + + + DeviceInterfaceLink + switch-mx + etp28 + Servers27 + eth0 + + + DeviceInterfaceLink + switch-mx + etp29 + Servers28 + eth0 + + + DeviceInterfaceLink + switch-mx + etp30 + Servers29 + eth0 + + + DeviceInterfaceLink + switch-mx + etp31 + Servers30 + eth0 + + + DeviceInterfaceLink + switch-mx + etp32 + Servers31 + eth0 + + + DeviceInterfaceLink + switch-mx + etp33 + Servers32 + eth0 + + + DeviceInterfaceLink + switch-mx + etp34 + Servers33 + eth0 + + + DeviceInterfaceLink + switch-mx + etp35 + Servers34 + eth0 + + + DeviceInterfaceLink + switch-mx + etp36 + Servers35 + eth0 + + + DeviceInterfaceLink + switch-mx + etp37 + Servers36 + eth0 + + + DeviceInterfaceLink + switch-mx + etp38 + Servers37 + eth0 + + + DeviceInterfaceLink + switch-mx + etp39 + Servers38 + eth0 + + + DeviceInterfaceLink + switch-mx + etp40 + Servers39 + eth0 + + + DeviceInterfaceLink + switch-mx + etp41 + Servers40 + eth0 + + + DeviceInterfaceLink + switch-mx + etp42 + Servers41 + eth0 + + + DeviceInterfaceLink + switch-mx + etp43 + Servers42 + eth0 + + + DeviceInterfaceLink + switch-mx + etp44 + Servers43 + eth0 + + + DeviceInterfaceLink + switch-mx + etp45 + Servers44 + eth0 + + + DeviceInterfaceLink + switch-mx + etp46 + Servers45 + eth0 + + + + + switch-mx + Nokia-7215 + + 10.0.0.100 + + + + ARISTA01M0 + + 172.0.0.128 + + Arista-VM + + + ARISTA02M0 + + 172.0.0.129 + + Arista-VM + + + Bmc +
+ 0.0.0.0/0 +
+ + ::/0 + + + + + + + + + + + 192.168.0.2/32 + + + fc02:1000::2/128 + + + + TEST01BMC + BMC +
+ + Bmc +
+ 0.0.0.0/0 +
+ + ::/0 + + + + + + + + + + + 192.168.0.3/32 + + + fc02:1000::3/128 + + + + TEST02BMC + BMC +
+
+
+ + + true + + + DeviceInterface + + true + true + 1 + etp1 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp2 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp3 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp4 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp5 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp6 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp7 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp8 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp9 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp10 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp11 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp12 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp13 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp14 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp15 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp16 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp17 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp18 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp19 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp20 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp21 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp22 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp23 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp24 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp25 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp26 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp27 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp28 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp29 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp30 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp31 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp32 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp33 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp34 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp35 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp36 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp37 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp38 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp39 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp40 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp41 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp42 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp43 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp44 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp45 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp46 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp47 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp48 + + false + 0 + 0 + 1000 + + + DeviceInterface + + true + true + 1 + etp49 + + false + 0 + 0 + 10000 + + + DeviceInterface + + true + true + 1 + etp50 + + false + 0 + 0 + 10000 + + + DeviceInterface + + true + true + 1 + etp51 + + false + 0 + 0 + 10000 + + + DeviceInterface + + true + true + 1 + etp52 + + false + 0 + 0 + 10000 + + + true + 0 + Nokia-7215 + + + + + + + switch-mx + + + DeploymentId + + 1 + + + NtpResources + + 10.0.10.1;10.0.10.2 + + + SnmpResources + + 10.0.10.3;10.0.10.4 + + + SyslogResources + + 10.0.10.5;10.0.10.6 + + + TacacsServer + + 10.0.10.7;10.0.10.8 + + + RackMgmtMap + + dummy_value + + + + + + + switch-mx + Nokia-7215 +
diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index e1242a3fa9e..4345c83927b 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -23,7 +23,9 @@ def setUp(self): self.sample_subintf_graph = os.path.join(self.test_dir, 'sample-graph-subintf.xml') self.sample_simple_device_desc = os.path.join(self.test_dir, 'simple-sample-device-desc.xml') self.sample_simple_device_desc_ipv6_only = os.path.join(self.test_dir, 'simple-sample-device-desc-ipv6-only.xml') + self.sample_graph_7215_mx = os.path.join(self.test_dir, 'simple-sample-graph-7215-mx.xml') self.port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini') + self.nokia_7215_port_config = os.path.join(self.test_dir, 'sample-nokia-7215-port-config.ini') def run_script(self, argument, check_stderr=False): print('\n Running sonic-cfggen ' + ' '.join(argument)) @@ -198,6 +200,54 @@ def test_minigraph_rack_mgmt_map(self): output = self.run_script(argument) self.assertEqual(output.strip(), "dummy_value") + def test_dhcp_server_ipv4(self): + argument = ['-m', self.sample_graph_7215_mx, '-p', self.nokia_7215_port_config, '-v', 'DHCP_SERVER_IPV4'] + output = self.run_script(argument) + expected_table_str = "{'Vlan1000': {'gateway': '192.168.0.1', 'lease_time': 900, 'customized_options': " + \ + "['rack_mgmt_map'], 'mode': 'PORT', 'netmask': '255.255.255.0', 'state': 'enabled'}}" + self.assertEqual(utils.to_dict(output.strip()), utils.to_dict(expected_table_str)) + + def test_dhcp_server_ipv4_port(self): + argument = ['-m', self.sample_graph_7215_mx, '-p', self.nokia_7215_port_config, '-v', 'DHCP_SERVER_IPV4_PORT'] + output = self.run_script(argument) + expected_table = { + 'Vlan1000|Ethernet0': { + 'ips': ['192.168.0.2'] + }, + 'Vlan1000|Ethernet1': { + 'ips': ['192.168.0.3'] + } + } + self.assertEqual(utils.to_dict(output.strip()), expected_table) + + def test_mx_dhcp_server_table(self): + argument = ['-m', self.sample_graph_7215_mx, '-p', self.nokia_7215_port_config, '-v', 'DHCP_SERVER'] + output = self.run_script(argument) + expected_table = { + "240.127.1.2": {} + } + self.assertEqual(utils.to_dict(output.strip()), expected_table) + + def test_mx_dhcp_servers(self): + argument = ['-m', self.sample_graph_7215_mx, '-p', self.nokia_7215_port_config, '-v', 'VLAN'] + output = self.run_script(argument) + expected_table_str = "{'Vlan1000': {'vlanid': '1000', 'dhcp_servers': ['240.127.1.2'], 'dhcpv6_servers': " + \ + "['fc02:2000::1', 'fc02:2000::2', 'fc02:2000::3', 'fc02:2000::4']}}" + self.assertEqual(utils.to_dict(output.strip()), utils.to_dict(expected_table_str)) + + def test_dhcp_server_ipv4_customized_options(self): + argument = ['-m', self.sample_graph_7215_mx, '-p', self.nokia_7215_port_config, '-v', + 'DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS'] + output = self.run_script(argument) + expected_table = { + 'rack_mgmt_map': { + 'id': 223, + 'type': 'text', + 'value': 'dummy_value' + } + } + self.assertEqual(utils.to_dict(output.strip()), expected_table) + def test_minigraph_cluster(self): argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', "DEVICE_METADATA[\'localhost\'][\'cluster\']"] output = self.run_script(argument)