-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Fix for broken salt cmd return codes - issue #7013 #11337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thatch45
merged 9 commits into
saltstack:develop
from
techdragon:fix-hightstate-failure-retcode
Mar 22, 2014
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40b5b18
Fix for broken salt cmd return codes - issue #7013
techdragon 0798119
fixing syntax error.
techdragon 7c23998
another syntax fix
techdragon 7e69dd5
Fixing W0632(unbalanced-tuple-unpacking) pylint violation
techdragon 7bf555e
Fixes
techdragon d359c25
Pylint fixes
techdragon 0241691
Fixing E8261(at-least-two-spaces-before-inline-comment)
techdragon 281262f
Trying to fix integration test failing on a missing file so CI actual…
techdragon e2a04d2
Fixes & Updates
techdragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ''' | ||
| Test States | ||
| ================== | ||
|
|
||
| Provide test case states that enable easy testing of things to do with | ||
| state calls, e.g. running, calling, logging, output filtering etc. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| always-passes: | ||
| test.succeed_without_changes: | ||
| - name: foo | ||
|
|
||
| always-fails: | ||
| test.fail_without_changes: | ||
| - name: foo | ||
|
|
||
| always-changes-and-succeeds: | ||
| test.succeed_with_changes: | ||
| - name: foo | ||
|
|
||
| always-changes-and-fails: | ||
| test.fail_with_changes: | ||
| - name: foo | ||
|
|
||
| my-custom-combo: | ||
| test.configurable_test_state: | ||
| - name: foo | ||
| - changes: True | ||
| - result: False | ||
| - comment: bar.baz | ||
|
|
||
| ''' | ||
|
|
||
| # Import Python libs | ||
| import logging | ||
| import random | ||
| from salt.exceptions import SaltInvocationError | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def succeed_without_changes(name): | ||
| ''' | ||
| Returns successful. | ||
|
|
||
| name | ||
| A unique string. | ||
| ''' | ||
| ret = { | ||
| 'name': name, | ||
| 'changes': {}, | ||
| 'result': True, | ||
| 'comment': 'This is just a test, nothing actually happened' | ||
| } | ||
| if __opts__['test']: | ||
| ret['result'] = None | ||
| ret['comment'] = ( | ||
| 'Yo dawg I heard you like tests,' | ||
| ' so I put tests in your tests,' | ||
| ' so you can test while you test.' | ||
| ) | ||
| return ret | ||
|
|
||
|
|
||
| def fail_without_changes(name): | ||
| ''' | ||
| Returns failure. | ||
|
|
||
| name: | ||
| A unique string. | ||
| ''' | ||
| ret = { | ||
| 'name': name, | ||
| 'changes': {}, | ||
| 'result': False, | ||
| 'comment': 'This is just a test, nothing actually happened' | ||
| } | ||
|
|
||
| if __opts__['test']: | ||
| ret['result'] = None | ||
| ret['comment'] = ( | ||
| 'Yo dawg I heard you like tests,' | ||
| ' so I put tests in your tests,' | ||
| ' so you can test while you test.' | ||
| ) | ||
|
|
||
| return ret | ||
|
|
||
|
|
||
| def succeed_with_changes(name): | ||
| ''' | ||
| Returns successful and changes is not empty | ||
|
|
||
| name: | ||
| A unique string. | ||
| ''' | ||
| ret = { | ||
| 'name': name, | ||
| 'changes': {}, | ||
| 'result': True, | ||
| 'comment': 'This is just a test, nothing actually happened' | ||
| } | ||
|
|
||
| # Following the docs as written here | ||
| # http://docs.saltstack.com/ref/states/writing.html#return-data | ||
| ret['changes'] = { | ||
| 'testing': { | ||
| 'old': 'Nothing has changed yet', | ||
| 'new': 'Were pretending really hard that we changed something' | ||
| } | ||
| } | ||
|
|
||
| if __opts__['test']: | ||
| ret['result'] = None | ||
| ret['comment'] = ( | ||
| 'Yo dawg I heard you like tests,' | ||
| ' so I put tests in your tests,' | ||
| ' so you can test while you test.' | ||
| ) | ||
|
|
||
| return ret | ||
|
|
||
|
|
||
| def fail_with_changes(name): | ||
| ''' | ||
| Returns failure and changes is not empty. | ||
|
|
||
| name: | ||
| A unique string. | ||
| ''' | ||
| ret = { | ||
| 'name': name, | ||
| 'changes': {}, | ||
| 'result': False, | ||
| 'comment': 'This is just a test, nothing actually happened' | ||
| } | ||
|
|
||
| # Following the docs as written here | ||
| # http://docs.saltstack.com/ref/states/writing.html#return-data | ||
| ret['changes'] = { | ||
| 'testing': { | ||
| 'old': 'Nothing has changed yet', | ||
| 'new': 'Were pretending really hard that we changed something' | ||
| } | ||
| } | ||
|
|
||
| if __opts__['test']: | ||
| ret['result'] = None | ||
| ret['comment'] = ( | ||
| 'Yo dawg I heard you like tests,' | ||
| ' so I put tests in your tests,' | ||
| ' so you can test while you test.' | ||
| ) | ||
|
|
||
| return ret | ||
|
|
||
|
|
||
| def configurable_test_state(name, changes=True, result=True, comment=''): | ||
| ''' | ||
| A configurable test state which determines its output based on the inputs. | ||
|
|
||
| name: | ||
| A unique string. | ||
| changes: | ||
| Do we return anything in the changes field? | ||
| Accepts True, False, and 'Random' | ||
| Default is True | ||
| result: | ||
| Do we return sucessfuly or not? | ||
| Accepts True, False, and 'Random' | ||
| Default is True | ||
| comment: | ||
| String to fill the comment field with. | ||
| Default is '' | ||
| ''' | ||
| ret = { | ||
| 'name': name, | ||
| 'changes': {}, | ||
| 'result': False, | ||
| 'comment': comment | ||
| } | ||
|
|
||
| # E8712 is disabled because this code is a LOT cleaner if we allow it. | ||
| if changes == "Random": | ||
| if random.choice([True, False]): | ||
| # Following the docs as written here | ||
| # http://docs.saltstack.com/ref/states/writing.html#return-data | ||
| ret['changes'] = { | ||
| 'testing': { | ||
| 'old': 'Nothing has changed yet', | ||
| 'new': 'Were pretending really hard that we changed something' | ||
| } | ||
| } | ||
| elif changes == True: # pylint: disable=E8712 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would elif changes is True:be less readable? |
||
| # If changes is True we place our dummy change dictionary into it. | ||
| # Following the docs as written here | ||
| # http://docs.saltstack.com/ref/states/writing.html#return-data | ||
| ret['changes'] = { | ||
| 'testing': { | ||
| 'old': 'Nothing has changed yet', | ||
| 'new': 'Were pretending really hard that we changed something' | ||
| } | ||
| } | ||
| elif changes == False: # pylint: disable=E8712 | ||
| ret['changes'] = {} | ||
| else: | ||
| err = ('You have specified the state option \'Changes\' with' | ||
| ' invalid arguments. It must be either ' | ||
| ' \'True\', \'False\', or \'Random\'') | ||
| raise SaltInvocationError(err) | ||
|
|
||
| if result == 'Random': | ||
| # since result is a boolean, if its random we just set it here, | ||
| ret['result'] = random.choice([True, False]) | ||
| elif result == True: # pylint: disable=E8712 | ||
| ret['result'] = True | ||
| elif result == False: # pylint: disable=E8712 | ||
| ret['result'] = False | ||
| else: | ||
| err = ('You have specified the state option \'Result\' with' | ||
| ' invalid arguments. It must be either ' | ||
| ' \'True\', \'False\', or \'Random\'') | ||
| raise SaltInvocationError(err) | ||
|
|
||
| if __opts__['test']: | ||
| ret['result'] = None | ||
| ret['comment'] = ( | ||
| 'Yo dawg I heard you like tests,' | ||
| ' so I put tests in your tests,' | ||
| ' so you can test while you test.' | ||
| ) | ||
|
|
||
| return ret | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # -*- coding: utf-8 -*- |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not want to raise an error like this, but just return with the error return code, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean just passing on the return code that is generated from the minion. The problem is what to do when you get multiple different return codes. For instance one minion has no errors, another has a single state return retcode 1, another minion returns retcode 2. How to represent this? I've been contemplating options on how to provide the information and feel that given the possible permutations we really have little option as far as the process return/exit code but to choose a distinct error code for this 'minion failures' use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, no, I like your approach with a static exit code! I just think we should use sys.exit instead of raise SaltSystemExit