From 9ce55f7e940959a6a04fab51ab5c4c98da260c02 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 21 Jun 2018 07:52:24 +1000 Subject: [PATCH] win_updates fix when win_updates is run with async (#41756) (cherry picked from commit 11bd3fd318244264e8dbb95ce1412d9817e53fbe) --- .../fragments/win_updates-async-fix.yml | 2 + lib/ansible/plugins/action/win_updates.py | 2 +- test/units/plugins/action/test_win_updates.py | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/win_updates-async-fix.yml diff --git a/changelogs/fragments/win_updates-async-fix.yml b/changelogs/fragments/win_updates-async-fix.yml new file mode 100644 index 00000000000..3ce4c38adf3 --- /dev/null +++ b/changelogs/fragments/win_updates-async-fix.yml @@ -0,0 +1,2 @@ +bugfixes: +- win_updates - Fixed issue where running win_updates on async fails without any error diff --git a/lib/ansible/plugins/action/win_updates.py b/lib/ansible/plugins/action/win_updates.py index 5c12a51e23d..2d8adc44b52 100644 --- a/lib/ansible/plugins/action/win_updates.py +++ b/lib/ansible/plugins/action/win_updates.py @@ -213,7 +213,7 @@ class ActionModule(ActionBase): # so we just return the result as is # https://github.com/ansible/ansible/issues/38232 failed = result.get('failed', False) - if "updates" not in result.keys() or failed: + if ("updates" not in result.keys() and self._task.async_val == 0) or failed: result['failed'] = True return result diff --git a/test/units/plugins/action/test_win_updates.py b/test/units/plugins/action/test_win_updates.py index 15016e752ea..340fe9b950c 100644 --- a/test/units/plugins/action/test_win_updates.py +++ b/test/units/plugins/action/test_win_updates.py @@ -118,3 +118,40 @@ class TestWinUpdatesActionPlugin(object): assert actual['become'] == e_b assert actual['become_method'] == e_bmethod assert actual['become_user'] == e_buser + + def test_module_exec_async_result(self, monkeypatch): + return_val = { + "ansible_async_watchdog_pid": 7584, + "ansible_job_id": "545519115287.9620", + "changed": True, + "finished": 0, + "results_file": r"C:\.ansible_async\545519115287.9620", + "started": 1 + } + mock_execute = MagicMock(return_value=return_val) + monkeypatch.setattr(ActionModule, '_execute_module', mock_execute) + + task = MagicMock(Task) + task.args = {} + task.async_val = 10 + + connection = MagicMock() + connection.module_implementation_preferences = ('.ps1', '.exe', '') + + play_context = MagicMock() + play_context.check_mode = False + play_context.become = True + play_context.become_method = 'runas' + play_context.become_user = 'SYSTEM' + + plugin = ActionModule(task, connection, play_context, loader=None, + templar=None, shared_loader_obj=None) + actual = plugin.run(None, {}) + + assert actual.get('failed') is None + assert actual['ansible_async_watchdog_pid'] == 7584 + assert actual['ansible_job_id'] == "545519115287.9620" + assert actual['changed'] is True + assert actual['finished'] == 0 + assert actual['results_file'] == r"C:\.ansible_async\545519115287.9620" + assert actual['started'] == 1