Blame SOURCES/wla-redhat-Fix-command-sequence-for-restarting-net-inter.patch

a85d1c
From 6d452b28383c59a8193595daaca13fa8db9338a1 Mon Sep 17 00:00:00 2001
a85d1c
From: Mohammed Gamal <mgamal@redhat.com>
a85d1c
Date: Wed, 22 Jun 2022 13:36:07 +0200
a85d1c
Subject: [PATCH] redhat: Fix command sequence for restarting net interface
a85d1c
a85d1c
RH-Author: Mohamed Gamal Morsy <mmorsy@redhat.com>
a85d1c
RH-MergeRequest: 2: redhat: Fix command sequence for restarting net interface
a85d1c
RH-Commit: [1/1] e838ff196b8823f64e08247b3a4dac9d60e5ed72
a85d1c
RH-Bugzilla: 2098233
a85d1c
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
a85d1c
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
a85d1c
a85d1c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2098233
a85d1c
a85d1c
Apparently the down and up commands need to be run in the same command, so
a85d1c
connect them together with "&&" operator. Also re-implement restart_if ot handle
a85d1c
warnings same wat as other distros
a85d1c
a85d1c
Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
a85d1c
---
a85d1c
 azurelinuxagent/common/osutil/redhat.py | 22 ++++++++++------------
a85d1c
 1 file changed, 10 insertions(+), 12 deletions(-)
a85d1c
a85d1c
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
a85d1c
index a02647cd..5c397ae8 100644
a85d1c
--- a/azurelinuxagent/common/osutil/redhat.py
a85d1c
+++ b/azurelinuxagent/common/osutil/redhat.py
a85d1c
@@ -147,16 +147,14 @@ class RedhatOSUtil(Redhat6xOSUtil):
a85d1c
         """
a85d1c
         Restart an interface by bouncing the link.
a85d1c
         """
a85d1c
-        retry_limit=retries+1
a85d1c
+        retry_limit = retries + 1
a85d1c
         for attempt in range(1, retry_limit):
a85d1c
-            try:
a85d1c
-                shellutil.run_command(["ip", "link", "set", ifname, "down"])
a85d1c
-                shellutil.run_command(["ip", "link", "set", ifname, "up"])
a85d1c
-
a85d1c
-            except shellutil.CommandError as cmd_err:
a85d1c
-                logger.warn("failed to restart {0}: return code {1}".format(ifname, cmd_err.returncode))
a85d1c
-                if attempt < retry_limit:
a85d1c
-                    logger.info("retrying in {0} seconds".format(wait))
a85d1c
-                    time.sleep(wait)
a85d1c
-                else:
a85d1c
-                    logger.warn("exceeded restart retries")
a85d1c
+            return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname), expected_errors=[1] if attempt < retries else [])
a85d1c
+            if return_code == 0:
a85d1c
+                return
a85d1c
+            logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
a85d1c
+            if attempt < retry_limit:
a85d1c
+                logger.info("retrying in {0} seconds".format(wait))
a85d1c
+                time.sleep(wait)
a85d1c
+            else:
a85d1c
+                logger.warn("exceeded restart retries")
a85d1c
-- 
a85d1c
2.31.1
a85d1c