|
|
39a8b9 |
From b415b30624f0dcbe9fd574c28593e8fd38a8d9c8 Mon Sep 17 00:00:00 2001
|
|
|
39a8b9 |
From: Mohammed Gamal <mgamal@redhat.com>
|
|
|
39a8b9 |
Date: Thu, 2 Jun 2022 14:39:42 +0200
|
|
|
39a8b9 |
Subject: [PATCH 1/2] Fix if hangs (#2283)
|
|
|
39a8b9 |
|
|
|
39a8b9 |
RH-Author: Mohamed Gamal Morsy <mmorsy@redhat.com>
|
|
|
39a8b9 |
RH-MergeRequest: 2: Fix if hangs (#2283)
|
|
|
39a8b9 |
RH-Commit: [1/2] cf3b0a2d65eb9eeeceab6d74e376e729e06a01ed
|
|
|
39a8b9 |
RH-Bugzilla: 2092753
|
|
|
39a8b9 |
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
|
39a8b9 |
RH-Acked-by: Cathy Avery <cavery@redhat.com>
|
|
|
39a8b9 |
|
|
|
39a8b9 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2092753
|
|
|
39a8b9 |
|
|
|
39a8b9 |
Signed-off-by: Laveesh Rohra <larohra@microsoft.com>
|
|
|
39a8b9 |
(cherry picked from commit 05cd6437ba90928788ef18c8b9fc8a6dbaf47c7d)
|
|
|
39a8b9 |
|
|
|
39a8b9 |
Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
|
|
|
39a8b9 |
---
|
|
|
39a8b9 |
azurelinuxagent/common/osutil/default.py | 26 ++++++++----------------
|
|
|
39a8b9 |
azurelinuxagent/common/osutil/ubuntu.py | 22 +++++++++-----------
|
|
|
39a8b9 |
tests/common/osutil/test_default.py | 11 +++-------
|
|
|
39a8b9 |
3 files changed, 21 insertions(+), 38 deletions(-)
|
|
|
39a8b9 |
|
|
|
39a8b9 |
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
|
|
|
39a8b9 |
index 066e1431..820016c1 100644
|
|
|
39a8b9 |
--- a/azurelinuxagent/common/osutil/default.py
|
|
|
39a8b9 |
+++ b/azurelinuxagent/common/osutil/default.py
|
|
|
39a8b9 |
@@ -1163,25 +1163,15 @@ class DefaultOSUtil(object):
|
|
|
39a8b9 |
def restart_if(self, ifname, retries=3, wait=5):
|
|
|
39a8b9 |
retry_limit = retries + 1
|
|
|
39a8b9 |
for attempt in range(1, retry_limit):
|
|
|
39a8b9 |
- try:
|
|
|
39a8b9 |
- shellutil.run_command(["ifdown", ifname])
|
|
|
39a8b9 |
- shellutil.run_command(["ifup", ifname])
|
|
|
39a8b9 |
+ return_code = shellutil.run("ifdown {0} && ifup {0}".format(ifname), expected_errors=[1] if attempt < retries else [])
|
|
|
39a8b9 |
+ if return_code == 0:
|
|
|
39a8b9 |
return
|
|
|
39a8b9 |
- except shellutil.CommandError as cmd_err:
|
|
|
39a8b9 |
-
|
|
|
39a8b9 |
- msg = "failed to restart {0}: returncode={1}\n[stdout]{2}\n\n[stderr]{3}\n"\
|
|
|
39a8b9 |
- .format(ifname, cmd_err.returncode, cmd_err.stdout, cmd_err.stderr)
|
|
|
39a8b9 |
-
|
|
|
39a8b9 |
- if cmd_err.returncode == 1:
|
|
|
39a8b9 |
- logger.info(msg)
|
|
|
39a8b9 |
- else:
|
|
|
39a8b9 |
- logger.warn(msg)
|
|
|
39a8b9 |
-
|
|
|
39a8b9 |
- if attempt < retry_limit:
|
|
|
39a8b9 |
- logger.info("retrying in {0} seconds".format(wait))
|
|
|
39a8b9 |
- time.sleep(wait)
|
|
|
39a8b9 |
- else:
|
|
|
39a8b9 |
- logger.warn("exceeded restart retries")
|
|
|
39a8b9 |
+ logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
|
|
|
39a8b9 |
+ if attempt < retry_limit:
|
|
|
39a8b9 |
+ logger.info("retrying in {0} seconds".format(wait))
|
|
|
39a8b9 |
+ time.sleep(wait)
|
|
|
39a8b9 |
+ else:
|
|
|
39a8b9 |
+ logger.warn("exceeded restart retries")
|
|
|
39a8b9 |
|
|
|
39a8b9 |
def publish_hostname(self, hostname):
|
|
|
39a8b9 |
self.set_dhcp_hostname(hostname)
|
|
|
39a8b9 |
diff --git a/azurelinuxagent/common/osutil/ubuntu.py b/azurelinuxagent/common/osutil/ubuntu.py
|
|
|
39a8b9 |
index 249e1120..5a21511c 100644
|
|
|
39a8b9 |
--- a/azurelinuxagent/common/osutil/ubuntu.py
|
|
|
39a8b9 |
+++ b/azurelinuxagent/common/osutil/ubuntu.py
|
|
|
39a8b9 |
@@ -142,19 +142,17 @@ class UbuntuOSUtil(Ubuntu16OSUtil):
|
|
|
39a8b9 |
Restart an interface by bouncing the link. systemd-networkd observes
|
|
|
39a8b9 |
this event, and forces a renew of DHCP.
|
|
|
39a8b9 |
"""
|
|
|
39a8b9 |
- retry_limit=retries+1
|
|
|
39a8b9 |
+ retry_limit = retries+1
|
|
|
39a8b9 |
for attempt in range(1, retry_limit):
|
|
|
39a8b9 |
- try:
|
|
|
39a8b9 |
- shellutil.run_command(["ip", "link", "set", ifname, "down"])
|
|
|
39a8b9 |
- shellutil.run_command(["ip", "link", "set", ifname, "up"])
|
|
|
39a8b9 |
-
|
|
|
39a8b9 |
- except shellutil.CommandError as cmd_err:
|
|
|
39a8b9 |
- logger.warn("failed to restart {0}: return code {1}".format(ifname, cmd_err.returncode))
|
|
|
39a8b9 |
- if attempt < retry_limit:
|
|
|
39a8b9 |
- logger.info("retrying in {0} seconds".format(wait))
|
|
|
39a8b9 |
- time.sleep(wait)
|
|
|
39a8b9 |
- else:
|
|
|
39a8b9 |
- logger.warn("exceeded restart retries")
|
|
|
39a8b9 |
+ return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname))
|
|
|
39a8b9 |
+ if return_code == 0:
|
|
|
39a8b9 |
+ return
|
|
|
39a8b9 |
+ logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
|
|
|
39a8b9 |
+ if attempt < retry_limit:
|
|
|
39a8b9 |
+ logger.info("retrying in {0} seconds".format(wait))
|
|
|
39a8b9 |
+ time.sleep(wait)
|
|
|
39a8b9 |
+ else:
|
|
|
39a8b9 |
+ logger.warn("exceeded restart retries")
|
|
|
39a8b9 |
|
|
|
39a8b9 |
|
|
|
39a8b9 |
class UbuntuSnappyOSUtil(Ubuntu14OSUtil):
|
|
|
39a8b9 |
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
|
|
|
39a8b9 |
index 65d7ae0f..d6eae68f 100644
|
|
|
39a8b9 |
--- a/tests/common/osutil/test_default.py
|
|
|
39a8b9 |
+++ b/tests/common/osutil/test_default.py
|
|
|
39a8b9 |
@@ -49,20 +49,15 @@ class TestOSUtil(AgentTestCase):
|
|
|
39a8b9 |
# setup
|
|
|
39a8b9 |
retries = 3
|
|
|
39a8b9 |
ifname = 'dummy'
|
|
|
39a8b9 |
- with patch.object(shellutil, "run_command") as run_patch:
|
|
|
39a8b9 |
- run_patch.side_effect = shellutil.CommandError("ifupdown dummy", 1, "", "")
|
|
|
39a8b9 |
+ with patch.object(shellutil, "run") as run_patch:
|
|
|
39a8b9 |
+ run_patch.return_value = 1
|
|
|
39a8b9 |
|
|
|
39a8b9 |
# execute
|
|
|
39a8b9 |
osutil.DefaultOSUtil.restart_if(osutil.DefaultOSUtil(), ifname=ifname, retries=retries, wait=0)
|
|
|
39a8b9 |
|
|
|
39a8b9 |
# assert
|
|
|
39a8b9 |
self.assertEqual(run_patch.call_count, retries)
|
|
|
39a8b9 |
- cmd_queue = list(args[0] for (args, _) in run_patch.call_args_list)
|
|
|
39a8b9 |
- while cmd_queue:
|
|
|
39a8b9 |
- self.assertEqual(cmd_queue.pop(0), ["ifdown", ifname])
|
|
|
39a8b9 |
- # We don't expect the following command to be called because 'dummy' does
|
|
|
39a8b9 |
- # not exist.
|
|
|
39a8b9 |
- self.assertNotEqual(cmd_queue[0] if cmd_queue else None, ["ifup", ifname])
|
|
|
39a8b9 |
+ self.assertEqual(run_patch.call_args_list[0][0][0], 'ifdown {0} && ifup {0}'.format(ifname))
|
|
|
39a8b9 |
|
|
|
39a8b9 |
def test_get_dvd_device_success(self):
|
|
|
39a8b9 |
with patch.object(os, 'listdir', return_value=['cpu', 'cdrom0']):
|
|
|
39a8b9 |
--
|
|
|
39a8b9 |
2.31.1
|
|
|
39a8b9 |
|