Skip to content

[develop] Ability to override retcode from various cmdmod functions#45851

Merged
rallytime merged 4 commits intosaltstack:developfrom
garethgreenaway:38625_overriding_retcode
Feb 16, 2018
Merged

[develop] Ability to override retcode from various cmdmod functions#45851
rallytime merged 4 commits intosaltstack:developfrom
garethgreenaway:38625_overriding_retcode

Conversation

@garethgreenaway
Copy link
Contributor

@garethgreenaway garethgreenaway commented Feb 3, 2018

What does this PR do?

Adding a flag to various cmdmod functions to allow overriding the retcode that is returned. This is useful when a command will return a non-zero retcode but 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space between code and returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"overridden" seems like the wrong word here. "replaced" maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@rallytime rallytime merged commit 7897d79 into saltstack:develop Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants