Skip to content

Commit

Permalink
app-emulation/wa-linux-agent: Update to 2.9.1.1
Browse files Browse the repository at this point in the history
This is the current version being deployed to the Azure fleet for other
distros. This update contains a fix for:

  Failed to get the PID of the DHCP client: invalid literal for int() with base 10: 'MainPID=1640'

The upstream fix (stripping MainPid=) is in
Azure/WALinuxAgent#2784.

The patch has also been updated to fix the error:

  Unable to setup the persistent firewall rules: [Errno 30] Read-only file system: '/lib/systemd/system/waagent-network-setup.service'

by redirecting unit file installation to /etc/systemd/system. This change
requires handling in manglefs.sh as package installation unfortunately uses the
same path. This also requires adding a dependency on systemd-sysext.service to
that unit, as it depends on python, which is done through a drop-in.

A final change is handling interface restart. RedHat and Ubuntu bounce a single
link while Flatcar has so far used the "coreos" implementation (restart the
whole systemd-networkd), which forced a full dhcp lease renewal. Follow the
approaches of other distros by copying their implementation of restart_if.

Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
  • Loading branch information
jepio committed Nov 17, 2023
1 parent 4bc44d7 commit 836bdad
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DIST wa-linux-agent-2.6.0.2.tar.gz 1530936 BLAKE2B f47a4293a939da03859dafac2f422c4066dc2e92d6d4417a7e61e64abf22f1e096fcc7fc4ddfbe3166427ca44df75d967dbd1379d06c1b409fc3edc6340a17f2 SHA512 8826482ceb9e47a9b7f7271c5db19bf46ccabcefd327119e44f2760b147206a1fd3905a0cc8178527fe3326d4179f84bab8f7c673ede3c6de8dcacde0008e405
DIST wa-linux-agent-2.9.1.1.tar.gz 1986486 BLAKE2B ce630830886fe9bb729cfa7d92ac40bf158d26272b83e099fa2957928761642f84af2eef28ad691a076a89af6304f6ae67d7aa37ecf8629b3b973d083e619ae7 SHA512 3f44aecc16ac545db4b550586f168dbbdef34289aad6775973517bf645e5a1d486864c01e974f03a71b3e946c14e1ca140673a75c1cd602aac28725eaa68e83d
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
From dd1512513b407e23155f58400cacecac8576d6f9 Mon Sep 17 00:00:00 2001
From c51b223ed4e510abbf5b89200fa25ee2eede078a Mon Sep 17 00:00:00 2001
From: Krzesimir Nowak <knowak@microsoft.com>
Date: Mon, 27 Feb 2023 15:59:21 +0100
Subject: [PATCH] flatcar changes

Signed-off-by: Jeremi Piotrowski <jpiotrowski@microsoft.com>
---
azurelinuxagent/common/osutil/coreos.py | 39 +-----
azurelinuxagent/common/osutil/coreoscommon.py | 57 ++++++++
azurelinuxagent/common/osutil/coreos.py | 40 +-----
azurelinuxagent/common/osutil/coreoscommon.py | 59 +++++++++
azurelinuxagent/common/osutil/factory.py | 3 +
azurelinuxagent/common/osutil/flatcar.py | 60 +++++++++
azurelinuxagent/common/osutil/flatcar.py | 78 +++++++++++
config/flatcar/waagent.conf | 122 ++++++++++++++++++
.../10-waagent-network-setup-sysext.conf | 2 +
init/flatcar/10-waagent-sysext.conf | 2 +
init/flatcar/waagent.service | 30 +++++
setup.py | 20 ++-
8 files changed, 291 insertions(+), 42 deletions(-)
setup.py | 23 +++-
9 files changed, 316 insertions(+), 43 deletions(-)
create mode 100644 azurelinuxagent/common/osutil/coreoscommon.py
create mode 100644 azurelinuxagent/common/osutil/flatcar.py
create mode 100644 config/flatcar/waagent.conf
create mode 100644 init/flatcar/10-waagent-network-setup-sysext.conf
create mode 100644 init/flatcar/10-waagent-sysext.conf
create mode 100644 init/flatcar/waagent.service

diff --git a/azurelinuxagent/common/osutil/coreos.py b/azurelinuxagent/common/osutil/coreos.py
index fc0a6604..314008f0 100644
index 373727e2..63578932 100644
--- a/azurelinuxagent/common/osutil/coreos.py
+++ b/azurelinuxagent/common/osutil/coreos.py
@@ -17,11 +17,10 @@
#
@@ -18,10 +18,10 @@

import os
-import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.utils import shellutil
-from azurelinuxagent.common.osutil.default import DefaultOSUtil
+from azurelinuxagent.common.osutil.coreoscommon import CoreosCommonUtil

Expand All @@ -37,7 +39,7 @@ index fc0a6604..314008f0 100644

def __init__(self):
super(CoreOSUtil, self).__init__()
@@ -46,40 +45,6 @@ class CoreOSUtil(DefaultOSUtil):
@@ -46,42 +46,6 @@ class CoreOSUtil(DefaultOSUtil):
def get_agent_bin_path():
return "/usr/share/oem/bin"

Expand Down Expand Up @@ -73,17 +75,19 @@ index fc0a6604..314008f0 100644
- return shellutil.run("systemctl stop {0}".format(self.service_name), chk_err=False)
-
- def get_dhcp_pid(self):
- return self._get_dhcp_pid(["systemctl", "show", "-p", "MainPID", "systemd-networkd"])
- return self._get_dhcp_pid(
- ["systemctl", "show", "-p", "MainPID", "systemd-networkd"],
- transform_command_output=lambda o: o.replace("MainPID=", ""))
-
def conf_sshd(self, disable_password):
# In CoreOS, /etc/sshd_config is mount readonly. Skip the setting.
pass
diff --git a/azurelinuxagent/common/osutil/coreoscommon.py b/azurelinuxagent/common/osutil/coreoscommon.py
new file mode 100644
index 00000000..fde9a456
index 00000000..66eae16e
--- /dev/null
+++ b/azurelinuxagent/common/osutil/coreoscommon.py
@@ -0,0 +1,57 @@
@@ -0,0 +1,59 @@
+#
+# Copyright 2023 Microsoft Corporation
+#
Expand Down Expand Up @@ -140,20 +144,22 @@ index 00000000..fde9a456
+ return shellutil.run("systemctl stop {0}".format(self.service_name), chk_err=False)
+
+ def get_dhcp_pid(self):
+ return self._get_dhcp_pid(["systemctl", "show", "-p", "MainPID", "systemd-networkd"])
+ return self._get_dhcp_pid(
+ ["systemctl", "show", "-p", "MainPID", "systemd-networkd"],
+ transform_command_output=lambda o: o.replace("MainPID=", ""))
diff --git a/azurelinuxagent/common/osutil/factory.py b/azurelinuxagent/common/osutil/factory.py
index b5ee0b09..9280c645 100644
index 83123e3f..b9257a9b 100644
--- a/azurelinuxagent/common/osutil/factory.py
+++ b/azurelinuxagent/common/osutil/factory.py
@@ -27,6 +27,7 @@ from .clearlinux import ClearLinuxUtil
from .coreos import CoreOSUtil
@@ -28,6 +28,7 @@ from .coreos import CoreOSUtil
from .debian import DebianOSBaseUtil, DebianOSModernUtil
from .default import DefaultOSUtil
from .devuan import DevuanOSUtil
+from .flatcar import FlatcarUtil
from .freebsd import FreeBSDOSUtil
from .gaia import GaiaOSUtil
from .iosxe import IosxeOSUtil
@@ -82,6 +83,8 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
@@ -88,6 +89,8 @@ def _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
return DebianOSBaseUtil()

if distro_name in ("flatcar", "coreos") or distro_code_name in ("flatcar", "coreos"):
Expand All @@ -164,10 +170,10 @@ index b5ee0b09..9280c645 100644
if distro_name in ("suse", "sle_hpc", "sles", "opensuse"):
diff --git a/azurelinuxagent/common/osutil/flatcar.py b/azurelinuxagent/common/osutil/flatcar.py
new file mode 100644
index 00000000..bf739a8e
index 00000000..e31b2923
--- /dev/null
+++ b/azurelinuxagent/common/osutil/flatcar.py
@@ -0,0 +1,60 @@
@@ -0,0 +1,78 @@
+#
+# Copyright 2023 Microsoft Corporation
+#
Expand All @@ -194,14 +200,15 @@ index 00000000..bf739a8e
+import azurelinuxagent.common.conf as conf
+import azurelinuxagent.common.logger as logger
+import azurelinuxagent.common.utils.fileutil as fileutil
+import azurelinuxagent.common.utils.shellutil as shellutil
+
+from azurelinuxagent.common.osutil.coreoscommon import CoreosCommonUtil
+
+class FlatcarUtil(CoreosCommonUtil):
+
+ @staticmethod
+ def get_systemd_unit_file_install_path():
+ return "/usr/lib/systemd/system"
+ return "/etc/systemd/system"
+
+ def conf_sshd(self, disable_password):
+ ssh_dir = conf.get_ssh_dir()
Expand All @@ -228,6 +235,23 @@ index 00000000..bf739a8e
+ os.remove(conf_file_path)
+ os.rename(conf_file_path2, conf_file_path)
+ super(CoreosCommonUtil, self).conf_sshd(disable_password)
+
+ def restart_if(self, ifname, retries=3, wait=5):
+ """
+ Restart an interface by bouncing the link. systemd-networkd observes
+ this event, and forces a renew of DHCP.
+ """
+ retry_limit = retries + 1
+ for attempt in range(1, retry_limit):
+ return_code = shellutil.run("ip link set {0} down && ip link set {0} up".format(ifname))
+ 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")
diff --git a/config/flatcar/waagent.conf b/config/flatcar/waagent.conf
new file mode 100644
index 00000000..b453c634
Expand Down Expand Up @@ -356,6 +380,14 @@ index 00000000..b453c634
+
+# Add firewall rules to protect access to Azure host node services
+OS.EnableFirewall=y
diff --git a/init/flatcar/10-waagent-network-setup-sysext.conf b/init/flatcar/10-waagent-network-setup-sysext.conf
new file mode 100644
index 00000000..28af9fad
--- /dev/null
+++ b/init/flatcar/10-waagent-network-setup-sysext.conf
@@ -0,0 +1,2 @@
+[Unit]
+After=systemd-sysext.service
diff --git a/init/flatcar/10-waagent-sysext.conf b/init/flatcar/10-waagent-sysext.conf
new file mode 100644
index 00000000..f756dbc9
Expand Down Expand Up @@ -401,10 +433,10 @@ index 00000000..d0d6f7c8
+[Install]
+WantedBy=multi-user.target
diff --git a/setup.py b/setup.py
index d38d74d6..57b0edb9 100755
index 8f5d92b4..0e5af794 100755
--- a/setup.py
+++ b/setup.py
@@ -125,12 +125,22 @@ def get_data_files(name, version, fullname): # pylint: disable=R0912
@@ -135,12 +135,25 @@ def get_data_files(name, version, fullname): # pylint: disable=R0912
src=["init/arch/waagent.service"])
elif name in ('coreos', 'flatcar'):
set_bin_files(data_files, dest=agent_bin_path)
Expand All @@ -423,6 +455,9 @@ index d38d74d6..57b0edb9 100755
+ multi_user_target_drop_in_dir=f"{systemd_dir_path}/multi-user.target.d"
+ set_systemd_files(data_files, dest=multi_user_target_drop_in_dir,
+ src=["init/flatcar/10-waagent-sysext.conf"])
+ waagent_network_setup_drop_in_dir=f"{systemd_dir_path}/waagent-network-setup.service.d"
+ set_systemd_files(data_files, dest=waagent_network_setup_drop_in_dir,
+ src=["init/flatcar/10-waagent-network-setup-sysext.conf"])
+ else:
+ set_udev_files(data_files)
+ set_conf_files(data_files, dest="/usr/share/oem",
Expand All @@ -433,5 +468,5 @@ index d38d74d6..57b0edb9 100755
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files, dest="/usr/share/defaults/waagent",
--
2.25.1
2.39.2

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ to_delete=(
rm -rf "${to_delete[@]/#/${rootfs}}"

ln -sf /usr/bin/true "${rootfs}/usr/bin/eject"

# At runtime we need the agent to write systemd.service to /etc but during
# package creation it needs to be /usr/lib. waagent uses the same function in
# both cases, so mangle manually.
mkdir -p "${rootfs}"/usr/lib/systemd
mv "${rootfs}"/{etc,usr/lib}/systemd/system

0 comments on commit 836bdad

Please sign in to comment.