Merge branch 'c9' into a9

This commit is contained in:
eabdullin 2022-09-20 11:45:24 +00:00 committed by Stepan Oksanichenko
commit 1e23b0bd1a
2 changed files with 150 additions and 2 deletions

View File

@ -0,0 +1,142 @@
From 2e3f17d06a61f4fa05abe186b30e6aba7e23d1ba Mon Sep 17 00:00:00 2001
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Date: Fri, 10 Jun 2022 20:59:09 +0200
Subject: [PATCH] Honor system locale for RHEL (#1355)
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
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 <vkuznets@redhat.com>
RH-Acked-by: Mohamed Gamal Morsy <mmorsy@redhat.com>
commit 58da7d856274e9ca2b507128d6f186e0e6abfe06
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
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 <shi2wei3@hotmail.com>
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 <eesposit@redhat.com>
---
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 <harlowja@yahoo-inc.com>
#
# 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

View File

@ -1,6 +1,6 @@
Name: cloud-init Name: cloud-init
Version: 21.1 Version: 21.1
Release: 19%{?dist}.3.alma Release: 19%{?dist}.4.alma
Summary: Cloud instance init scripts Summary: Cloud instance init scripts
License: ASL 2.0 or GPLv3 License: ASL 2.0 or GPLv3
URL: http://launchpad.net/cloud-init 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 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] # 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 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
# AlmaLinux patches # AlmaLinux patches
Patch100: cloud-init-20.3-add_almalinux.patch Patch100: cloud-init-20.3-add_almalinux.patch
@ -274,9 +276,13 @@ fi
%config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf %config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf
%changelog %changelog
* Tue Jun 28 2022 Eduard Abdullin <eabdullin@almalinux.org> - 21.1-19.el9_0.3.alma * Tue Sep 20 2022 Eduard Abdullin <eabdullin@almalinux.org> - 21.1-19.el9_0_0.4.alma
- AlmaLinux support - AlmaLinux support
* Tue Jun 28 2022 Miroslav Rezanina <mrezanin@redhat.com> - 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 <mrezanin@redhat.com> - 21.1-19.el9_0.3 * Wed Jun 08 2022 Miroslav Rezanina <mrezanin@redhat.com> - 21.1-19.el9_0.3
- ci-cc_set_hostname-do-not-write-localhost-when-no-hostn.patch [bz#2092909] - ci-cc_set_hostname-do-not-write-localhost-when-no-hostn.patch [bz#2092909]
- Resolves: bz#2092909 - Resolves: bz#2092909