Blame SOURCES/wla-redhat-Implement-restart_if-correctly-to-eliminate-w.patch

60528a
From 085ca05c4dfa8462a100e4218e4570e610f28564 Mon Sep 17 00:00:00 2001
60528a
From: Mohammed Gamal <mgamal@redhat.com>
60528a
Date: Thu, 30 Jun 2022 11:54:12 +0200
60528a
Subject: [PATCH] redhat: Implement restart_if correctly to eliminate warnings
60528a
60528a
RH-Author: Mohamed Gamal Morsy <mmorsy@redhat.com>
60528a
RH-MergeRequest: 5: redhat: Implement restart_if correctly to eliminate warnings
60528a
RH-Commit: [1/1] 3d4a942dfcc15d36607455175191a9a67196d76d
60528a
RH-Bugzilla: 2098083
60528a
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
60528a
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
60528a
60528a
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2098083
60528a
60528a
restart_if seems to generate some warnings. As errors are not handled correctly.
60528a
Implement restart_if() the same wat as default.py, but with RH supported commands
60528a
instead
60528a
60528a
Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
60528a
---
60528a
 azurelinuxagent/common/osutil/redhat.py | 21 ++++++++++-----------
60528a
 1 file changed, 10 insertions(+), 11 deletions(-)
60528a
60528a
diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py
60528a
index 840f7a1d..5c397ae8 100644
60528a
--- a/azurelinuxagent/common/osutil/redhat.py
60528a
+++ b/azurelinuxagent/common/osutil/redhat.py
60528a
@@ -147,15 +147,14 @@ class RedhatOSUtil(Redhat6xOSUtil):
60528a
         """
60528a
         Restart an interface by bouncing the link.
60528a
         """
60528a
-        retry_limit=retries+1
60528a
+        retry_limit = retries + 1
60528a
         for attempt in range(1, retry_limit):
60528a
-            try:
60528a
-                shellutil.run_command(["ip", "link", "set", ifname, "down", "&&", "ip", "link", "set", ifname, "up"])
60528a
-
60528a
-            except shellutil.CommandError as cmd_err:
60528a
-                logger.warn("failed to restart {0}: return code {1}".format(ifname, cmd_err.returncode))
60528a
-                if attempt < retry_limit:
60528a
-                    logger.info("retrying in {0} seconds".format(wait))
60528a
-                    time.sleep(wait)
60528a
-                else:
60528a
-                    logger.warn("exceeded restart retries")
60528a
+            return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname), expected_errors=[1] if attempt < retries else [])
60528a
+            if return_code == 0:
60528a
+                return
60528a
+            logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
60528a
+            if attempt < retry_limit:
60528a
+                logger.info("retrying in {0} seconds".format(wait))
60528a
+                time.sleep(wait)
60528a
+            else:
60528a
+                logger.warn("exceeded restart retries")
60528a
-- 
60528a
2.31.1
60528a