[develop] Ability to override retcode from various cmdmod functions#45851
Conversation
salt/modules/cmdmod.py
Outdated
There was a problem hiding this comment.
extra space between code and returned.
salt/modules/cmdmod.py
Outdated
There was a problem hiding this comment.
"overridden" seems like the wrong word here. "replaced" maybe?
salt/modules/cmdmod.py
Outdated
There was a problem hiding this comment.
In many places in salt we support both a Python and comma-separated list. We have a helper function for this, salt.utils.args.split_input(), which would be a good fit here.
Also , I noticed that there is a similar block below. How about moving the evaluation of success_exit_codes up higher in the function and doing something like this:
if success_exit_codes is None:
success_exit_codes = [0]
else:
try:
success_exit_codes = [int(i) for i in salt.utils.args.split_input(success_exit_codes)]
except ValueError:
raise SaltInvocationError(
'success_exit_codes must be a list of integers'
)Then you could just do a simple membership check:
if ret['retcode'] in success_exit_codes:There was a problem hiding this comment.
I'm also wondering if maybe this should be called success_retcodes instead of success_exit_codes. We already use retcode everywhere else in cmdmod.py to refer to the exit code of a command, so it may make sense to rename this for clarity/consistency.
salt/modules/cmdmod.py
Outdated
There was a problem hiding this comment.
NOTE: The above two comments should be addressed in all places in the docstrings where they were copied.
…code that is returned. This is useful when a command will return a non-zero retcode but the command is still considered successful.
988923b to
80c0636
Compare
What does this PR do?
Adding a flag to various
cmdmodfunctions to allow overriding theretcodethat is returned. This is useful when a command will return a non-zeroretcodebut the command is still considered successful.What issues does this PR fix or reference?
#38625
Tests written?
Yes
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.