[Enterprise SONiC] ZTP (Zero Touch Provisioning) Follow
Zero Touch Provisioning (ZTP) service can be used by users to configure a fleet of switches using common configuration templates. Switches booting from factory default state should be able to communicate with remote provisioning server and download relevant configuration files and scripts to kick start more complex configuration steps. ZTP service takes user input in JSON format.
- Using ZTP to download the config_db.json.
- Using ZTP to download the config_db.json and the new SONiC version.
- Using ZTP to download the config_db.json and test the connectivity-check.
- ZTP configuration provision via USB drive
- Frequently Asked Question
Tested model & firmware version:
- Switch model name:
DCS203(AS7326-56X)
- Edgecore SONiC version:
202012.3 ~ 4
202111.0 ~ 202111.8
Restriction
- ZTP only could work on the management port.
- ZTP only could be triggered when there's no "config_db.json" in /etc/sonic.
- [202012.4]Known issue:
- [ SONIC-4610] Management VRF fails to activate while ZTP is running
- [202111.0] Know issue:
- [SONIC-5329] : [ZTP][ec202111] admin failed to login after ZTP installing image by firmware plugin
- [202111.3] Know issue:
- [SONIC-6746] : [ZTP][ec202111] ZTP download the config_db.json will not reload automatically
Using ZTP to download the config_db.json.
Topology
Pre-configuration:
-
DHCP Server:
ts@ts-server-up:~$ sudo cat /etc/dhcp/dhcpd.conf
subnet 188.188.0.0 netmask 255.255.0.0 {
range 188.188.36.21 188.188.36.30;
option tftp-server-name "188.188.36.36";
option routers 188.188.1.1;
option bootfile-name "ztp.json";
default-lease-time 300;
max-lease-time 600;
} - Prepare the essential files and put them in TFTP Server.
-
ztp.json
Note: "ztp.json" name must match the bootfile-name which is in the DHCP Server configuration.
Example for ztp.json{
"ztp": {
"01-configdb-json": {
"url": {
"source": "tftp://188.188.36.36/7326_56X_config_db.json",
"destination": "/etc/sonic/config_db.json"
}
}
}
} - 7326_56X_config_db.json
Note: "7326_56X_config_db.json" will upload to the switch and it will be the switch's config_db.json
-
Procedure:
Step 1: Make sure there's no config_db.json in /etc/sonic
admin@sonic:/etc/sonic$ ls | grep config_db.json
admin@sonic:/etc/sonic$
Step 2: enable the ZTP service.
admin@sonic:~$ sudo config ztp enable
Step 3: Running the ZTP service
admin@sonic:~$ sudo config ztp run -y
Result:
admin@sonic:~$ Sep 7 17:50:40.887369 sonic INFO sonic-ztp[8921]: Installing ZTP configuration profile to initiate ZTP discovery.
Sep 7 17:50:42.714004 sonic INFO sonic-ztp[8921]: Executing stop of service mgmt-framework...
Sep 7 17:50:45.134200 sonic INFO sonic-ztp[8921]: Executing stop of service telemetry...
Sep 7 17:50:47.217116 sonic INFO sonic-ztp[8921]: Executing stop of service swss...
...
omitted
...
Sep 7 17:52:43.314322 sonic INFO sonic-ztp[8921]: Waiting for system online status before continuing ZTP. (This may take 30--120 seconds).
Sep 7 17:52:57.171491 sonic INFO sonic-ztp[8921]: System is ready to respond.
Sep 7 17:52:57.405111 sonic INFO sonic-ztp[8922]: Link up detected for interface eth0
Sep 7 17:52:57.405455 sonic INFO sonic-ztp[8922]: Restarting network discovery after link scan.
Sep 7 17:53:02.502494 sonic INFO sonic-ztp[8922]: Restarted network discovery after link scan.
Sep 7 17:53:12.583293 sonic INFO sonic-ztp[8922]: Downloading provisioning data from tftp://188.188.36.36/ztp.json to /var/run/ztp/ztp_data_opt67.json
Sep 7 17:53:12.793189 sonic INFO sonic-ztp[8922]: Starting ZTP using JSON file /var/run/ztp/ztp_data_opt67.json at 2019-09-07 17:53:12 UTC.
Sep 7 17:53:12.794183 sonic INFO sonic-ztp[8922]: Processing configuration section 01-configdb-json at 2019-09-07 17:53:12 UTC.
Sep 7 17:53:13.392886 sonic INFO sonic-ztp[16981]: configdb-json: Downloading config_db.json file from 'tftp://188.188.36.36/7326_56X_config_db.json'.
Sep 7 17:53:13.606164 sonic INFO sonic-ztp[16981]: configdb-json: Configuration change detected. Removing ZTP configuation from Config DB.
Sep 7 17:53:13.732840 sonic INFO sonic-ztp[8921]: 1
Sep 7 17:53:13.774375 sonic INFO sonic-ztp[16981]: configdb-json: Stopping ZTP discovery on interfaces.
Sep 7 17:53:18.609174 sonic INFO sonic-ztp[16981]: configdb-json: Reloading config_db.json to Config DB.
Sep 7 17:53:18.972663 sonic INFO sonic-ztp[8921]: Executing stop of service mgmt-framework...
Sep 7 17:53:21.319553 sonic INFO sonic-ztp[8921]: Executing stop of service telemetry...
Sep 7 17:53:23.500125 sonic INFO sonic-ztp[8921]: Executing stop of service swss...
...
omitted
...
Sep 7 17:55:19.631655 sonic INFO sonic-ztp[8922]: Processed Configuration section 01-configdb-json with result SUCCESS, exit code (0) at 2019-09-07 17:53:12 UTC.
Sep 7 17:55:19.632394 sonic INFO sonic-ztp[8922]: Checking configuration section 01-configdb-json result: SUCCESS, ignore-result: False.
Sep 7 17:55:19.633525 sonic INFO sonic-ztp[8922]: ZTP successfully completed at 2019-09-07 17:55:19 UTC.
Check the ZTP status
admin@sonic:~$ show ztp status
ZTP Admin Mode : True
ZTP Service : Inactive
ZTP Status : SUCCESS
ZTP Source : dhcp-opt67 (eth0)
Runtime : 04m 40s
Timestamp : 2019-09-07 17:55:19 UTC
ZTP Service is not running
01-configdb-json: SUCCESS
Check the /etc/sonic.
admin@sonic:~$ ls /etc/sonic/ | grep config_db.json
config_db.json
Using ZTP to download the config_db.json and the new SONiC version.
Topology
Pre-configuration:
- DHCP Server. (please refer to the "Using ZTP to download the config_db.json".)
- Prepare the essential file and put them in TFTP Server and HTTP Server.
-
ztp.json
Example for ztp.json.{
"ztp": {
"01-configdb-json": {
"url": {
"source": "tftp://188.188.36.36/7326_56X_config_db.json",
"destination": "/etc/sonic/config_db.json"
}
},
"02-firmware": {
"install": {
"url": "http://188.188.36.36:8000/sonic-broadcom.bin",
"skip-reboot": true
}
}
}
}Note:
"skip-reboot": Specifies if a switch reboot operation is performed immediately after installing a new switch firmware image.
"7326_56X_config_db.json" put in the TFTP Server.
"sonic-broadcom.bin" put in the HTTP server.
-
Procedure:
Step 1: Make sure there's no config_db.json in /etc/sonic
admin@sonic:/etc/sonic$ ls | grep config_db.json
admin@sonic:/etc/sonic$
Step 2: Make sure if there is space to upload the SONiC image or not.
admin@sonic:~$ sudo sonic_installer list
Warning: 'sonic_installer' command is deprecated and will be removed in the future
Please use 'sonic-installer' instead
Current: SONiC-OS-Edgecore-SONiC_20220623_052151_ec202012_362
Next: SONiC-OS-Edgecore-SONiC_20220623_052151_ec202012_362
Available:
SONiC-OS-Edgecore-SONiC_20220623_052151_ec202012_362
Note: SONiC could only have two images. If there are two images, please remove one of the images. (About removed images, please refer to this article.)
Step 3: enable the ZTP service.
admin@sonic:~$ sudo config ztp enable
Step 4: Running the ZTP service
admin@sonic:~$ sudo config ztp run -y
Result:
admin@sonic:~$ Sep 7 18:34:49.892401 sonic INFO sonic-ztp[11865]: Installing ZTP configuration profile to initiate ZTP discovery.
Sep 7 18:34:51.711815 sonic INFO sonic-ztp[11865]: Executing stop of service mgmt-framework...
Sep 7 18:34:53.432000 sonic INFO sonic-ztp[11865]: Executing stop of service telemetry...
Sep 7 18:34:55.647147 sonic INFO sonic-ztp[11865]: Executing stop of service swss...
...
omitted
...
Sep 7 18:36:51.364468 sonic INFO sonic-ztp[11865]: Waiting for system online status before continuing ZTP. (This may take 30--120 seconds).
Sep 7 18:37:05.000641 sonic INFO sonic-ztp[11865]: System is ready to respond.
Sep 7 18:37:05.237949 sonic INFO sonic-ztp[11868]: Link up detected for interface eth0
Sep 7 18:37:05.238403 sonic INFO sonic-ztp[11868]: Restarting network discovery after link scan.
Sep 7 18:37:10.366858 sonic INFO sonic-ztp[11868]: Restarted network discovery after link scan.
Sep 7 18:37:20.464056 sonic INFO sonic-ztp[11868]: Downloading provisioning data from tftp://188.188.36.36/ztp.json to /var/run/ztp/ztp_data_opt67.json
Sep 7 18:37:21.722754 sonic INFO sonic-ztp[11868]: Starting ZTP using JSON file /var/run/ztp/ztp_data_opt67.json at 2019-09-07 18:37:21 UTC.
Sep 7 18:37:21.723886 sonic INFO sonic-ztp[11868]: Processing configuration section 01-configdb-json at 2019-09-07 18:37:21 UTC.
Sep 7 18:37:22.330495 sonic INFO sonic-ztp[19957]: configdb-json: Downloading config_db.json file from 'tftp://188.188.36.36/7326_56X_config_db.json'.
Sep 7 18:37:22.540962 sonic INFO sonic-ztp[19957]: configdb-json: Configuration change detected. Removing ZTP configuation from Config DB.
Sep 7 18:37:22.656274 sonic INFO sonic-ztp[11865]: 1
Sep 7 18:37:22.692543 sonic INFO sonic-ztp[19957]: configdb-json: Stopping ZTP discovery on interfaces.
Sep 7 18:37:27.522254 sonic INFO sonic-ztp[19957]: configdb-json: Reloading config_db.json to Config DB.
Sep 7 18:37:27.852614 sonic INFO sonic-ztp[11865]: Executing stop of service mgmt-framework...
Sep 7 18:37:29.977310 sonic INFO sonic-ztp[11865]: Executing stop of service telemetry...
Sep 7 18:37:32.388821 sonic INFO sonic-ztp[11865]: Executing stop of service swss...
...
omitted
...
Sep 7 18:39:28.248780 sonic INFO sonic-ztp[11868]: Processed Configuration section 01-configdb-json with result SUCCESS, exit code (0) at 2019-09-07 18:37:21 UTC.
Sep 7 18:39:28.250975 sonic INFO sonic-ztp[11868]: Processing configuration section 02-firmware at 2019-09-07 18:39:28 UTC.
Sep 7 18:39:30.229524 sonic INFO sonic-ztp[26198]: firmware: Downloading file 'http://188.188.36.36:8000/sonic-broadcom.bin'.
Sep 7 18:40:03.053057 sonic INFO sonic-ztp[26198]: firmware: Installing firmware image located at '/var/lib/ztp/tmp/sonic-broadcom.bin'.
[ 561.792993] sonic-ztp[11865]: Installing image SONiC-OS-Edgecore-SONiC_20220218_065711_ec202012_279 and setting it as default...
Sep 7 18:40:17.058669 sonic INFO sonic-ztp[11865]: Installing image SONiC-OS-Edgecore-SONiC_20220218_065711_ec202012_279 and setting it as default...
Sep 7 18:40:17.061644 sonic INFO sonic-ztp[11865]: Command: bash /var/lib/ztp/tmp/sonic-broadcom.bin
...
omitted
...
Sep 7 18:41:04.653599 sonic INFO sonic-ztp[11865]: Done
Sep 7 18:41:04.871445 sonic INFO sonic-ztp[26198]: firmware: Version SONiC-OS-Edgecore-SONiC_20220218_065711_ec202012_279 successfully installed.
Sep 7 18:41:05.058964 sonic INFO sonic-ztp[26198]: firmware: Post image installation device reboot.
Sep 7 18:41:05.059381 sonic INFO sonic-ztp[26198]: firmware: Skipped switch reboot as requested.
Sep 7 18:41:05.067220 sonic INFO sonic-ztp[11868]: Processed Configuration section 02-firmware with result SUCCESS, exit code (0) at 2019-09-07 18:39:28 UTC.
Sep 7 18:41:05.068893 sonic INFO sonic-ztp[11868]: Checking configuration section 01-configdb-json result: SUCCESS, ignore-result: False.
Sep 7 18:41:05.069259 sonic INFO sonic-ztp[11868]: Checking configuration section 02-firmware result: SUCCESS, ignore-result: False.
Sep 7 18:41:05.072068 sonic INFO sonic-ztp[11868]: ZTP successfully completed at 2019-09-07 18:41:05 UTC.
Check the ZTP status
admin@sonic:~$ show ztp status
ZTP Admin Mode : True
ZTP Service : Inactive
ZTP Status : SUCCESS
ZTP Source : dhcp-opt67 (eth0)
Runtime : 06m 17s
Timestamp : 2019-09-07 18:41:05 UTC
ZTP Service is not running
01-configdb-json: SUCCESS
02-firmware: SUCCESS
Check the /etc/sonic.
admin@sonic:~$ ls /etc/sonic/ | grep config_db.json
config_db.json
Check the image list.
admin@sonic:~$ sudo sonic_installer list
Warning: 'sonic_installer' command is deprecated and will be removed in the future
Please use 'sonic-installer' instead
Current: SONiC-OS-Edgecore-SONiC_20220623_052151_ec202012_362
Next: SONiC-OS-Edgecore-SONiC_20220218_065711_ec202012_279
Available:
SONiC-OS-Edgecore-SONiC_20220218_065711_ec202012_279
SONiC-OS-Edgecore-SONiC_20220623_052151_ec202012_362
Using ZTP to download the config_db.json and test the connectivity-check
Topology:
Pre-configuration:
- DHCP Server. (please refer to the "Using ZTP to download the config_db.json".)
- Prepare the essential file and put them in TFTP Server and HTTP Server.
-
ztp.json
Example for ztp.json.{
"ztp": {
"01-configdb-json": {
"url": {
"source": "tftp://188.188.36.36/7326_56X_config_db.json",
"destination": "/etc/sonic/config_db.json"
},
"clear-config": false
},
"02-connectivity-check": {
"ping-hosts": [ "192.168.1.10", "192.168.2.10"]
}
}
}Note:
"clear-config:" Use this to specify if the existing configuration has to be cleared before loading the download config_db.json file content to the Config DB.
-
Procedure:
Step 1: Make sure there's no config_db.json in /etc/sonic
admin@sonic:/etc/sonic$ ls | grep config_db.json
admin@sonic:/etc/sonic$
Step 2: enable the ZTP service.
admin@sonic:~$ sudo config ztp enable
Step 3: Running the ZTP service
admin@sonic:~$ sudo config ztp run -y
Result:
Oct 11 06:08:43.049557 sonic INFO sonic-ztp[60274]: Downloading provisioning data from tftp://188.188.36.36/ztp.json to /var/run/ztp/ztp_data_opt67.json
Oct 11 06:08:43.329804 sonic INFO sonic-ztp[60274]: Starting ZTP using JSON file /var/run/ztp/ztp_data_opt67.json at 2022-10-11 06:08:43 UTC.
Oct 11 06:08:43.331530 sonic INFO sonic-ztp[60274]: Processing configuration section 01-configdb-json at 2022-10-11 06:08:43 UTC.
Oct 11 06:08:44.239493 sonic INFO sonic-ztp[64035]: configdb-json: Downloading config_db.json file from 'tftp://188.188.36.36/7326_56X_config_db.json'.
Oct 11 06:08:50.502393 sonic INFO sonic-ztp[64035]: configdb-json: Applying config_db.json to Config DB.
Oct 11 06:08:51.079640 sonic INFO sonic-ztp[65900]: Running command: /usr/local/bin/sonic-cfggen -j /tmp/config_dl.json --write-to-db
Oct 11 06:08:51.535689 sonic INFO sonic-ztp[64035]: configdb-json: Configuration change detected. Removing ZTP configuation from Config DB.
Oct 11 06:08:51.535823 sonic INFO sonic-ztp[64035]: configdb-json: Stopping ZTP discovery on interfaces.
Oct 11 06:08:58.018029 sonic INFO sonic-ztp[60274]: Processed Configuration section 01-configdb-json with result SUCCESS, exit code (0) at 2022-10-11 06:08:43 UTC.
Oct 11 06:08:58.024332 sonic INFO sonic-ztp[60274]: Processing configuration section 02-connectivity-check at 2022-10-11 06:08:58 UTC.
Oct 11 06:08:58.712077 sonic INFO sonic-ztp[66655]: connectivity-check: Attempting to connect to IPv4 hosts ['192.168.1.10', '192.168.2.10'].
Oct 11 06:08:58.712209 sonic INFO sonic-ztp[66655]: connectivity-check: Pinging host '192.168.1.10'.
[ 2352.202025] sonic-ztp[66706]: ping: connect: Network is unreachable
Oct 11 06:08:58.714944 sonic INFO sonic-ztp[66706]: ping: connect: Network is unreachable
Oct 11 06:08:58.756668 sonic INFO sonic-ztp[66655]: connectivity-check: Host '192.168.1.10' not reachable.
Oct 11 06:08:58.756979 sonic INFO sonic-ztp[66655]: connectivity-check: Pinging host '192.168.2.10'.
[ 2352.248766] sonic-ztp[66715]: ping: connect: Network is unreachable
Oct 11 06:08:58.761684 sonic INFO sonic-ztp[66715]: ping: connect: Network is unreachable
Oct 11 06:08:58.761828 sonic INFO sonic-ztp[66655]: connectivity-check: Host '192.168.2.10' not reachable.
Oct 11 06:09:03.764672 sonic INFO sonic-ztp[66655]: connectivity-check: Pinging host '192.168.1.10'.
Oct 11 06:09:04.781845 sonic INFO sonic-ztp[67202]: PING 192.168.1.10 (192.168.1.10) 56(84) bytes of data.
Oct 11 06:09:07.808584 sonic INFO sonic-ztp[67202]: --- 192.168.1.10 ping statistics ---
Oct 11 06:09:07.808687 sonic INFO sonic-ztp[67202]: 3 packets transmitted, 2 received, 33.3333% packet loss, time 2014ms
Oct 11 06:09:07.808754 sonic INFO sonic-ztp[67202]: rtt min/avg/max/mdev = 0.883/507.151/1013.420/506.268 ms, pipe 2
Oct 11 06:09:07.809155 sonic INFO sonic-ztp[66655]: connectivity-check: Host '192.168.1.10' not reachable.
Oct 11 06:09:07.809256 sonic INFO sonic-ztp[66655]: connectivity-check: Pinging host '192.168.2.10'.
Oct 11 06:09:07.822322 sonic INFO sonic-ztp[67448]: PING 192.168.2.10 (192.168.2.10) 56(84) bytes of data.
Oct 11 06:09:09.835944 sonic INFO sonic-ztp[67448]: --- 192.168.2.10 ping statistics ---
Oct 11 06:09:09.836090 sonic INFO sonic-ztp[67448]: 3 packets transmitted, 3 received, 0% packet loss, time 2003ms
Oct 11 06:09:09.836174 sonic INFO sonic-ztp[67448]: rtt min/avg/max/mdev = 2.549/11.084/20.498/7.353 ms
Oct 11 06:09:09.836776 sonic INFO sonic-ztp[66655]: connectivity-check: Host '192.168.2.10' not reachable.
Oct 11 06:09:09.836919 sonic INFO sonic-ztp[66655]: connectivity-check: All IPv4 hosts ['192.168.1.10', '192.168.2.10'] reachable
Oct 11 06:09:09.856797 sonic INFO sonic-ztp[60274]: Processed Configuration section 02-connectivity-check with result SUCCESS, exit code (0) at 2022-10-11 06:08:58 UTC.
Oct 11 06:09:09.859021 sonic INFO sonic-ztp[60274]: Checking configuration section 01-configdb-json result: SUCCESS, ignore-result: False.
Oct 11 06:09:09.859173 sonic INFO sonic-ztp[60274]: Checking configuration section 02-connectivity-check result: SUCCESS, ignore-result: False.
Oct 11 06:09:09.861319 sonic INFO sonic-ztp[60274]: ZTP successfully completed at 2022-10-11 06:09:09 UTC.
ZTP configuration provision via USB drive
After version 202111.6, you can use USB to provision ZTP.
Once the USB drive is inserted and detected, the first disk partition of the USB drive will be auto mounted in the path /mnt/usb/ in the switch.
After mounted, it will check if there's ztp.json located in the USB(/mnt/usb/ztp.json). If the file is not found, it will continue with the ZTP DHCP discovery process.
The supported file system includes FAT32, ext2, ext3, ext4. And only the first partition of the USB drive is searched. And Only USB thumb drive is tested, no USB external hard drive.
Example file
ztp.json
{
"ztp": {
"30-configdb-json": {
"url": {
"source": "file:///mnt/usb/config_db.json"
},
"clear-config": false,
"save-config": true
}
}
}
Files in USB
"onie-installer" is the SONiC image, which means you can install SONiC from USB via ONIE within same USB.(refer to [Enterprise SONiC] Installation & Upgrade image)
Result:
[ 28.014646] rc.local[611]: + rm -rf /host/image-Edgecore-SONiC_20231127_051854_ec202111_657/platform/firsttime
[ 28.034630] rc.local[611]: + exit 0
Debian GNU/Linux 11 sonic ttyS0
sonic login: Jun 25 21:47:17.354033 sonic INFO sonic-ztp[2376]: ZTP service started.
Jun 25 21:47:17.358815 sonic INFO sonic-ztp[2376]: Starting ZTP using JSON file /mnt/usb/ztp.json at 2023-06-25 21:47:17 UTC.
Jun 25 21:47:17.358904 sonic INFO sonic-ztp[2376]: Checking running configuration to load ZTP configuration profile.
Jun 25 21:47:18.248390 sonic INFO sonic-ztp[2425]: Waiting for system online status before continuing ZTP. (This may take 30--120 seconds).
Jun 25 21:47:33.357997 sonic INFO sonic-ztp[2425]: System is ready to respond.
Jun 25 21:47:34.382724 sonic INFO sonic-ztp[2425]: Restarting network configuration.
Jun 25 21:47:41.472553 sonic INFO sonic-ztp[2425]: Restarted network configuration.
Jun 25 21:47:41.474877 sonic INFO sonic-ztp[2376]: Processing configuration section 30-configdb-json at 2023-06-25 21:47:41 UTC.
Jun 25 21:47:42.563692 sonic INFO sonic-ztp[5944]: configdb-json: Downloading config_db.json file from 'file:///mnt/usb/config_db.json'.
Jun 25 21:47:42.637724 sonic INFO sonic-ztp[5944]: configdb-json: Applying config_db.json to Config DB.
Jun 25 21:47:42.963234 sonic INFO sonic-ztp[5995]: Running command: /usr/local/bin/sonic-cfggen -j /tmp/config_dl.json --write-to-db
Jun 25 21:47:43.319068 sonic INFO sonic-ztp[5944]: configdb-json: Configuration change detected. Removing ZTP configuation from Config DB.
Jun 25 21:47:43.319248 sonic INFO sonic-ztp[5944]: configdb-json: Stopping ZTP discovery on interfaces.
Jun 25 21:47:54.046854 sonic INFO sonic-ztp[5944]: configdb-json: Saving Config DB contents to startup configuration.
Jun 25 21:47:54.386409 sonic INFO sonic-ztp[6660]: Running command: /usr/local/bin/sonic-cfggen -d --print-data /etc/sonic/config_db.json
Jun 25 21:47:54.747169 sonic INFO sonic-ztp[2376]: Processed Configuration section 30-configdb-json with result SUCCESS, exit code (0) at 2023-06-25 21:47:41 UTC.
Jun 25 21:47:54.749337 sonic INFO sonic-ztp[2376]: Checking configuration section 30-configdb-json result: SUCCESS, ignore-result: False.
Jun 25 21:47:54.751630 sonic INFO sonic-ztp[2376]: ZTP successfully completed at 2023-06-25 21:47:54 UTC.
Frequently Asked Question
How to change the MAC address in config_db.json when downloading config_db.json via ZTP.
Once there are many switches that get the config_db.json via ZTP, there's a problem.
Each switch will have the same MAC address because the mac address in the config_db.json is the same.
So below is the solution to this issue.
Note:
After version 202111, users don't add the script to change the MAC address, this issue only happens before version 202111.
"DEVICE_METADATA": {
"localhost": {
"buffer_model": "traditional",
"default_bgp_status": "up",
"default_pfcwd_status": "disable",
"docker_routing_config_mode": "split",
"frr_mgmt_framework_config": "true",
"hostname": "sonic",
"hwsku": "Accton-AS7326-56X",
"mac": "34:EF:B6:95:20:00",
"platform": "x86_64-accton_as7326_56x-r0",
"type": "LeafRouter"
}
},
Tested model & firmware version:
- Switch model name:
DCS203 (AS7326-56X) - Edgecore SONiC version:
202012.4
Topology
Pre-configuration:
- DHCP Server.
- Prepare the essential file and put them in TFTP Server.
-
ztp.json
Example for ztp.json.
{
"ztp": {
"01-configdb-json": {
"url": {
"source": "tftp://188.188.36.36/7326_56X_config_db.json",
"destination": "/etc/sonic/7326_56X_config_db.json"
}
},
"02-provisioning-script": {
"plugin": {
"url": "tftp://188.188.36.36/chg_mac.sh"
},
"reboot-on-success": true
}
}
}
}
-
- config_db.json (7326_56X_config_db.json)
-
chg_mac.sh (this script is used to change the MAC address)
#!/bin/bash
DUT_MAC=`show platform syseeprom | grep 'Base MAC Address' | awk '{print $6}'`
echo MAC of DUT is $DUT_MAC
jq --arg dut_mac $DUT_MAC '.DEVICE_METADATA.localhost += {"mac": $dut_mac}' /etc/sonic/7326_56X_config_db.json > /etc/sonic/config_db.json
-
Procedure:
Step 1: Make sure there's no config_db.json in /etc/sonic
admin@sonic:/etc/sonic$ ls | grep config_db.json
admin@sonic:/etc/sonic$
Step 2: enable the ZTP service.
admin@sonic:~$ sudo config ztp enable
Step 3: Running the ZTP service
admin@sonic:~$ sudo config ztp run -y
Result:
Aug 11 02:46:11.796450 sonic INFO sonic-ztp[11570]: Processed Configuration section 01-configdb-json with result SUCCESS, exit code (0) at 2022-08-11 02:43:27 UTC.
Aug 11 02:46:11.798613 sonic INFO sonic-ztp[11570]: Processing configuration section 02-provisioning-script at 2022-08-11 02:46:11 UTC.
Aug 11 02:46:12.722543 sonic INFO sonic-ztp[11569]: MAC of DUT is 04:F8:F8:6B:06:91
Aug 11 02:46:12.729279 sonic INFO sonic-ztp[11570]: Processed Configuration section 02-provisioning-script with result SUCCESS, exit code (0) at 2022-08-11 02:46:11 UTC.
Aug 11 02:46:12.731083 sonic WARNING sonic-ztp[11570]: ZTP is rebooting the device as reboot-on-success flag is set.
[ 2399.421623] sonic-ztp[11569]: logname: no login name
Aug 11 02:46:13.689502 sonic INFO sonic-ztp[11569]: logname: no login name
[ 2401.193584] sonic-ztp[11569]: requested COLD shutdown
Aug 11 02:46:15.461467 sonic INFO sonic-ztp[11569]: requested COLD shutdown
Check the config_db.json on both switches.
AS7326-56X_1
admin@sonic:~$ sonic-cfggen -j /etc/sonic/config_db.json --var-json=DEVICE_METADATA
{
"DEVICE_METADATA": {
"localhost": {
"hostname": "sonic",
"hwsku": "Accton-AS7326-56X",
"platform": "x86_64-accton_as7326_56x-r0",
"mac": "04:F8:F8:6B:06:91",
"type": "LeafRouter",
"docker_routing_config_mode": "split",
"frr_mgmt_framework_config": "true"
}
}
}
AS7326-56X_2
admin@sonic:~$ sonic-cfggen -j /etc/sonic/config_db.json --var-json=DEVICE_METADATA
{
"DEVICE_METADATA": {
"localhost": {
"hostname": "sonic",
"hwsku": "Accton-AS7326-56X",
"platform": "x86_64-accton_as7326_56x-r0",
"mac": "68:21:5F:DC:3A:C8",
"type": "LeafRouter",
"docker_routing_config_mode": "split",
"frr_mgmt_framework_config": "true"
}
}
}
How to upload the frr.conf via ZTP?
Tested model & firmware version:
- Switch model name:
DCS203 (AS7326-56X) - Edgecore SONiC version:
202111.1
Topology:
Pre-configuration:
- DHCP Server.
- Prepare the essential file and put them in TFTP Server.
-
ztp.json
Example for ztp.json.
root@sharkobe:/tftpboot# cat ztp.json
{
"ztp": {
"01-download": {
"files": [
{
"url": {
"source": "tftp://188.188.36.36/7326_56X_config_db.json",
"destination": "/etc/sonic/config_db.json"
}
},
{
"url": {
"source": "tftp://188.188.36.36/7326_56X_frr.conf",
"destination": "/etc/sonic/frr/frr.conf"
}
}
],
"reboot-on-success": true
}
}
} - config_db.json (7326_56X_config_db.json)
- frr.conf (7326_56X_frr.conf)
-
Procedure:
Step 1: Make sure there's no config_db.json in /etc/sonic
admin@sonic:/etc/sonic$ ls | grep config_db.json
admin@sonic:/etc/sonic$
Step 2: enable the ZTP service.
admin@sonic:~$ sudo config ztp enable
Step 3: Running the ZTP service
admin@sonic:~$ sudo config ztp run -y
Result:
Oct 11 06:48:08.008016 sonic INFO sonic-ztp[25300]: Processing configuration section 01-download at 2022-10-11 06:48:08 UTC.
Oct 11 06:48:08.919545 sonic INFO sonic-ztp[25675]: download: Start downloading file 'tftp://188.188.36.36/7326_56X_config_db.json'.
Oct 11 06:48:14.170825 sonic INFO sonic-ztp[25675]: download: Completed downloading the file 'tftp://188.188.36.36/7326_56X_config_db.json' to '/etc/sonic/config_db.json'.
Oct 11 06:48:14.444236 sonic INFO sonic-ztp[25675]: download: Start downloading file 'tftp://188.188.36.36/7326_56X_frr.conf'.
Oct 11 06:48:20.667977 sonic INFO sonic-ztp[25675]: download: Completed downloading the file 'tftp://188.188.36.36/7326_56X_frr.conf' to '/etc/sonic/frr/frr.conf'.
Oct 11 06:48:20.680228 sonic INFO sonic-ztp[25300]: Processed Configuration section 01-download with result SUCCESS, exit code (0) at 2022-10-11 06:48:08 UTC.
Oct 11 06:48:20.681266 sonic WARNING sonic-ztp[25300]: ZTP is rebooting the device as reboot-on-success flag is set.
[ 1462.010770] sonic-ztp[25772]: logname: no login name
Oct 11 06:48:21.524415 sonic INFO sonic-ztp[25772]: logname: no login name
[ 1463.885547] sonic-ztp[25798]: requested COLD shutdown
Oct 11 06:48:23.399195 sonic INFO sonic-ztp[25798]: requested COLD shutdown
Oct 11 06:48:27.103808 sonic INFO sonic-ztp[25935]: /var/log: 0 B (0 bytes) trimmed on /dev/loop1
Oct 11 06:48:27.103889 sonic INFO sonic-ztp[25935]: /host: 1.7 GiB (1858351104 bytes) trimmed on /dev/sda4
[ 1470.992652] sonic-ztp[25770]: Tue 11 Oct 2022 06:48:30 AM UTC Issuing OS-level reboot ...
Oct 11 06:48:30.506293 sonic INFO sonic-ztp[25770]: Tue 11 Oct 2022 06:48:30 AM UTC Issuing OS-level reboot ...
[ 1492.701547] systemd-shutdown[1]: Could not detach loopback /dev/loop0: Device or resource busy
[ 1492.712058] systemd-shutdown[1]: Failed to finalize loop devices, ignoring.
[ 1493.115603] reboot: Restarting system
Comments
2 comments
Hi Shark,
Did you have test the connectivity-check case?
BEST,
Hello, Edgar
No, I didn't test the connectivity-check case.
I will try to test it, if it could work, I will add this article.
Thanks for your opinion.
Please sign in to leave a comment.