From 152339a8f9e7c3986399b7c4eeab86a617d0ae54 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 24 Nov 2024 03:03:56 +1300 Subject: [PATCH] gio_mime: fix bug when looking for version (#9171) * gio_mime: fix bug when looking for version * add changelog frag --- changelogs/fragments/9171-gio-mime-fix-version.yml | 2 ++ plugins/module_utils/gio_mime.py | 5 +++-- plugins/modules/gio_mime.py | 5 ++--- tests/unit/plugins/modules/test_gio_mime.yaml | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/9171-gio-mime-fix-version.yml diff --git a/changelogs/fragments/9171-gio-mime-fix-version.yml b/changelogs/fragments/9171-gio-mime-fix-version.yml new file mode 100644 index 00000000000..ca9dbddd7fa --- /dev/null +++ b/changelogs/fragments/9171-gio-mime-fix-version.yml @@ -0,0 +1,2 @@ +bugfixes: + - gio_mime - fix command line when determining version of ``gio`` (https://github.com/ansible-collections/community.general/pull/9171, https://github.com/ansible-collections/community.general/issues/9158). diff --git a/plugins/module_utils/gio_mime.py b/plugins/module_utils/gio_mime.py index 132981a3399..c734e13a816 100644 --- a/plugins/module_utils/gio_mime.py +++ b/plugins/module_utils/gio_mime.py @@ -12,8 +12,9 @@ def gio_mime_runner(module, **kwargs): return CmdRunner( module, - command=['gio', 'mime'], + command=['gio'], arg_formats=dict( + mime=cmd_runner_fmt.as_fixed('mime'), mime_type=cmd_runner_fmt.as_list(), handler=cmd_runner_fmt.as_list(), version=cmd_runner_fmt.as_fixed('--version'), @@ -29,5 +30,5 @@ def process(rc, out, err): out = out.splitlines()[0] return out.split()[-1] - with runner("mime_type", output_process=process) as ctx: + with runner("mime mime_type", output_process=process) as ctx: return ctx.run(mime_type=mime_type) diff --git a/plugins/modules/gio_mime.py b/plugins/modules/gio_mime.py index 587aaec4278..a3b340b677e 100644 --- a/plugins/modules/gio_mime.py +++ b/plugins/modules/gio_mime.py @@ -108,12 +108,11 @@ def __init_module__(self): def __run__(self): check_mode_return = (0, 'Module executed in check mode', '') if self.vars.has_changed: - with self.runner.context(args_order=["mime_type", "handler"], check_mode_skip=True, check_mode_return=check_mode_return) as ctx: + with self.runner.context(args_order="mime mime_type handler", check_mode_skip=True, check_mode_return=check_mode_return) as ctx: rc, out, err = ctx.run() self.vars.stdout = out self.vars.stderr = err - if self.verbosity >= 4: - self.vars.run_info = ctx.run_info + self.vars.set("run_info", ctx.run_info, verbosity=4) def main(): diff --git a/tests/unit/plugins/modules/test_gio_mime.yaml b/tests/unit/plugins/modules/test_gio_mime.yaml index f71e5957017..36454462918 100644 --- a/tests/unit/plugins/modules/test_gio_mime.yaml +++ b/tests/unit/plugins/modules/test_gio_mime.yaml @@ -13,7 +13,7 @@ changed: true mocks: run_command: - - command: [/testbin/gio, mime, --version] + - command: [/testbin/gio, --version] environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} rc: 0 out: "2.80.0\n" @@ -40,7 +40,7 @@ skip: test helper does not support check mode yet mocks: run_command: - - command: [/testbin/gio, mime, --version] + - command: [/testbin/gio, --version] environ: *env-def rc: 0 out: "2.80.0\n" @@ -65,7 +65,7 @@ changed: false mocks: run_command: - - command: [/testbin/gio, mime, --version] + - command: [/testbin/gio, --version] environ: *env-def rc: 0 out: "2.80.0\n"