salt/tests/integration/modules/test_localemod.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
3 KiB
Python
Raw Normal View History

import subprocess
import pytest
import salt.utils.platform
from tests.support.case import ModuleCase
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["localectl"], capture_output=True, check=False)
_check_systemctl.memo = b"No such file or directory" in proc.stderr
return _check_systemctl.memo
@pytest.mark.skip_on_windows(reason="minion is windows")
@pytest.mark.skip_on_darwin(reason="locale method is not supported on mac")
@pytest.mark.skip_on_freebsd(
reason="locale method is supported only within login classes or environment variables"
2020-08-10 10:40:37 +02:00
)
@pytest.mark.skipif(_check_systemctl(), reason="localectl degraded")
@pytest.mark.requires_salt_modules("locale")
@pytest.mark.windows_whitelisted
class LocaleModuleTest(ModuleCase):
2020-11-06 14:24:50 -05:00
def _find_new_locale(self, current_locale):
test_locales = ["en_US.UTF-8", "de_DE.UTF-8", "fr_FR.UTF-8", "en_AU.UTF-8"]
for locale in test_locales:
if locale != current_locale and self.run_function("locale.avail", [locale]):
return locale
self.skipTest(
"The test locals: {} do not exist on the host. Skipping test.".format(
",".join(test_locales)
)
)
def test_get_locale(self):
locale = self.run_function("locale.get_locale")
self.assertNotIn("Unsupported platform!", locale)
2024-03-14 20:47:19 +00:00
@pytest.mark.timeout_unless_on_windows(120)
@pytest.mark.destructive_test
@pytest.mark.slow_test
def test_gen_locale(self):
# Make sure charmaps are available on test system before attempting
# call gen_locale. We log this error to the user in the function, but
# we don't want to fail this test if this is missing on the test system.
char_maps = self.run_function("cmd.run_all", ["locale -m"])
if char_maps["stdout"] == "":
self.skipTest("locale charmaps not available. Skipping test.")
2020-04-02 20:10:20 -05:00
if char_maps["retcode"] and char_maps["stderr"]:
self.skipTest(
2020-08-10 10:40:37 +02:00
"{}. Cannot generate locale. Skipping test.".format(char_maps["stderr"])
)
locale = self.run_function("locale.get_locale")
2020-11-06 14:24:50 -05:00
new_locale = self._find_new_locale(locale)
ret = self.run_function("locale.gen_locale", [new_locale])
self.assertTrue(ret)
@pytest.mark.destructive_test
@pytest.mark.slow_test
2025-01-09 14:37:04 -07:00
@pytest.mark.skipif(_check_systemctl(), reason="systemd degraded")
def test_set_locale(self):
original_locale = self.run_function("locale.get_locale")
2020-11-06 14:24:50 -05:00
locale_to_set = self._find_new_locale(original_locale)
self.run_function("locale.gen_locale", [locale_to_set])
ret = self.run_function("locale.set_locale", [locale_to_set])
new_locale = self.run_function("locale.get_locale")
self.assertTrue(ret)
self.assertEqual(locale_to_set, new_locale)
self.run_function("locale.set_locale", [original_locale])