-
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
FreeBSD pkg module enhancements #45217
Conversation
Thanks @amendlik - There are a couple of lint errors https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/17759/violations/file/tests/unit/modules/test_pkgng.py/. Can you fix those up? |
This makes the pkgng execution module compatible with the pkg.uptodate state.
The pkgs kwarg is passed by salt.states.pkg.uptodate. If it is not recognized by the pkg module, all packages are upgraded.
These functions are called by salt.states.pkg.installed, if present. They are implemented here for compatibility between pkg.installed (state) and pkg.lock/unlock (module)
This change reimplements the pkgng.list_upgrades function to use the `pkg upgrade --dry-run` command. An earlier version of this function used `pkg version`, but it had several problems: 1) Long execution times when used with multiple repositories and the --no-repo-update argument. 2) It would show expected upgrades for a package when any repository had a newer version available. FreeBSD, by default, only applies upgrades from the repository the package was originally installed from. 3) It would show expected upgrades for locked packages.
@rallytime Those lint errors are fixed now. |
salt/modules/pkgng.py
Outdated
continue | ||
locked_pkgs.append(pkgname) | ||
|
||
log.debug("Locked packages: {0}".format(locked_pkgs)) |
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.
Can you revise your logging calls, and remove str.format usage in favor of string replacement? Python logging already does string replacement using any positional args passed after the format string, so using str.format is redundant. Also, we have code in our custom logging handler which normalizes the format string and the args passed to it so that they are unicode, preventing log messages from triggering unicode encoding/decoding errors. This log message should be changed to:
log.debug("Locked packages: %s", locked_pkgs)
I realize you have probably seen a lot of usage of str.format in logging, but it's something we're working to stamp out in the codebase to make logging work better with unicode.
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.
Note, there are other logging calls where similar changes need to be made, this is just one example.
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.
One minor change left to make.
salt/modules/pkgng.py
Outdated
@@ -74,10 +75,10 @@ def __virtual__(): | |||
providers = {} | |||
if 'providers' in __opts__: | |||
providers = __opts__['providers'] | |||
log.debug('__opts__.providers: {0}'.format(providers)) | |||
log.debug('__opts__.providers: %s', str(providers)) |
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.
There is no need to use str()
here. The fact that you have used a %s
placeholder in the log string means that Python's logging module will convert the dictionary to a string.
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.
Thank you for the code review, @terminalmage. The last item is fixed.
@terminalmage Is there anything left to do on this change? |
What does this PR do?
Various enhancements for the FreeBSD pkgng execution module:
pkg.lock
pkg.unlock
pkg.locked
pkg.list_locked
pkg.list_upgrades
for compatibility withpkg.uptodate
statepkgs
keyword inpkg.upgrade
for compatibility withpkg.uptodate
statepkg.hold
andpkg.unhold
for compatibility withpkg.installed
stateWhat issues does this PR fix or reference?
None
New Behavior
Better compatibility with
pkg.uptodate
andpkg.installed
statesTests 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.