Skip to content

Commit b8ca432

Browse files
authored
fix network interface restart in RHEL9 (Azure#2592)
1 parent aa6d82c commit b8ca432

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

azurelinuxagent/common/osutil/factory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from .nsbsd import NSBSDOSUtil
3535
from .openbsd import OpenBSDOSUtil
3636
from .openwrt import OpenWRTOSUtil
37-
from .redhat import RedhatOSUtil, Redhat6xOSUtil
37+
from .redhat import RedhatOSUtil, Redhat6xOSUtil, RedhatOSModernUtil
3838
from .suse import SUSEOSUtil, SUSE11OSUtil
3939
from .photonos import PhotonOSUtil
4040
from .ubuntu import UbuntuOSUtil, Ubuntu12OSUtil, Ubuntu14OSUtil, \
@@ -107,6 +107,9 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
107107
if Version(distro_version) < Version("7"):
108108
return Redhat6xOSUtil()
109109

110+
if Version(distro_version) == Version("8.6") or Version(distro_version) > Version("9"):
111+
return RedhatOSModernUtil()
112+
110113
return RedhatOSUtil()
111114

112115
if distro_name == "euleros":

azurelinuxagent/common/osutil/redhat.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,25 @@ def get_dhcp_lease_endpoint(self):
142142
endpoint = self.get_endpoint_from_leases_path('/var/lib/NetworkManager/dhclient-*.lease')
143143

144144
return endpoint
145+
146+
147+
class RedhatOSModernUtil(RedhatOSUtil):
148+
def __init__(self): # pylint: disable=W0235
149+
super(RedhatOSModernUtil, self).__init__()
150+
151+
def restart_if(self, ifname, retries=3, wait=5):
152+
"""
153+
Restart an interface by bouncing the link. systemd-networkd observes
154+
this event, and forces a renew of DHCP.
155+
"""
156+
retry_limit = retries + 1
157+
for attempt in range(1, retry_limit):
158+
return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname))
159+
if return_code == 0:
160+
return
161+
logger.warn("failed to restart {0}: return code {1}".format(ifname, return_code))
162+
if attempt < retry_limit:
163+
logger.info("retrying in {0} seconds".format(wait))
164+
time.sleep(wait)
165+
else:
166+
logger.warn("exceeded restart retries")

0 commit comments

Comments
 (0)