From e7f49c9bce2bd7b8960b6a61ffe2c8b933423c6b Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Thu, 21 Sep 2023 20:40:21 +0800 Subject: [PATCH] Fix potentially not having any loopback address on lo interface (#16490) (#16628) In #15080, there was a command added to re-add 127.0.0.1/8 to the lo interface when the networking configuration is being brought down. However, the trigger for that command is `down`, which, looking at ifupdown2 configuration files, runs immediately after 127.0.0.1/16 is removed. This means there may be a period of time where there are no loopback addresses assigned to the lo interface, and redis commands will fail. Fix this by changing this to pre-down, which should run well before 127.0.0.1/16 is removed, and should always leave lo with a loopback address. Signed-off-by: Saikrishna Arcot Co-authored-by: Saikrishna Arcot --- files/image_config/interfaces/interfaces.j2 | 2 +- src/sonic-config-engine/tests/sample_output/py2/interfaces | 2 +- .../tests/sample_output/py2/interfaces_nomgmt | 2 +- .../tests/sample_output/py2/interfaces_nomgmt_ztp | 2 +- .../tests/sample_output/py2/interfaces_nomgmt_ztp_inband | 2 +- .../tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip | 2 +- .../tests/sample_output/py2/interfaces_nomgmt_ztp_ip | 2 +- src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces | 2 +- .../tests/sample_output/py2/mvrf_interfaces_nomgmt | 2 +- .../tests/sample_output/py2/two_mgmt_interfaces | 2 +- src/sonic-config-engine/tests/sample_output/py3/interfaces | 2 +- .../tests/sample_output/py3/interfaces_nomgmt | 2 +- .../tests/sample_output/py3/interfaces_nomgmt_ztp | 2 +- .../tests/sample_output/py3/interfaces_nomgmt_ztp_inband | 2 +- .../tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip | 2 +- .../tests/sample_output/py3/interfaces_nomgmt_ztp_ip | 2 +- src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces | 2 +- .../tests/sample_output/py3/mvrf_interfaces_nomgmt | 2 +- .../tests/sample_output/py3/two_mgmt_interfaces | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index 18e1181c71..b39331f459 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -26,7 +26,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo {% endblock loopback %} {% block mgmt_interface %} diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces b/src/sonic-config-engine/tests/sample_output/py2/interfaces index a47c89258e..90aadce5f4 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt index c447cfbc6d..b38c3692e9 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index b41038fd8d..705a5a0e20 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 543819734f..d09e9e741d 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 57bf924ce7..e76aea8261 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 31a6d33257..e5ad2330f3 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces index 5777bce183..1c33cfe819 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces @@ -19,7 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 04490892fe..8f0f455578 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt @@ -19,7 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces b/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces index ce3961f1a7..319f25c4e9 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth1 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces b/src/sonic-config-engine/tests/sample_output/py3/interfaces index a47c89258e..90aadce5f4 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt index c447cfbc6d..b38c3692e9 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index b41038fd8d..705a5a0e20 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 543819734f..d09e9e741d 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 57bf924ce7..e76aea8261 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 31a6d33257..e5ad2330f3 100644 --- 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 @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces index 5777bce183..1c33cfe819 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces @@ -19,7 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 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 index 04490892fe..8f0f455578 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt @@ -19,7 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces b/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces index 5e2680854c..490a27366f 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces @@ -10,7 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo - down ip addr add 127.0.0.1/8 dev lo + pre-down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0