WALinuxAgent/SOURCES/wla-redhat-Implement-restar...

57 lines
2.5 KiB
Diff

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