summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Klausen <kristian@klausen.dk>2021-03-15 20:30:03 +0100
committerGitHub <noreply@github.com>2021-03-15 14:30:03 -0500
commit3aeb14cd46613b97afefc4632909f6e9b83d0230 (patch)
tree591f52bf5800f63b3e9db00ce711e812b4d5f3cf
parentd95b448fe106146b7510f7b64f2e83c51943f04d (diff)
downloadcloud-init-git-3aeb14cd46613b97afefc4632909f6e9b83d0230.tar.gz
archlinux: Fix broken locale logic (#841)
The locale wasn't persisted correct nor set. LP: #1402406
-rw-r--r--cloudinit/distros/arch.py18
-rw-r--r--tests/unittests/test_handler/test_handler_locale.py23
2 files changed, 34 insertions, 7 deletions
diff --git a/cloudinit/distros/arch.py b/cloudinit/distros/arch.py
index 5f42a24c..f8385f7f 100644
--- a/cloudinit/distros/arch.py
+++ b/cloudinit/distros/arch.py
@@ -23,7 +23,7 @@ LOG = logging.getLogger(__name__)
class Distro(distros.Distro):
- locale_conf_fn = "/etc/locale.gen"
+ locale_gen_fn = "/etc/locale.gen"
network_conf_dir = "/etc/netctl"
resolve_conf_fn = "/etc/resolv.conf"
init_cmd = ['systemctl'] # init scripts
@@ -43,16 +43,20 @@ class Distro(distros.Distro):
cfg['ssh_svcname'] = 'sshd'
def apply_locale(self, locale, out_fn=None):
- if not out_fn:
- out_fn = self.locale_conf_fn
- subp.subp(['locale-gen', '-G', locale], capture=False)
- # "" provides trailing newline during join
+ if out_fn is not None and out_fn != "/etc/locale.conf":
+ LOG.warning("Invalid locale_configfile %s, only supported "
+ "value is /etc/locale.conf", out_fn)
lines = [
util.make_header(),
- 'LANG="%s"' % (locale),
+ # Hard-coding the charset isn't ideal, but there is no other way.
+ '%s UTF-8' % (locale),
"",
]
- util.write_file(out_fn, "\n".join(lines))
+ util.write_file(self.locale_gen_fn, "\n".join(lines))
+ subp.subp(['locale-gen'], capture=False)
+ # In the future systemd can handle locale-gen stuff:
+ # https://github.com/systemd/systemd/pull/9864
+ subp.subp(['localectl', 'set-locale', locale], capture=False)
def install_packages(self, pkglist):
self.update_package_sources()
diff --git a/tests/unittests/test_handler/test_handler_locale.py b/tests/unittests/test_handler/test_handler_locale.py
index 47e7d804..15fe7b23 100644
--- a/tests/unittests/test_handler/test_handler_locale.py
+++ b/tests/unittests/test_handler/test_handler_locale.py
@@ -44,6 +44,29 @@ class TestLocale(t_help.FilesystemMockingTestCase):
cc = cloud.Cloud(ds, paths, {}, d, None)
return cc
+ def test_set_locale_arch(self):
+ locale = 'en_GB.UTF-8'
+ locale_configfile = '/etc/invalid-locale-path'
+ cfg = {
+ 'locale': locale,
+ 'locale_configfile': locale_configfile,
+ }
+ cc = self._get_cloud('arch')
+
+ with mock.patch('cloudinit.distros.arch.subp.subp') as m_subp:
+ with mock.patch('cloudinit.distros.arch.LOG.warning') as m_LOG:
+ cc_locale.handle('cc_locale', cfg, cc, LOG, [])
+ m_LOG.assert_called_with('Invalid locale_configfile %s, '
+ 'only supported value is '
+ '/etc/locale.conf',
+ locale_configfile)
+
+ contents = util.load_file(cc.distro.locale_gen_fn)
+ self.assertIn('%s UTF-8' % locale, contents)
+ m_subp.assert_called_with(['localectl',
+ 'set-locale',
+ locale], capture=False)
+
def test_set_locale_sles(self):
cfg = {