From 7285f365b81cc7db8c0559920d220f4236f408ae Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Tue, 20 Sep 2022 07:44:40 -0400 Subject: [PATCH] import cloud-init-21.1-19.el9_0.4 --- ...ci-Honor-system-locale-for-RHEL-1355.patch | 142 ++++++++++++++++++ SPECS/cloud-init.spec | 9 +- 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 SOURCES/ci-Honor-system-locale-for-RHEL-1355.patch diff --git a/SOURCES/ci-Honor-system-locale-for-RHEL-1355.patch b/SOURCES/ci-Honor-system-locale-for-RHEL-1355.patch new file mode 100644 index 0000000..61ea35e --- /dev/null +++ b/SOURCES/ci-Honor-system-locale-for-RHEL-1355.patch @@ -0,0 +1,142 @@ +From 2e3f17d06a61f4fa05abe186b30e6aba7e23d1ba Mon Sep 17 00:00:00 2001 +From: Emanuele Giuseppe Esposito +Date: Fri, 10 Jun 2022 20:59:09 +0200 +Subject: [PATCH] Honor system locale for RHEL (#1355) + +RH-Author: Emanuele Giuseppe Esposito +RH-MergeRequest: 78: Honor system locale for RHEL (#1355) +RH-Commit: [1/1] cf4e8ebe6828a05ec135cfbd58e54418aa28a02d (eesposit/cloud-init) +RH-Bugzilla: 2096196 +RH-Acked-by: Vitaly Kuznetsov +RH-Acked-by: Mohamed Gamal Morsy + +commit 58da7d856274e9ca2b507128d6f186e0e6abfe06 +Author: Emanuele Giuseppe Esposito +Date: Fri Jun 10 20:57:32 2022 +0200 + + Honor system locale for RHEL (#1355) + + Make sure to use system locale as default on RHEL if locale is not + set in cloud-config. + + RHEL has a pre-installed cloud image using C.UTF-8 for system locale + just like ubuntu-minimal cloud image, without this patch, locale + module will set it to en_US.UTF-8 from ds default value during config + stage. + + Authored-by: Wei Shi + +Conflicts: + cloudinit/distros/rhel.py: single quotes instead of double, and + _write_hostname also has out_fn parameter instead of filename + .github-cla-signers: names from other people not yet present + +Signed-off-by: Emanuele Giuseppe Esposito +--- + cloudinit/distros/rhel.py | 32 ++++++++++++++++++++ + tests/unittests/test_distros/test_generic.py | 10 +++--- + tools/.github-cla-signers | 1 + + 3 files changed, 39 insertions(+), 4 deletions(-) + +diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py +index c72f7c17..9fbfc3ce 100644 +--- a/cloudinit/distros/rhel.py ++++ b/cloudinit/distros/rhel.py +@@ -7,6 +7,7 @@ + # Author: Joshua Harlow + # + # This file is part of cloud-init. See LICENSE file for license information. ++import os + + from cloudinit import distros + from cloudinit import helpers +@@ -57,6 +58,8 @@ class Distro(distros.Distro): + # should only happen say once per instance...) + self._runner = helpers.Runners(paths) + self.osfamily = 'redhat' ++ self.default_locale = "en_US.UTF-8" ++ self.system_locale = None + cfg['ssh_svcname'] = 'sshd' + + def install_packages(self, pkglist): +@@ -65,6 +68,18 @@ class Distro(distros.Distro): + def _write_network_config(self, netconfig): + return self._supported_write_network_config(netconfig) + ++ def get_locale(self): ++ """Return the default locale if set, else use system locale""" ++ ++ # read system locale value ++ if not self.system_locale: ++ self.system_locale = self._read_system_locale() ++ ++ # Return system_locale setting if valid, else use default locale ++ return ( ++ self.system_locale if self.system_locale else self.default_locale ++ ) ++ + def apply_locale(self, locale, out_fn=None): + if self.uses_systemd(): + if not out_fn: +@@ -78,6 +93,23 @@ class Distro(distros.Distro): + } + rhel_util.update_sysconfig_file(out_fn, locale_cfg) + ++ def _read_system_locale(self, keyname="LANG"): ++ """Read system default locale setting, if present""" ++ if self.uses_systemd(): ++ locale_fn = self.systemd_locale_conf_fn ++ else: ++ locale_fn = self.locale_conf_fn ++ ++ if not locale_fn: ++ raise ValueError("Invalid path: %s" % locale_fn) ++ ++ if os.path.exists(locale_fn): ++ (_exists, contents) = rhel_util.read_sysconfig_file(locale_fn) ++ if keyname in contents: ++ return contents[keyname] ++ else: ++ return None ++ + def _write_hostname(self, hostname, out_fn): + # systemd will never update previous-hostname for us, so + # we need to do it ourselves +diff --git a/tests/unittests/test_distros/test_generic.py b/tests/unittests/test_distros/test_generic.py +index 336150bc..2c3cdc59 100644 +--- a/tests/unittests/test_distros/test_generic.py ++++ b/tests/unittests/test_distros/test_generic.py +@@ -174,12 +174,14 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase): + locale = d.get_locale() + self.assertEqual('C.UTF-8', locale) + +- def test_get_locale_rhel(self): +- """Test rhel distro returns NotImplementedError exception""" ++ @mock.patch("cloudinit.distros.rhel.Distro._read_system_locale") ++ def test_get_locale_rhel(self, m_locale): ++ """Test rhel distro returns locale set to C.UTF-8""" ++ m_locale.return_value = "C.UTF-8" + cls = distros.fetch("rhel") + d = cls("rhel", {}, None) +- with self.assertRaises(NotImplementedError): +- d.get_locale() ++ locale = d.get_locale() ++ self.assertEqual("C.UTF-8", locale) + + def test_expire_passwd_uses_chpasswd(self): + """Test ubuntu.expire_passwd uses the passwd command.""" +diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers +index cbfa883c..c58761d4 100644 +--- a/tools/.github-cla-signers ++++ b/tools/.github-cla-signers +@@ -34,6 +34,7 @@ omBratteng + onitake + qubidt + riedel ++shi2wei3 + slyon + smoser + sshedi +-- +2.31.1 + diff --git a/SPECS/cloud-init.spec b/SPECS/cloud-init.spec index 3580913..caa543f 100644 --- a/SPECS/cloud-init.spec +++ b/SPECS/cloud-init.spec @@ -1,6 +1,6 @@ Name: cloud-init Version: 21.1 -Release: 19%{?dist}.3 +Release: 19%{?dist}.4 Summary: Cloud instance init scripts License: ASL 2.0 or GPLv3 URL: http://launchpad.net/cloud-init @@ -70,6 +70,8 @@ Patch31: ci-Add-r-n-check-for-SSH-keys-in-Azure-889.patch Patch32: ci-Leave-the-details-of-service-management-to-the-distr.patch # For bz#2092909 - [RHV] RHEL 9 VM with cloud-init without hostname set doesn't result in the FQDN as hostname [rhel-9.0.0.z] Patch33: ci-cc_set_hostname-do-not-write-localhost-when-no-hostn.patch +# For bz#2096196 - cloud-config will change /etc/locale.conf back to en_US.UTF-8 on rhel-guest-image-9.0 [rhel-9.0.0.z] +Patch34: ci-Honor-system-locale-for-RHEL-1355.patch # Source-git patches @@ -271,6 +273,11 @@ fi %config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf %changelog +* Tue Jun 28 2022 Miroslav Rezanina - 21.1-19.el9_0_0.4 +- ci-Honor-system-locale-for-RHEL-1355.patch [bz#2096196] +- Resolves: bz#2096196 + (cloud-config will change /etc/locale.conf back to en_US.UTF-8 on rhel-guest-image-9.0 [rhel-9.0.0.z]) + * Wed Jun 08 2022 Miroslav Rezanina - 21.1-19.el9_0.3 - ci-cc_set_hostname-do-not-write-localhost-when-no-hostn.patch [bz#2092909] - Resolves: bz#2092909