From ab69ae533c18db1f468e7433984b36159612c0d0 Mon Sep 17 00:00:00 2001 From: Mohammed Gamal Date: Tue, 17 May 2022 10:50:59 +0200 Subject: [PATCH 2/2] Implement restart_if for RedHat OS RH-Author: Mohamed Gamal Morsy RH-MergeRequest: 2: Fix if hangs (#2283) RH-Commit: [2/2] ba8712ff724d5f3cd8bd0b19f5849c854f6c99ca RH-Bugzilla: 2092753 RH-Acked-by: Vitaly Kuznetsov RH-Acked-by: Cathy Avery Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2092753 Signed-off-by: Vitaly Kuznetsov Signed-off-by: Mohammed Gamal --- azurelinuxagent/common/osutil/redhat.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py index 9759d113..840f7a1d 100644 --- a/azurelinuxagent/common/osutil/redhat.py +++ b/azurelinuxagent/common/osutil/redhat.py @@ -142,3 +142,20 @@ class RedhatOSUtil(Redhat6xOSUtil): endpoint = self.get_endpoint_from_leases_path('/var/lib/NetworkManager/dhclient-*.lease') return endpoint + + def restart_if(self, ifname, retries=3, wait=5): + """ + Restart an interface by bouncing the link. + """ + 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") -- 2.31.1