From 5eb97f097352a40da2a30337d8362729c959e401 Mon Sep 17 00:00:00 2001 From: Justin Findlay Date: Fri, 22 May 2015 10:48:30 -0600 Subject: [PATCH] if a charmap is not supplied, set it to the codeset Fixes #23221. --- salt/modules/localemod.py | 5 ++++ tests/unit/modules/localemod_test.py | 45 +++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/salt/modules/localemod.py b/salt/modules/localemod.py index 4307139a6d..6229c70c4b 100644 --- a/salt/modules/localemod.py +++ b/salt/modules/localemod.py @@ -261,6 +261,11 @@ def gen_locale(locale, **kwargs): if on_debian or on_gentoo: # file-based search search = '/usr/share/i18n/SUPPORTED' valid = __salt__['file.search'](search, '^{0}$'.format(locale)) + if not valid and not locale_info['charmap']: + # charmap was not supplied, so try copying the codeset + locale_info['charmap'] = locale_info['codeset'] + locale = _join_locale(locale_info) + valid = __salt__['file.search'](search, '^{0}$'.format(locale)) else: # directory-based search if on_suse: search = '/usr/share/locale' diff --git a/tests/unit/modules/localemod_test.py b/tests/unit/modules/localemod_test.py index 765d1e0269..225bd127a3 100644 --- a/tests/unit/modules/localemod_test.py +++ b/tests/unit/modules/localemod_test.py @@ -109,6 +109,28 @@ class LocalemodTestCase(TestCase): 'cmd.run_all': MagicMock(return_value=ret)}): self.assertTrue(localemod.gen_locale('en_US.UTF-8 UTF-8')) + @patch('salt.utils.which', MagicMock(return_value='/some/dir/path')) + def test_gen_locale_debian_no_charmap(self): + ''' + Tests the return of successful gen_locale on Debian system without a charmap + ''' + def file_search(search, pattern): + ''' + mock file.search + ''' + if len(pattern.split()) == 1: + return False + else: # charmap was supplied + return True + + ret = {'stdout': 'saltines', 'stderr': 'biscuits', 'retcode': 0, 'pid': 1337} + with patch.dict(localemod.__grains__, {'os': 'Debian'}): + with patch.dict(localemod.__salt__, + {'file.search': file_search, + 'file.replace': MagicMock(return_value=True), + 'cmd.run_all': MagicMock(return_value=ret)}): + self.assertTrue(localemod.gen_locale('en_US.UTF-8')) + @patch('salt.utils.which', MagicMock(return_value='/some/dir/path')) @patch('os.listdir', MagicMock(return_value=['en_US'])) def test_gen_locale_ubuntu(self): @@ -124,7 +146,6 @@ class LocalemodTestCase(TestCase): with patch.dict(localemod.__grains__, {'os': 'Ubuntu'}): self.assertTrue(localemod.gen_locale('en_US.UTF-8')) - @patch('salt.utils.which', MagicMock(return_value='/some/dir/path')) @patch('os.listdir', MagicMock(return_value=['en_US.UTF-8'])) def test_gen_locale_gentoo(self): ''' @@ -138,6 +159,28 @@ class LocalemodTestCase(TestCase): 'cmd.run_all': MagicMock(return_value=ret)}): self.assertTrue(localemod.gen_locale('en_US.UTF-8 UTF-8')) + @patch('os.listdir', MagicMock(return_value=['en_US.UTF-8'])) + def test_gen_locale_gentoo_no_charmap(self): + ''' + Tests the return of successful gen_locale on Gentoo system without a charmap + ''' + def file_search(search, pattern): + ''' + mock file.search + ''' + if len(pattern.split()) == 1: + return False + else: # charmap was supplied + return True + + ret = {'stdout': 'saltines', 'stderr': 'biscuits', 'retcode': 0, 'pid': 1337} + with patch.dict(localemod.__grains__, {'os_family': 'Gentoo'}): + with patch.dict(localemod.__salt__, + {'file.search': file_search, + 'file.replace': MagicMock(return_value=True), + 'cmd.run_all': MagicMock(return_value=ret)}): + self.assertTrue(localemod.gen_locale('en_US.UTF-8')) + @patch('salt.utils.which', MagicMock(return_value='/some/dir/path')) @patch('os.listdir', MagicMock(return_value=['en_US'])) def test_gen_locale(self):