From 9a6da79c40e52f4603ad4a90cc7bd82cdd30321c Mon Sep 17 00:00:00 2001 From: geogchen <106694330+geogchen@users.noreply.github.com> Date: Thu, 30 Jun 2022 09:34:27 -0700 Subject: [PATCH] [Interfaces] Add more unit tests for interfaces.j2 (#11277) #### Why I did it The tests that are available for interfaces.j2 only covers the case when ZTP is disabled and MGMT_INTERFACE is defined. This change adds unit tests for: 1) When ZTP is enabled, with combination of (ip enabled/disabled, inband enabled/disabled) 2) When ZTP is disabled, and MGMT_INTERFACE is not defined, with mgmtVrfEnabled set to true/false #### How I did it I created multiple mock-up files to: 1) Enable/disable ZTP, and subconditions under ZTP 2) Created graph file that has no management interface defined #### How to verify it Compared output with interfaces.j2 template to ensure the output is expected. #### Which release branch to backport (provide reason below if selected) - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [ ] 202205 #### Description for the changelog #### Link to config_db schema for YANG module changes #### A picture of a cute animal (not mandatory but encouraged) --- .../tests/sample-port-data.json | 9 + .../tests/sample-ztp-inband-ip.json | 10 + .../tests/sample-ztp-inband.json | 8 + .../tests/sample-ztp-ip.json | 9 + src/sonic-config-engine/tests/sample-ztp.json | 7 + .../tests/sample_output/py2/interfaces_nomgmt | 24 + .../sample_output/py2/interfaces_nomgmt_ztp | 25 + .../py2/interfaces_nomgmt_ztp_inband | 29 + .../py2/interfaces_nomgmt_ztp_inband_ip | 35 + .../py2/interfaces_nomgmt_ztp_ip | 29 + .../sample_output/py2/mvrf_interfaces_nomgmt | 34 + .../tests/sample_output/py3/interfaces_nomgmt | 24 + .../sample_output/py3/interfaces_nomgmt_ztp | 25 + .../py3/interfaces_nomgmt_ztp_inband | 29 + .../py3/interfaces_nomgmt_ztp_inband_ip | 35 + .../py3/interfaces_nomgmt_ztp_ip | 29 + .../sample_output/py3/mvrf_interfaces_nomgmt | 34 + .../tests/t0-sample-graph-mvrf-nomgmt.xml | 797 +++++++++++++++ .../tests/t0-sample-graph-nomgmt.xml | 921 ++++++++++++++++++ .../tests/t0-sample-port-config-tiny.ini | 2 + src/sonic-config-engine/tests/test_j2files.py | 37 + 21 files changed, 2152 insertions(+) create mode 100644 src/sonic-config-engine/tests/sample-port-data.json create mode 100644 src/sonic-config-engine/tests/sample-ztp-inband-ip.json create mode 100644 src/sonic-config-engine/tests/sample-ztp-inband.json create mode 100644 src/sonic-config-engine/tests/sample-ztp-ip.json create mode 100644 src/sonic-config-engine/tests/sample-ztp.json create mode 100644 src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt create mode 100644 src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp create mode 100644 src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband create mode 100644 src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip create mode 100644 src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip create mode 100644 src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt create mode 100644 src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt create mode 100644 src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp create mode 100644 src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband create mode 100644 src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip create mode 100644 src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip create mode 100644 src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt create mode 100644 src/sonic-config-engine/tests/t0-sample-graph-mvrf-nomgmt.xml create mode 100644 src/sonic-config-engine/tests/t0-sample-graph-nomgmt.xml create mode 100644 src/sonic-config-engine/tests/t0-sample-port-config-tiny.ini diff --git a/src/sonic-config-engine/tests/sample-port-data.json b/src/sonic-config-engine/tests/sample-port-data.json new file mode 100644 index 0000000000..f206b18270 --- /dev/null +++ b/src/sonic-config-engine/tests/sample-port-data.json @@ -0,0 +1,9 @@ +{ + "PORT_DATA": { + "PORT_TABLE:Ethernet0": { + "value": { + "oper_status": "up" + } + } + } +} diff --git a/src/sonic-config-engine/tests/sample-ztp-inband-ip.json b/src/sonic-config-engine/tests/sample-ztp-inband-ip.json new file mode 100644 index 0000000000..8e05abbfb8 --- /dev/null +++ b/src/sonic-config-engine/tests/sample-ztp-inband-ip.json @@ -0,0 +1,10 @@ +{ + "ZTP": { + "mode": { + "profile": "active", + "inband": "true", + "ipv4": "true", + "ipv6": "true" + } + } +} diff --git a/src/sonic-config-engine/tests/sample-ztp-inband.json b/src/sonic-config-engine/tests/sample-ztp-inband.json new file mode 100644 index 0000000000..dd80b76111 --- /dev/null +++ b/src/sonic-config-engine/tests/sample-ztp-inband.json @@ -0,0 +1,8 @@ +{ + "ZTP": { + "mode": { + "profile": "active", + "inband": "true" + } + } +} diff --git a/src/sonic-config-engine/tests/sample-ztp-ip.json b/src/sonic-config-engine/tests/sample-ztp-ip.json new file mode 100644 index 0000000000..ff04047f7d --- /dev/null +++ b/src/sonic-config-engine/tests/sample-ztp-ip.json @@ -0,0 +1,9 @@ +{ + "ZTP": { + "mode": { + "profile": "active", + "ipv4": "true", + "ipv6": "true" + } + } +} diff --git a/src/sonic-config-engine/tests/sample-ztp.json b/src/sonic-config-engine/tests/sample-ztp.json new file mode 100644 index 0000000000..5438a96385 --- /dev/null +++ b/src/sonic-config-engine/tests/sample-ztp.json @@ -0,0 +1,7 @@ +{ + "ZTP": { + "mode": { + "profile": "active" + } + } +} diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt new file mode 100644 index 0000000000..b2d854266c --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt @@ -0,0 +1,24 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 +iface eth0 inet dhcp + metric 202 +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp new file mode 100644 index 0000000000..2080d7dfcd --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp @@ -0,0 +1,25 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 + + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband new file mode 100644 index 0000000000..85d476a910 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband @@ -0,0 +1,29 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 + + +# ZTP in-band interface Ethernet0 +auto Ethernet0 +allow-hotplug Ethernet0 + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip new file mode 100644 index 0000000000..9e62929b5a --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip @@ -0,0 +1,35 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 +iface eth0 inet dhcp +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 + + +# ZTP in-band interface Ethernet0 +auto Ethernet0 +allow-hotplug Ethernet0 +iface Ethernet0 inet dhcp +iface Ethernet0 inet6 dhcp + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip new file mode 100644 index 0000000000..9ddde6b5e8 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip @@ -0,0 +1,29 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 +iface eth0 inet dhcp +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 + + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt new file mode 100644 index 0000000000..a110a91980 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt @@ -0,0 +1,34 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +auto mgmt +iface mgmt + vrf-table 5000 +# The loopback network interface for mgmt VRF that is required for applications like NTP + up ip link add lo-m type dummy + up ip link set dev lo-m master mgmt + up ip addr add 127.0.0.1/16 dev lo-m + up ip link set lo-m up + down ip link delete dev lo-m +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 +iface eth0 inet dhcp + metric 202 + vrf mgmt +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt new file mode 100644 index 0000000000..b2d854266c --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt @@ -0,0 +1,24 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 +iface eth0 inet dhcp + metric 202 +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp new file mode 100644 index 0000000000..2080d7dfcd --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp @@ -0,0 +1,25 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 + + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband new file mode 100644 index 0000000000..85d476a910 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband @@ -0,0 +1,29 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 + + +# ZTP in-band interface Ethernet0 +auto Ethernet0 +allow-hotplug Ethernet0 + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip new file mode 100644 index 0000000000..9e62929b5a --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip @@ -0,0 +1,35 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 +iface eth0 inet dhcp +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 + + +# ZTP in-band interface Ethernet0 +auto Ethernet0 +allow-hotplug Ethernet0 +iface Ethernet0 inet dhcp +iface Ethernet0 inet6 dhcp + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip new file mode 100644 index 0000000000..9ddde6b5e8 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip @@ -0,0 +1,29 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 + + +# ZTP out-of-band interface +allow-hotplug eth0 +iface eth0 inet dhcp +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 + + +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt new file mode 100644 index 0000000000..a110a91980 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt @@ -0,0 +1,34 @@ +# +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +auto mgmt +iface mgmt + vrf-table 5000 +# The loopback network interface for mgmt VRF that is required for applications like NTP + up ip link add lo-m type dummy + up ip link set dev lo-m master mgmt + up ip addr add 127.0.0.1/16 dev lo-m + up ip link set lo-m up + down ip link delete dev lo-m +# The loopback network interface +auto lo +iface lo inet loopback + address 127.0.0.1 + netmask 255.255.0.0 + scope host + post-up ip addr del 127.0.0.1/8 dev lo + +# The management network interface +auto eth0 +iface eth0 inet dhcp + metric 202 + vrf mgmt +iface eth0 inet6 dhcp + up sysctl net.ipv6.conf.eth0.accept_ra=1 + down sysctl net.ipv6.conf.eth0.accept_ra=0 +# +source /etc/network/interfaces.d/* +# + diff --git a/src/sonic-config-engine/tests/t0-sample-graph-mvrf-nomgmt.xml b/src/sonic-config-engine/tests/t0-sample-graph-mvrf-nomgmt.xml new file mode 100644 index 0000000000..3bd4827ac0 --- /dev/null +++ b/src/sonic-config-engine/tests/t0-sample-graph-mvrf-nomgmt.xml @@ -0,0 +1,797 @@ + + + + + + false + switch-t0 + 10.0.0.56 + ARISTA01T1 + 10.0.0.57 + 1 + 180 + 60 + + + switch-t0 + FC00::71 + ARISTA01T1 + FC00::72 + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.58 + ARISTA02T1 + 10.0.0.59 + 1 + 180 + 60 + + + switch-t0 + FC00::75 + ARISTA02T1 + FC00::76 + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.60 + ARISTA03T1 + 10.0.0.61 + 1 + 180 + 60 + + + switch-t0 + FC00::79 + ARISTA03T1 + FC00::7A + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.62 + ARISTA04T1 + 10.0.0.63 + 1 + 180 + 60 + + + switch-t0 + FC00::7D + ARISTA04T1 + FC00::7E + 1 + 180 + 60 + + + + + 65100 + switch-t0 + + +
10.0.0.57
+ + + +
+ +
10.0.0.59
+ + + +
+ +
10.0.0.61
+ + + +
+ +
10.0.0.63
+ + + +
+
+ +
+ + 64600 + ARISTA01T1 + + + + 64600 + ARISTA02T1 + + + + 64600 + ARISTA03T1 + + + + 64600 + ARISTA04T1 + + +
+
+ + + + + + HostIP + Loopback0 + + 10.1.0.32/32 + + 10.1.0.32/32 + + + HostIP1 + Loopback0 + + FC00:1::32/128 + + FC00:1::32/128 + + + LoopbackIP1 + Loopback1 + + 10.10.0.99/32 + + 10.10.0.99/32 + + + + + true + + + + + + + + switch-t0 + + + PortChannel01 + fortyGigE0/112 + + + + PortChannel02 + fortyGigE0/116 + + + + PortChannel03 + fortyGigE0/120 + + + + PortChannel04 + fortyGigE0/124 + + + + + + Vlan1000 + fortyGigE0/4;fortyGigE0/8;fortyGigE0/12;fortyGigE0/16;fortyGigE0/20;fortyGigE0/24;fortyGigE0/28;fortyGigE0/32;fortyGigE0/36;fortyGigE0/40;fortyGigE0/44;fortyGigE0/48;fortyGigE0/52;fortyGigE0/56;fortyGigE0/60;fortyGigE0/64;fortyGigE0/68;fortyGigE0/72;fortyGigE0/76;fortyGigE0/80;fortyGigE0/84;fortyGigE0/88;fortyGigE0/92;fortyGigE0/96 + False + 0.0.0.0/0 + + 192.0.0.1;192.0.0.2 + 1000 + 1000 + 192.168.0.0/27 + + + + + + PortChannel01 + 10.0.0.56/31 + + + + PortChannel01 + FC00::71/126 + + + + PortChannel02 + 10.0.0.58/31 + + + + PortChannel02 + FC00::75/126 + + + + PortChannel03 + 10.0.0.60/31 + + + + PortChannel03 + FC00::79/126 + + + + PortChannel04 + 10.0.0.62/31 + + + + PortChannel04 + FC00::7D/126 + + + + Vlan1000 + 192.168.0.1/27 + + + + + + ERSPAN + everflow + Everflow + + + ERSPANv6 + everflowV6 + Everflow + + + PortChannel01;PortChannel02;PortChannel03;PortChannel04 + DataAcl + DataPlane + + + SNMP + SNMP_ACL + SNMP + + + NTP + NTP_ACL + NTP + + + SSH + SSH_ACL + SSH + + + SSH + ROUTER-PROTECT + SSH + + + SNMP + ROUTER-PROTECT + SNMP + + + NTP + NTP_ACL + + + + + + + + + + DeviceInterfaceLink + ARISTA01T1 + Ethernet1/1 + switch-t0 + fortyGigE0/112 + + + DeviceInterfaceLink + ARISTA02T1 + Ethernet1/1 + switch-t0 + fortyGigE0/116 + + + DeviceInterfaceLink + ARISTA03T1 + Ethernet1/1 + switch-t0 + fortyGigE0/120 + + + DeviceInterfaceLink + ARISTA04T1 + Ethernet1/1 + switch-t0 + fortyGigE0/124 + + + DeviceInterfaceLink + 10000 + switch-t0 + fortyGigE0/2 + true + ARISTA05T1 + Ethernet1/33 + true + + + + + switch-t0 + Force10-S6000 + + + ARISTA01T1 + Arista + + + ARISTA02T1 + Arista + + + ARISTA03T1 + Arista + + + ARISTA04T1 + Arista + + + + + + + + DeviceInterface + + true + 1 + Ethernet0 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet4 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet8 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet12 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet16 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet20 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet24 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet28 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet32 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet36 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet40 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet44 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet48 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet52 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet56 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet60 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet64 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet68 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet72 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet76 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet80 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet84 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet88 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet92 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet96 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet100 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet104 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet108 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet112 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet116 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet120 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet124 + + false + 0 + 0 + 40000 + + + Force10-S6000 + + + + + + + switch-t0 + + + ErspanDestinationIpv4 + + 2.2.2.2 + + + + + + + + + + + + + AutoNegotiation + + True + + + ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/2 + + + + switch-t0 + Force10-S6000 +
diff --git a/src/sonic-config-engine/tests/t0-sample-graph-nomgmt.xml b/src/sonic-config-engine/tests/t0-sample-graph-nomgmt.xml new file mode 100644 index 0000000000..e584671315 --- /dev/null +++ b/src/sonic-config-engine/tests/t0-sample-graph-nomgmt.xml @@ -0,0 +1,921 @@ + + + + + + switch-t0 + 10.1.0.32 + BGPMonitor + 10.20.30.40 + 30 + 10 + 3 + + + false + switch-t0 + 10.0.0.56 + ARISTA01T1 + 10.0.0.57 + 1 + 180 + 60 + + + switch-t0 + FC00::71 + ARISTA01T1 + FC00::72 + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.58 + ARISTA02T1 + 10.0.0.59 + 1 + 180 + 60 + + + switch-t0 + FC00::75 + ARISTA02T1 + FC00::76 + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.60 + ARISTA03T1 + 10.0.0.61 + 1 + 180 + 60 + + + switch-t0 + FC00::79 + ARISTA03T1 + FC00::7A + 1 + 180 + 60 + + + false + switch-t0 + 10.0.0.62 + ARISTA04T1 + 10.0.0.63 + 1 + 180 + 60 + + + switch-t0 + FC00::7D + ARISTA04T1 + FC00::7E + 1 + 180 + 60 + + + + + 1 + + BGPMonitor + + + BGPPeer +
10.1.0.32
+ + + +
+
+ +
+ + 65100 + switch-t0 + + +
10.0.0.57
+ + + +
+ +
10.0.0.59
+ + + +
+ +
10.0.0.61
+ + + +
+ +
10.0.0.63
+ + + +
+
+ +
+ + 64600 + ARISTA01T1 + + + + 64600 + ARISTA02T1 + + + + 64600 + ARISTA03T1 + + + + 64600 + ARISTA04T1 + + +
+
+ + + + + + HostIP + Loopback0 + + 10.1.0.32/32 + + 10.1.0.32/32 + + + HostIP1 + Loopback0 + + FC00:1::32/128 + + FC00:1::32/128 + + + LoopbackIP1 + Loopback1 + + 10.10.0.99/32 + + 10.10.0.99/32 + + + LoopbackIP2 + Loopback2 + + 10.21.0.64/32 + + 10.21.0.64/32 + + + LoopbackIP3 + Loopback3 + + 10.21.64.2/32 + + 10.21.64.2/32 + + + + + + + + switch-t0 + + + PortChannel01 + fortyGigE0/112 + + + + PortChannel02 + fortyGigE0/116 + + + + PortChannel03 + fortyGigE0/120 + + + + PortChannel04 + fortyGigE0/124 + + + + + + Vlan1000 + fortyGigE0/4;fortyGigE0/8;fortyGigE0/12;fortyGigE0/16;fortyGigE0/20;fortyGigE0/24;fortyGigE0/28;fortyGigE0/32;fortyGigE0/36;fortyGigE0/40;fortyGigE0/44;fortyGigE0/48;fortyGigE0/52;fortyGigE0/56;fortyGigE0/60;fortyGigE0/64;fortyGigE0/68;fortyGigE0/72;fortyGigE0/76;fortyGigE0/80;fortyGigE0/84;fortyGigE0/88;fortyGigE0/92;fortyGigE0/96 + False + 0.0.0.0/0 + + + 192.0.0.1;192.0.0.2 + fc02:2000::1;fc02:2000::2 + 1000 + 1000 + 192.168.0.0/27 + + + + + Vlan2000 + fortyGigE0/112;fortyGigE0/116;fortyGigE0/120 + False + 0.0.0.0/0 + + + 192.0.0.3;192.0.0.4 + fc02:2000::3;fc02:2000::4 + 2000 + 2000 + 192.168.200.0/27 + + + + + Vlan99 + fortyGigE0/100 + False + 0.0.0.0/0 + + UserDefinedL2Vlan + 192.0.0.1;192.0.0.2 + 99 + 99 + + + + + + Vlan98 + fortyGigE0/100;PortChannel01;PortChannel03 + False + 0.0.0.0/0 + + UserDefinedL2Vlan + 192.0.0.1;192.0.0.2 + 98 + 98 + + + + + + + + + PortChannel01 + 10.0.0.56/31 + + + + PortChannel01 + FC00::71/126 + + + + PortChannel02 + 10.0.0.58/31 + + + + PortChannel02 + FC00::75/126 + + + + PortChannel03 + 10.0.0.60/31 + + + + PortChannel03 + FC00::79/126 + + + + PortChannel04 + 10.0.0.62/31 + + + + PortChannel04 + FC00::7D/126 + + + + Vlan1000 + 192.168.0.1/27 + + + + Vlan2000 + 192.168.200.1/27 + + + + + + ERSPAN + everflow + Everflow + + + ERSPANv6 + everflowV6 + Everflow + + + EGRESS_ERSPAN + everflow_egress + Everflow + + + PortChannel01;PortChannel02;PortChannel03;PortChannel04 + DataAclIngress + DataPlane + + + PortChannel01;PortChannel02;Vlan98 + DataAclEgress + DataPlane + + + SNMP + SNMP_ACL + SNMP + + + NTP + NTP_ACL + NTP + + + SSH + SSH_ACL + SSH + + + SSH + ROUTER-PROTECT + SSH + + + SNMP + ROUTER-PROTECT + SNMP + + + NTP + NTP_ACL + + + + + + + + + + DeviceInterfaceLink + ARISTA01T1 + Ethernet1/1 + switch-t0 + fortyGigE0/112 + + + DeviceInterfaceLink + ARISTA02T1 + Ethernet1/1 + switch-t0 + fortyGigE0/116 + + + DeviceInterfaceLink + ARISTA03T1 + Ethernet1/1 + switch-t0 + fortyGigE0/120 + + + DeviceInterfaceLink + ARISTA04T1 + Ethernet1/1 + switch-t0 + fortyGigE0/124 + 100000 + + + DeviceInterfaceLink + 100000 + switch-t0 + fortyGigE0/4 + true + ARISTA05T1 + Ethernet1/33 + true + + + DeviceInterfaceLink + Servers0 + eth0 + switch-t0 + fortyGigE0/4 + + + DeviceInterfaceLink + Servers100 + eth0 + switch-t0 + fortyGigE0/100 + + + + + switch-t0 + Force10-S6000 + + + ARISTA01T1 + Arista + + + ARISTA02T1 + Arista + + + ARISTA03T1 + Arista + + + ARISTA04T1 + Arista + + + + + + + + DeviceInterface + + true + 1 + Ethernet0 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet8 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet12 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet16 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet20 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet24 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet28 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet32 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet36 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet40 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet44 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet48 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet52 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet56 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet60 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet64 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet68 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet72 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet76 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet80 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet84 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet88 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet92 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet96 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet100 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet104 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet108 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet112 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet116 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + 1 + Ethernet120 + + false + 0 + 0 + 40000 + + + Force10-S6000 + + + + + + + switch-t0 + + + ErspanDestinationIpv4 + + 2.2.2.2 + + + + + + + + + + + + + AutoNegotiation + + True + + + FECDisabled + + True + + + ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/4 + + + + + + AutoNegotiation + + False + + + FECDisabled + + True + + + ARISTA06T1:Ethernet1/34;switch-t0:fortyGigE0/8 + + + + + + + switch-t0 + + + DeploymentId + + 1 + + + + + + + switch-t0 + Force10-S6000 +
diff --git a/src/sonic-config-engine/tests/t0-sample-port-config-tiny.ini b/src/sonic-config-engine/tests/t0-sample-port-config-tiny.ini new file mode 100644 index 0000000000..fe6f8afc90 --- /dev/null +++ b/src/sonic-config-engine/tests/t0-sample-port-config-tiny.ini @@ -0,0 +1,2 @@ +# name lanes alias +Ethernet0 29,30,31,32 fortyGigE0/0 diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index a82e108f68..b93d26ef36 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -12,10 +12,18 @@ class TestJ2Files(TestCase): self.test_dir = os.path.dirname(os.path.realpath(__file__)) self.script_file = utils.PYTHON_INTERPRETTER + ' ' + os.path.join(self.test_dir, '..', 'sonic-cfggen') self.simple_minigraph = os.path.join(self.test_dir, 'simple-sample-graph.xml') + self.port_data = os.path.join(self.test_dir, 'sample-port-data.json') + self.ztp = os.path.join(self.test_dir, "sample-ztp.json") + self.ztp_inband = os.path.join(self.test_dir, "sample-ztp-inband.json") + self.ztp_ip = os.path.join(self.test_dir, "sample-ztp-ip.json") + self.ztp_inband_ip = os.path.join(self.test_dir, "sample-ztp-inband-ip.json") self.t0_minigraph = os.path.join(self.test_dir, 't0-sample-graph.xml') self.t0_mvrf_minigraph = os.path.join(self.test_dir, 't0-sample-graph-mvrf.xml') + self.t0_minigraph_nomgmt = os.path.join(self.test_dir, 't0-sample-graph-nomgmt.xml') + self.t0_mvrf_minigraph_nomgmt = os.path.join(self.test_dir, 't0-sample-graph-mvrf-nomgmt.xml') self.pc_minigraph = os.path.join(self.test_dir, 'pc-test-graph.xml') self.t0_port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini') + self.t0_port_config_tiny = os.path.join(self.test_dir, 't0-sample-port-config-tiny.ini') self.l1_l3_port_config = os.path.join(self.test_dir, 'l1-l3-sample-port-config.ini') self.t0_7050cx3_port_config = os.path.join(self.test_dir, 't0_7050cx3_d48c8_port_config.ini') self.t1_mlnx_minigraph = os.path.join(self.test_dir, 't1-sample-graph-mlnx.xml') @@ -84,6 +92,25 @@ class TestJ2Files(TestCase): def test_interfaces(self): interfaces_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'interfaces', 'interfaces.j2') + + # ZTP enabled + argument = '-m ' + self.t0_minigraph_nomgmt + ' -p ' + self.t0_port_config_tiny + ' -j ' + self.ztp + ' -j ' + self.port_data + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + '> ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces_nomgmt_ztp'), self.output_file)) + + argument = '-m ' + self.t0_minigraph_nomgmt + ' -p ' + self.t0_port_config_tiny + ' -j ' + self.ztp_inband + ' -j ' + self.port_data + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + '> ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces_nomgmt_ztp_inband'), self.output_file)) + + argument = '-m ' + self.t0_minigraph_nomgmt + ' -p ' + self.t0_port_config_tiny + ' -j ' + self.ztp_ip + ' -j ' + self.port_data + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + '> ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces_nomgmt_ztp_ip'), self.output_file)) + + argument = '-m ' + self.t0_minigraph_nomgmt + ' -p ' + self.t0_port_config_tiny + ' -j ' + self.ztp_inband_ip + ' -j ' + self.port_data + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + '> ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces_nomgmt_ztp_inband_ip'), self.output_file)) + + # ZTP disabled, MGMT_INTERFACE defined argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + ' > ' + self.output_file self.run_script(argument) self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces'), self.output_file)) @@ -92,6 +119,16 @@ class TestJ2Files(TestCase): self.run_script(argument) self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'mvrf_interfaces'), self.output_file)) + # ZTP disabled, no MGMT_INTERFACE defined + argument = '-m ' + self.t0_minigraph_nomgmt + ' -p ' + self.t0_port_config + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + ' > ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'interfaces_nomgmt'), self.output_file)) + + argument = '-m ' + self.t0_mvrf_minigraph_nomgmt + ' -p ' + self.t0_port_config + ' -a \'{\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + interfaces_template + ' > ' + self.output_file + self.run_script(argument) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'mvrf_interfaces_nomgmt'), self.output_file)) + + def test_ports_json(self): ports_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'ports.json.j2') argument = '-m ' + self.simple_minigraph + ' -p ' + self.t0_port_config + ' -t ' + ports_template + ' > ' + self.output_file