From f79d25171e136ac9606d63d45f4848a5dcbd3671 Mon Sep 17 00:00:00 2001 From: yixiangzhike Date: Tue, 1 Apr 2025 15:37:29 +0800 Subject: [PATCH] Backport upstream patches --- ...yping-for-rsyslog-power_state_change.patch | 86 +++++++++++ ...-not-remove-all-existing-settings-of.patch | 138 ++++++++++++++++++ ...nit-22.1-no-override-default-network.patch | 36 ----- cloud-init.spec | 11 +- 4 files changed, 233 insertions(+), 38 deletions(-) create mode 100644 backport-fix-typing-for-rsyslog-power_state_change.patch create mode 100644 backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch delete mode 100644 cloud-init-22.1-no-override-default-network.patch diff --git a/backport-fix-typing-for-rsyslog-power_state_change.patch b/backport-fix-typing-for-rsyslog-power_state_change.patch new file mode 100644 index 0000000..20623a4 --- /dev/null +++ b/backport-fix-typing-for-rsyslog-power_state_change.patch @@ -0,0 +1,86 @@ +From 2b7d9636b303ad212d1a446ab59636c5cd75dd4a Mon Sep 17 00:00:00 2001 +From: MostafaTarek124eru + <48182100+MostafaTarek124eru@users.noreply.github.com> +Date: Tue, 11 Feb 2025 00:54:01 +0200 +Subject: [PATCH] fix: typing for rsyslog, ubuntu_pro, power_state_change + (#5985) + +Reference:https://github.com/canonical/cloud-init/commit/2b7d9636b303ad212d1a446ab59636c5cd75dd4a +Conflict:not change cloudinit/config/cc_ubuntu_pro.py, pyproject.toml and tests/unittests/config/test_cc_ubuntu_pro.py +--- + cloudinit/config/cc_power_state_change.py | 5 ++++- + cloudinit/config/cc_rsyslog.py | 5 +---- + tests/unittests/config/test_cc_power_state_change.py | 2 +- + tests/unittests/config/test_cc_rsyslog.py | 4 ++-- + 4 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py +index 72e6634..90534ed 100644 +--- a/cloudinit/config/cc_power_state_change.py ++++ b/cloudinit/config/cc_power_state_change.py +@@ -93,7 +93,10 @@ def givecmdline(pid): + (output, _err) = subp.subp(["procstat", "-c", str(pid)]) + line = output.splitlines()[1] + m = re.search(r"\d+ (\w|\.|-)+\s+(/\w.+)", line) +- return m.group(2) ++ if m: ++ return m.group(2) ++ else: ++ return None + else: + return util.load_file("/proc/%s/cmdline" % pid) + except IOError: +diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py +index a04595b..0087a16 100644 +--- a/cloudinit/config/cc_rsyslog.py ++++ b/cloudinit/config/cc_rsyslog.py +@@ -307,10 +307,7 @@ class SyslogRemotesLine: + self.proto = proto + + self.addr = addr +- if port: +- self.port = int(port) +- else: +- self.port = None ++ self.port = int(port) if port is not None else None + + def validate(self): + if self.port: +diff --git a/tests/unittests/config/test_cc_power_state_change.py b/tests/unittests/config/test_cc_power_state_change.py +index 8a1886c..ce8d74b 100644 +--- a/tests/unittests/config/test_cc_power_state_change.py ++++ b/tests/unittests/config/test_cc_power_state_change.py +@@ -47,7 +47,7 @@ class TestLoadPowerState(t_help.TestCase): + self.assertRaises(TypeError, psc.load_power_state, cfg, self.dist) + + def test_valid_modes(self): +- cfg = {"power_state": {}} ++ cfg: dict = {"power_state": {}} + for mode in ("halt", "poweroff", "reboot"): + cfg["power_state"]["mode"] = mode + check_lps_ret(psc.load_power_state(cfg, self.dist), mode=mode) +diff --git a/tests/unittests/config/test_cc_rsyslog.py b/tests/unittests/config/test_cc_rsyslog.py +index b69f602..6e67668 100644 +--- a/tests/unittests/config/test_cc_rsyslog.py ++++ b/tests/unittests/config/test_cc_rsyslog.py +@@ -340,7 +340,7 @@ class TestInstallRsyslog(TestCase): + with mock.patch.object( + cloud.distro, "install_packages" + ) as m_install: +- handle("rsyslog", {"rsyslog": config}, cloud, None) ++ handle("rsyslog", {"rsyslog": config}, cloud, []) + m_which.assert_called_with(config["check_exe"]) + m_install.assert_called_with(config["packages"]) + +@@ -356,6 +356,6 @@ class TestInstallRsyslog(TestCase): + m_isbsd.return_value = False + m_which.return_value = "/usr/sbin/rsyslogd" + with mock.patch.object(cloud.distro, "install_packages") as m_install: +- handle("rsyslog", {"rsyslog": config}, cloud, None) ++ handle("rsyslog", {"rsyslog": config}, cloud, []) + m_which.assert_called_with(config["check_exe"]) + m_install.assert_not_called() +-- +2.33.0 + + diff --git a/backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch b/backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch new file mode 100644 index 0000000..b7fe13f --- /dev/null +++ b/backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch @@ -0,0 +1,138 @@ +From fa331315d22f4bbe33320485e89a02bb2f695fbf Mon Sep 17 00:00:00 2001 +From: Ani Sinha +Date: Sat, 15 Feb 2025 01:54:31 +0530 +Subject: [PATCH] net/sysconfig: do not remove all existing settings of + /etc/sysconfig/network (#5991) + +Reference:https://github.com/canonical/cloud-init/commit/fa331315d22f4bbe33320485e89a02bb2f695fbf +Conflict:use util.load_file not util.load_text_file in render_network_state(). + +In some distros, /etc/sysconfig/network may have important configurations that +are necessary for the instance to come up. For example, centos based distros +write NOZEROCONF=yes in /etc/sysconfig/network for some instances that require +zeroconf to be disabled. Removing these customizations would prevent the +instance to come up. So leave the customizations in /etc/sysconfig/network +intact except those that we are interested in. + +Fixes GH-5990 +Signed-off-by: Ani Sinha +--- + cloudinit/net/sysconfig.py | 18 +++++++ + tests/unittests/distros/test_netconfig.py | 60 ++++++++++++++++++++++- + 2 files changed, 76 insertions(+), 2 deletions(-) + +diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py +index ab241df..ce24f19 100644 +--- a/cloudinit/net/sysconfig.py ++++ b/cloudinit/net/sysconfig.py +@@ -1035,6 +1035,24 @@ class Renderer(renderer.Renderer): + if network_state.use_ipv6: + netcfg.append("NETWORKING_IPV6=yes") + netcfg.append("IPV6_AUTOCONF=no") ++ ++ # if sysconfig file exists and is not empty, append rest of the ++ # file content, do not remove the exsisting customizations. ++ if os.path.exists(sysconfig_path): ++ for line in util.load_file(sysconfig_path).splitlines(): ++ if ( ++ not any( ++ setting in line ++ for setting in [ ++ "NETWORKING", ++ "NETWORKING_IPV6", ++ "IPV6_AUTOCONF", ++ ] ++ ) ++ and line not in _make_header().splitlines() ++ ): ++ netcfg.append(line) ++ + util.write_file( + sysconfig_path, "\n".join(netcfg) + "\n", file_mode + ) +diff --git a/tests/unittests/distros/test_netconfig.py b/tests/unittests/distros/test_netconfig.py +index 962ff7f..27ac636 100644 +--- a/tests/unittests/distros/test_netconfig.py ++++ b/tests/unittests/distros/test_netconfig.py +@@ -697,12 +697,16 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): + return "/etc/sysconfig/network" + + def _apply_and_verify( +- self, apply_fn, config, expected_cfgs=None, bringup=False ++ self, ++ apply_fn, ++ config, ++ expected_cfgs=None, ++ bringup=False, ++ tmpd=None, + ): + if not expected_cfgs: + raise ValueError("expected_cfg must not be None") + +- tmpd = None + with mock.patch("cloudinit.net.sysconfig.available") as m_avail: + m_avail.return_value = True + with self.reRooted(tmpd) as tmpd: +@@ -791,6 +795,58 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase): + expected_cfgs=expected_cfgs.copy(), + ) + ++ def test_sysconfig_network_no_overwite_ipv6_rh(self): ++ expected_cfgs = { ++ self.ifcfg_path("eth0"): dedent( ++ """\ ++ BOOTPROTO=none ++ DEFROUTE=yes ++ DEVICE=eth0 ++ IPV6ADDR=2607:f0d0:1002:0011::2/64 ++ IPV6INIT=yes ++ IPV6_AUTOCONF=no ++ IPV6_DEFAULTGW=2607:f0d0:1002:0011::1 ++ IPV6_FORCE_ACCEPT_RA=no ++ ONBOOT=yes ++ TYPE=Ethernet ++ USERCTL=no ++ """ ++ ), ++ self.ifcfg_path("eth1"): dedent( ++ """\ ++ BOOTPROTO=dhcp ++ DEVICE=eth1 ++ ONBOOT=yes ++ TYPE=Ethernet ++ USERCTL=no ++ """ ++ ), ++ self.control_path(): dedent( ++ """\ ++ NETWORKING=yes ++ NETWORKING_IPV6=yes ++ IPV6_AUTOCONF=no ++ NOZEROCONF=yes ++ """ ++ ), ++ } ++ tmpdir = self.tmp_dir() ++ file_mode = 0o644 ++ # pre-existing config in /etc/sysconfig/network should not be removed ++ with self.reRooted(tmpdir) as tmpdir: ++ util.write_file( ++ self.control_path(), ++ "".join("NOZEROCONF=yes") + "\n", ++ file_mode, ++ ) ++ ++ self._apply_and_verify( ++ self.distro.apply_network_config, ++ V1_NET_CFG_IPV6, ++ expected_cfgs=expected_cfgs.copy(), ++ tmpd=tmpdir, ++ ) ++ + def test_vlan_render_unsupported(self): + """Render officially unsupported vlan names.""" + cfg = { +-- +2.33.0 + + diff --git a/cloud-init-22.1-no-override-default-network.patch b/cloud-init-22.1-no-override-default-network.patch deleted file mode 100644 index ed10281..0000000 --- a/cloud-init-22.1-no-override-default-network.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 5514d5922cbc92278868bfea587c4207619d81fc Mon Sep 17 00:00:00 2001 -From: Eduardo Otubo -Date: Thu, 3 Dec 2020 12:34:01 +0100 -Subject: [PATCH 3/3] Don't override default network configuration - -Signed-off-by: Eduardo Otubo ---- - cloudinit/net/sysconfig.py | 12 +++++++++++- - 1 file changed, 11 insertions(+), 1 deletion(-) - -diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py -index d934f66..8a60c95 100644 ---- a/cloudinit/net/sysconfig.py -+++ b/cloudinit/net/sysconfig.py -@@ -1025,7 +1025,17 @@ class Renderer(renderer.Renderer): - # Distros configuring /etc/sysconfig/network as a file e.g. Centos - if sysconfig_path.endswith("network"): - util.ensure_dir(os.path.dirname(sysconfig_path)) -- netcfg = [_make_header(), "NETWORKING=yes"] -+ # Make sure that existing lines, other than overriding ones, remain -+ netcfg = [] -+ for line in util.load_file(sysconfig_path, quiet=True).split('\n'): -+ if 'cloud-init' in line: -+ break -+ if not line.startswith(('NETWORKING=', -+ 'IPV6_AUTOCONF=', -+ 'NETWORKING_IPV6=')): -+ netcfg.append(line) -+ # Now generate the cloud-init portion of sysconfig/network -+ netcfg.extend([_make_header(), 'NETWORKING=yes']) - if network_state.use_ipv6: - netcfg.append("NETWORKING_IPV6=yes") - netcfg.append("IPV6_AUTOCONF=no") --- -2.27.0 - diff --git a/cloud-init.spec b/cloud-init.spec index b773a7a..07f7b3b 100644 --- a/cloud-init.spec +++ b/cloud-init.spec @@ -1,6 +1,6 @@ Name: cloud-init Version: 23.4.1 -Release: 13 +Release: 14 Summary: the defacto multi-distribution package that handles early initialization of a cloud instance. License: ASL 2.0 or GPLv3 URL: http://launchpad.net/cloud-init @@ -8,7 +8,6 @@ Source0: https://launchpad.net/%{name}/trunk/%{version}/+download/%{name}-%{vers Source1: cloud-init-tmpfiles.conf -Patch0: cloud-init-22.1-no-override-default-network.patch Patch2: bugfix-sort-requirements.patch Patch3: add-variable-to-forbid-tmp-dir.patch Patch5: Do-not-write-NM_CONTROLLED-no-in-generated-interface-config.patch @@ -40,6 +39,8 @@ Patch6024: backport-fix-Wait-for-udev-on-openstack-5947.patch Patch6025: backport-fix-correct-the-path-for-Chef-s-cache-5994.patch Patch6022: backport-Fix-GCE-_get_data-crashes-if-DHCP-lease-fails-5998.patch Patch6023: backport-fix-Ensure-fqdn-is-treated-as-string-in-get_hostname.patch +Patch6026: backport-fix-typing-for-rsyslog-power_state_change.patch +Patch6027: backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch Patch9000: do-not-generate-dsa.patch @@ -172,6 +173,12 @@ fi %exclude /usr/share/doc/* %changelog +* Tue Apr 01 2025 yixiangzhike - 23.4.1-14 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:backport upstream patches + * Wed Mar 05 2025 Linux_zhang - 23.4.1-13 - Type:bugfix - CVE:NA -- Gitee