Merge pull request #41336 from mcalmer/fix-locale-on-SUSE

fix setting and getting locale on SUSE systems
This commit is contained in:
Mike Place 2017-05-24 12:46:07 -05:00 committed by GitHub
commit 88fd3c0ed9
2 changed files with 31 additions and 27 deletions

View File

@ -127,13 +127,14 @@ def get_locale():
salt '*' locale.get_locale
'''
cmd = ''
if salt.utils.systemd.booted(__context__):
if 'Suse' in __grains__['os_family']:
# this block applies to all SUSE systems - also with systemd
cmd = 'grep "^RC_LANG" /etc/sysconfig/language'
elif salt.utils.systemd.booted(__context__):
params = _parse_dbus_locale() if HAS_DBUS else _parse_localectl()
return params.get('LANG', '')
elif 'RedHat' in __grains__['os_family']:
cmd = 'grep "^LANG=" /etc/sysconfig/i18n'
elif 'SUSE' in __grains__['os_family']:
cmd = 'grep "^RC_LANG" /etc/sysconfig/language'
elif 'Debian' in __grains__['os_family']:
# this block only applies to Debian without systemd
cmd = 'grep "^LANG=" /etc/default/locale'
@ -161,7 +162,17 @@ def set_locale(locale):
salt '*' locale.set_locale 'en_US.UTF-8'
'''
if salt.utils.systemd.booted(__context__):
if 'Suse' in __grains__['os_family']:
# this block applies to all SUSE systems - also with systemd
if not __salt__['file.file_exists']('/etc/sysconfig/language'):
__salt__['file.touch']('/etc/sysconfig/language')
__salt__['file.replace'](
'/etc/sysconfig/language',
'^RC_LANG=.*',
'RC_LANG="{0}"'.format(locale),
append_if_not_found=True
)
elif salt.utils.systemd.booted(__context__):
return _localectl_set(locale)
elif 'RedHat' in __grains__['os_family']:
if not __salt__['file.file_exists']('/etc/sysconfig/i18n'):
@ -172,15 +183,6 @@ def set_locale(locale):
'LANG="{0}"'.format(locale),
append_if_not_found=True
)
elif 'SUSE' in __grains__['os_family']:
if not __salt__['file.file_exists']('/etc/sysconfig/language'):
__salt__['file.touch']('/etc/sysconfig/language')
__salt__['file.replace'](
'/etc/sysconfig/language',
'^RC_LANG=.*',
'RC_LANG="{0}"'.format(locale),
append_if_not_found=True
)
elif 'Debian' in __grains__['os_family']:
# this block only applies to Debian without systemd
update_locale = salt.utils.which('update-locale')

View File

@ -44,6 +44,7 @@ class LocalemodTestCase(TestCase):
Test for Get the current system locale
'''
with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': True}):
with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
localemod.HAS_DBUS = True
with patch.object(localemod,
'_parse_dbus_locale',
@ -82,6 +83,7 @@ class LocalemodTestCase(TestCase):
Test for Sets the current system locale
'''
with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': True}):
with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
with patch.object(localemod, '_localectl_set', return_value=True):
self.assertTrue(localemod.set_locale('l'))