Skip to content

Commit

Permalink
Revert "move_dep_from_module_run (#58701)"
Browse files Browse the repository at this point in the history
This reverts commit 8813cf2.
  • Loading branch information
cmcmarrow authored Oct 9, 2020
1 parent 8813cf2 commit ba35374
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions salt/states/module.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
r"""
Execution of Salt modules from within states
============================================
Expand Down Expand Up @@ -299,13 +300,17 @@ def bar(name, names, fun, state, saltenv):
.. _file_roots: https://docs.saltstack.com/en/latest/ref/configuration/master.html#file-roots
"""
from __future__ import absolute_import, print_function, unicode_literals

# Import salt libs
import salt.loader
import salt.utils.args
import salt.utils.functools
import salt.utils.jid
from salt.exceptions import SaltInvocationError
from salt.ext import six
from salt.ext.six.moves import range
from salt.utils.decorators import with_deprecated


def wait(name, **kwargs):
Expand Down Expand Up @@ -337,6 +342,7 @@ def wait(name, **kwargs):
watch = salt.utils.functools.alias_function(wait, "watch")


@with_deprecated(globals(), "Phosphorus", policy=with_deprecated.OPT_IN)
def run(**kwargs):
"""
Run a single module function or a range of module functions in a batch.
Expand Down Expand Up @@ -422,13 +428,13 @@ def run(**kwargs):
if not _get_result(func_ret, ret["changes"].get("ret", {})):
if isinstance(func_ret, dict):
failures.append(
"'{}' failed: {}".format(
"'{0}' failed: {1}".format(
func, func_ret.get("comment", "(error message N/A)")
)
)
else:
success.append(
"{}: {}".format(
"{0}: {1}".format(
func,
func_ret.get("comment", "Success")
if isinstance(func_ret, dict)
Expand All @@ -437,7 +443,7 @@ def run(**kwargs):
)
ret["changes"][func] = func_ret
except (SaltInvocationError, TypeError) as ex:
failures.append("'{}' failed: {}".format(func, ex))
failures.append("'{0}' failed: {1}".format(func, ex))
ret["comment"] = ", ".join(failures + success)
ret["result"] = not bool(failures)

Expand Down Expand Up @@ -493,12 +499,12 @@ def _run(name, **kwargs):
"""
ret = {"name": name, "changes": {}, "comment": "", "result": None}
if name not in __salt__:
ret["comment"] = "Module function {} is not available".format(name)
ret["comment"] = "Module function {0} is not available".format(name)
ret["result"] = False
return ret

if __opts__["test"]:
ret["comment"] = "Module function {} is set to execute".format(name)
ret["comment"] = "Module function {0} is set to execute".format(name)
return ret

aspec = salt.utils.args.get_function_argspec(__salt__[name])
Expand Down Expand Up @@ -556,7 +562,7 @@ def _run(name, **kwargs):
if missing:
comment = "The following arguments are missing:"
for arg in missing:
comment += " {}".format(arg)
comment += " {0}".format(arg)
ret["comment"] = comment
ret["result"] = False
return ret
Expand Down Expand Up @@ -601,9 +607,9 @@ def _run(name, **kwargs):
else:
mret = __salt__[name](*args)
except Exception as e: # pylint: disable=broad-except
ret["comment"] = "Module function {} threw an exception. Exception: {}".format(
name, e
)
ret[
"comment"
] = "Module function {0} threw an exception. Exception: {1}".format(name, e)
ret["result"] = False
return ret
else:
Expand All @@ -620,7 +626,7 @@ def _run(name, **kwargs):
returners = salt.loader.returners(__opts__, __salt__)
if kwargs["returner"] in returners:
returners[kwargs["returner"]](ret_ret)
ret["comment"] = "Module function {} executed".format(name)
ret["comment"] = "Module function {0} executed".format(name)
ret["result"] = _get_result(mret, ret["changes"])

return ret
Expand Down Expand Up @@ -652,7 +658,7 @@ def _get_result(func_ret, changes):

def _get_dict_result(node):
ret = True
for key, val in node.items():
for key, val in six.iteritems(node):
if key == "result" and val is False:
ret = False
break
Expand Down

0 comments on commit ba35374

Please sign in to comment.