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

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