backport upstream patches

(cherry picked from commit 5bed85e0936d1fd9f105d1e2db114efb057b7daf)
This commit is contained in:
Linux_zhang 2025-03-18 16:43:27 +08:00 committed by openeuler-sync-bot
parent 62b77b231b
commit ba62202f37
4 changed files with 220 additions and 38 deletions

View File

@ -0,0 +1,67 @@
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)
Conflict: (1) not change
cloudinit/config/cc_ubuntu_pro.py,pyproject.toml,tests/unittests/config/test_cc_rsyslog.py
and tests/unittests/config/test_cc_ubuntu_pro.py
(2) change test_handler/test_handler_power_state.py not
config/test_cc_power_state_change.py
---
cloudinit/config/cc_power_state_change.py | 5 ++++-
cloudinit/config/cc_rsyslog.py | 5 +----
tests/unittests/test_handler/test_handler_power_state.py | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 5780a7e..9665e9a 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -78,7 +78,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 dd2bbd0..b27a54c 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -333,10 +333,7 @@ class SyslogRemotesLine(object):
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/test_handler/test_handler_power_state.py b/tests/unittests/test_handler/test_handler_power_state.py
index 4ac4942..ed953d0 100644
--- a/tests/unittests/test_handler/test_handler_power_state.py
+++ b/tests/unittests/test_handler/test_handler_power_state.py
@@ -42,7 +42,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)
--
2.33.0

View File

@ -0,0 +1,144 @@
From fa331315d22f4bbe33320485e89a02bb2f695fbf Mon Sep 17 00:00:00 2001
From: Ani Sinha <anisinha@redhat.com>
Date: Sat, 15 Feb 2025 01:54:31 +0530
Subject: [PATCH] net/sysconfig: do not remove all existing settings of
/etc/sysconfig/network (#5991)
Conflict:(1) use util.load_file not util.load_text_file in
render_network_state().
(2)test format diff.
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 <anisinha@redhat.com>
---
cloudinit/net/sysconfig.py | 18 ++++++
.../unittests/test_distros/test_netconfig.py | 63 ++++++++++++++++++-
2 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
index 7135ecf..c030e41 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -970,6 +970,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/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 3f82d54..69cc26f 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -528,12 +528,17 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
def control_path(self):
return '/etc/sysconfig/network'
- def _apply_and_verify(self, apply_fn, config, expected_cfgs=None,
- bringup=False):
+ def _apply_and_verify(
+ 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:
@@ -606,6 +611,58 @@ class TestNetCfgDistroRedhat(TestNetCfgDistroBase):
V1_NET_CFG_IPV6,
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

View File

@ -1,36 +0,0 @@
From 5514d5922cbc92278868bfea587c4207619d81fc Mon Sep 17 00:00:00 2001
From: Eduardo Otubo <otubo@redhat.com>
Date: Thu, 3 Dec 2020 12:34:01 +0100
Subject: [PATCH 3/3] Don't override default network configuration
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
---
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 9c822c3e..a240f65e 100644
--- a/cloudinit/net/sysconfig.py
+++ b/cloudinit/net/sysconfig.py
@@ -918,7 +918,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

View File

@ -1,6 +1,6 @@
Name: cloud-init
Version: 21.4
Release: 33
Release: 34
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
@ -9,7 +9,6 @@ Source0: https://launchpad.net/%{name}/trunk/%{version}/+download/%{name}-%{vers
Source1: cloud-init-tmpfiles.conf
Patch0: cloud-init-20.4-nm-controlled.patch
Patch1: cloud-init-20.4-no-override-default-network.patch
Patch2: bugfix-cloud-init-add-os-support.patch
Patch3: bugfix-sort-requirements.patch
Patch4: add-variable-to-forbid-tmp-dir.patch
@ -91,6 +90,8 @@ Patch6056: backport-fix-Wait-for-udev-on-openstack-5947.patch
Patch6057: backport-fix-correct-the-path-for-Chef-s-cache-5994.patch
Patch6058: backport-Fix-GCE-_get_data-crashes-if-DHCP-lease-fails-5998.patch
Patch6059: backport-fix-Ensure-fqdn-is-treated-as-string-in-get_hostname.patch
Patch6060: backport-net-sysconfig-do-not-remove-all-existing-settings-of.patch
Patch6061: backport-fix-typing-for-rsyslog-ubuntu_pro-power_state_change.patch
BuildRequires: pkgconfig(systemd) python3-devel python3-setuptools systemd
BuildRequires: iproute python3-configobj python3-httpretty >= 0.8.14-2
@ -225,6 +226,12 @@ fi
%exclude /usr/share/doc/*
%changelog
* Tue Mar 18 2025 Linux_zhang <zhangruifang@h-partners.com> - 21.4-34
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:backport upstream patches
* Wed Mar 05 2025 Linux_zhang <zhangruifang@h-partners.com> - 21.4-33
- Type:bugfix
- CVE:NA