From 377e34c6895779d08ef780721277d83b61ae8444 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 25 May 2018 10:37:00 -0700 Subject: [PATCH 1/3] Updating function in saltmod to ensure that the result is a failure if the function being run returns as False. --- salt/states/saltmod.py | 3 +++ tests/integration/runners/test_state.py | 26 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/salt/states/saltmod.py b/salt/states/saltmod.py index 39f19ac1a2..3e2306f7c6 100644 --- a/salt/states/saltmod.py +++ b/salt/states/saltmod.py @@ -581,6 +581,9 @@ def function( m_ret = mdata['ret'] m_func = (not fail_function and True) or __salt__[fail_function](m_ret) + if m_ret is False: + m_func = False + if not m_func: if minion not in fail_minions: fail.add(minion) diff --git a/tests/integration/runners/test_state.py b/tests/integration/runners/test_state.py index ee7e81b262..4c214ef4cc 100644 --- a/tests/integration/runners/test_state.py +++ b/tests/integration/runners/test_state.py @@ -257,6 +257,32 @@ class StateRunnerTest(ShellCase): self.assertEqual(count('Succeeded: 1', ret), 1) self.assertEqual(count('Failed: 0', ret), 1) + def test_orchestrate_salt_function_return_false_failure(self): + ''' + Ensure that functions that only return False in the return + are flagged as failed when run as orchestrations. + + See https://github.com/saltstack/salt/issues/30367 + ''' + self.run_run('saltutil.sync_modules') + ret = salt.utils.json.loads( + '\n'.join( + self.run_run('state.orchestrate orch.issue30367 --out=json') + ) + ) + # Drill down to the changes dict + state_result = ret['data']['master']['salt_|-deploy_check_|-test.false_|-function']['result'] + func_ret = ret['data']['master']['salt_|-deploy_check_|-test.false_|-function']['changes'] + + self.assertEqual( + state_result, + False, + ) + + self.assertEqual( + func_ret, + {'out': 'highstate', 'ret': {'minion': False}} + ) @skipIf(salt.utils.platform.is_windows(), '*NIX-only test') class OrchEventTest(ShellCase): From 02609b6e61f05926470444fffbf3f266abdb7550 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Fri, 25 May 2018 14:54:14 -0700 Subject: [PATCH 2/3] Adding state files for new test. --- tests/integration/files/file/base/orch/issue30367/init.sls | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/integration/files/file/base/orch/issue30367/init.sls diff --git a/tests/integration/files/file/base/orch/issue30367/init.sls b/tests/integration/files/file/base/orch/issue30367/init.sls new file mode 100644 index 0000000000..a1e404b2be --- /dev/null +++ b/tests/integration/files/file/base/orch/issue30367/init.sls @@ -0,0 +1,4 @@ +deploy_check: + salt.function: + - name: test.false + - tgt: minion From 3e074be9c3cacb827452cbbd1cec736715d47b3e Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 28 May 2018 09:36:10 -0700 Subject: [PATCH 3/3] Fixing lint --- tests/integration/runners/test_state.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/runners/test_state.py b/tests/integration/runners/test_state.py index 4c214ef4cc..879b011f4c 100644 --- a/tests/integration/runners/test_state.py +++ b/tests/integration/runners/test_state.py @@ -284,6 +284,7 @@ class StateRunnerTest(ShellCase): {'out': 'highstate', 'ret': {'minion': False}} ) + @skipIf(salt.utils.platform.is_windows(), '*NIX-only test') class OrchEventTest(ShellCase): '''