-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[2017.7] fixes to states/pkg.py #48426
[2017.7] fixes to states/pkg.py #48426
Conversation
salt/states/pkg.py
Outdated
else: | ||
hold_ret = __salt__['pkg.unhold']( | ||
name=name, pkgs=desired, sources=sources | ||
) |
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.
Or shorter, so easier comprehend half-year later while debuggin and no same code repetitions:
hold_ret = __salt__['pkg.{}hold'.format(not kwargs['hold'] and 'un' or '')](
name=name, pkgs=desired, sources=sources
)
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.
This doesn't look that much better. It's certainly a lot less readable. It would be more readable like this:
action = 'pkg.hold' if kwargs['hold'] else 'pkg.unhold'
hold_ret = __salt__[action](
name=name, pkgs=desired, sources=sources
)
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.
That was exactly my first version, including the variable name... Probably I should use less compression in a future. 😏
salt/states/pkg.py
Outdated
except (CommandExecutionError, SaltInvocationError) as exc: | ||
comment.append(str(exc)) | ||
if 'pkg.hold' in __salt__: | ||
if 'hold' in kwargs: |
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.
No need in nested ifs and unnecessary large indent because of it:
if 'pkg.hold' in __salt__ and 'hold' in kwargs:
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.
While @garethgreenaway didn't originally write this (he just dedented existing code), this would probably be a good idea, especially since there is no action taken when the hold
argument is not passed.
salt/states/pkg.py
Outdated
else: | ||
hold_ret = __salt__['pkg.unhold']( | ||
name=name, pkgs=desired, sources=sources | ||
) |
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.
This doesn't look that much better. It's certainly a lot less readable. It would be more readable like this:
action = 'pkg.hold' if kwargs['hold'] else 'pkg.unhold'
hold_ret = __salt__[action](
name=name, pkgs=desired, sources=sources
)
salt/states/pkg.py
Outdated
except (CommandExecutionError, SaltInvocationError) as exc: | ||
comment.append(str(exc)) | ||
if 'pkg.hold' in __salt__: | ||
if 'hold' in kwargs: |
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.
While @garethgreenaway didn't originally write this (he just dedented existing code), this would probably be a good idea, especially since there is no action taken when the hold
argument is not passed.
3c3c476
to
1208f59
Compare
@garethgreenaway Can you fix the lint here? https://jenkinsci.saltstack.com/job/pr-lint/job/PR-48426/1/warnings52Result/ |
6909037
to
e521f6b
Compare
…nually and a state attempts to set that package to be held. Previously the holding/unholding logic was only being run against packages that were being installed. This change moves the holding logic outside and runs it against all desired packages. Adding a new test to test holding logic.
…uires_salt_modules decorator, sys.doc was returning too much information for the event to handle. This change specifically calls sys.doc with the module name.
e521f6b
to
9b0f5dd
Compare
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.
LGTM
…rue. This was due to a change in saltstack#48426 that swapped out sending the pkgs variable for the desired variable instead. This caused problems with pkg.hold because desired and sources are always populated, and pkg.hold can only include one or the other. This change just includes desired in the call to pkg.hold since desired has the same value for sources.
…rue. This was due to a change in saltstack#48426 that swapped out sending the pkgs variable for the desired variable instead. This caused problems with pkg.hold because desired and sources are always populated, and pkg.hold can only include one or the other. This change just includes desired in the call to pkg.hold since desired has the same value for sources.
What does this PR do?
Fixing a situation when a package is already installed via salt or manually and a state attempts to set that package to be held.
What issues does this PR fix or reference?
#46689
Previous Behavior
Previously the holding/unholding logic was only being run against packages that were being installed.
New Behavior
This change moves the holding logic outside and runs it against all desired packages. Adding a new test to test holding logic.
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.