1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ModuleHelper - also uses LC_ALL to force language (#2731) (#2737)

* also uses LC_ALL to force language

* adjusted test_xfconf and test_cpanm

* added changelog fragment

* Update changelogs/fragments/2731-mh-cmd-locale.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* adjusted chglog frag per PR

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 6a41fba2f8)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
Felix Fontein 2021-06-08 10:54:46 +02:00 committed by GitHub
parent 6afde82f2c
commit 885bb73cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 18 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- module_helper module utils - ``CmdMixin`` must also use ``LC_ALL`` to enforce locale choice (https://github.com/ansible-collections/community.general/pull/2731).
- xfconf - also use ``LC_ALL`` to enforce locale choice (https://github.com/ansible-collections/community.general/issues/2715).

View file

@ -487,13 +487,16 @@ class CmdMixin(object):
def run_command(self, extra_params=None, params=None, *args, **kwargs): def run_command(self, extra_params=None, params=None, *args, **kwargs):
self.vars.cmd_args = self._calculate_args(extra_params, params) self.vars.cmd_args = self._calculate_args(extra_params, params)
options = dict(self.run_command_fixed_options) options = dict(self.run_command_fixed_options)
env_update = dict(options.get('environ_update', {}))
options['check_rc'] = options.get('check_rc', self.check_rc) options['check_rc'] = options.get('check_rc', self.check_rc)
options.update(kwargs)
env_update = dict(options.get('environ_update', {}))
if self.force_lang: if self.force_lang:
env_update.update({'LANGUAGE': self.force_lang}) env_update.update({
'LANGUAGE': self.force_lang,
'LC_ALL': self.force_lang,
})
self.update_output(force_lang=self.force_lang) self.update_output(force_lang=self.force_lang)
options['environ_update'] = env_update options['environ_update'] = env_update
options.update(kwargs)
rc, out, err = self.module.run_command(self.vars.cmd_args, *args, **options) rc, out, err = self.module.run_command(self.vars.cmd_args, *args, **options)
self.update_output(rc=rc, stdout=out, stderr=err) self.update_output(rc=rc, stdout=out, stderr=err)
return self.process_command_output(rc, out, err) return self.process_command_output(rc, out, err)

View file

@ -49,7 +49,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '100\n', '',), (0, '100\n', '',),
), ),
@ -69,7 +69,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/i_dont_exist'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/i_dont_exist'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(1, '', 'Property "/general/i_dont_exist" does not exist on channel "xfwm4".\n',), (1, '', 'Property "/general/i_dont_exist" does not exist on channel "xfwm4".\n',),
), ),
@ -89,7 +89,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'Value is an array with 3 items:\n\nMain\nWork\nTmp\n', '',), (0, 'Value is an array with 3 items:\n\nMain\nWork\nTmp\n', '',),
), ),
@ -109,7 +109,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/use_compositing'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/use_compositing'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'true', '',), (0, 'true', '',),
), ),
@ -129,7 +129,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/use_compositing'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/use_compositing'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'false', '',), (0, 'false', '',),
), ),
@ -155,7 +155,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '100\n', '',), (0, '100\n', '',),
), ),
@ -164,7 +164,7 @@ TEST_CASES = [
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity', ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity',
'--create', '--type', 'int', '--set', '90'], '--create', '--type', 'int', '--set', '90'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '', '',), (0, '', '',),
), ),
@ -190,7 +190,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '90\n', '',), (0, '90\n', '',),
), ),
@ -199,7 +199,7 @@ TEST_CASES = [
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity', ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/inactive_opacity',
'--create', '--type', 'int', '--set', '90'], '--create', '--type', 'int', '--set', '90'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '', '',), (0, '', '',),
), ),
@ -225,7 +225,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'Value is an array with 3 items:\n\nMain\nWork\nTmp\n', '',), (0, 'Value is an array with 3 items:\n\nMain\nWork\nTmp\n', '',),
), ),
@ -235,7 +235,7 @@ TEST_CASES = [
'--create', '--force-array', '--type', 'string', '--set', 'A', '--type', 'string', '--set', 'B', '--create', '--force-array', '--type', 'string', '--set', 'A', '--type', 'string', '--set', 'B',
'--type', 'string', '--set', 'C'], '--type', 'string', '--set', 'C'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '', '',), (0, '', '',),
), ),
@ -261,7 +261,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'Value is an array with 3 items:\n\nA\nB\nC\n', '',), (0, 'Value is an array with 3 items:\n\nA\nB\nC\n', '',),
), ),
@ -271,7 +271,7 @@ TEST_CASES = [
'--create', '--force-array', '--type', 'string', '--set', 'A', '--type', 'string', '--set', 'B', '--create', '--force-array', '--type', 'string', '--set', 'A', '--type', 'string', '--set', 'B',
'--type', 'string', '--set', 'C'], '--type', 'string', '--set', 'C'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '', '',), (0, '', '',),
), ),
@ -295,7 +295,7 @@ TEST_CASES = [
# Calling of following command will be asserted # Calling of following command will be asserted
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'], ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, 'Value is an array with 3 items:\n\nA\nB\nC\n', '',), (0, 'Value is an array with 3 items:\n\nA\nB\nC\n', '',),
), ),
@ -304,7 +304,7 @@ TEST_CASES = [
['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names', ['/testbin/xfconf-query', '--channel', 'xfwm4', '--property', '/general/workspace_names',
'--reset'], '--reset'],
# Was return code checked? # Was return code checked?
{'environ_update': {'LANGUAGE': 'C'}, 'check_rc': False}, {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
# Mock of returned code, stdout and stderr # Mock of returned code, stdout and stderr
(0, '', '',), (0, '', '',),
), ),