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.
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.
Note, there are other logging calls where similar changes need to be made, this is just one example.
terminalmage
left a comment
There was a problem hiding this comment.
One minor change left to make.
salt/modules/pkgng.py
Outdated
There was a problem hiding this comment.
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.
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.lockpkg.unlockpkg.lockedpkg.list_lockedpkg.list_upgradesfor compatibility withpkg.uptodatestatepkgskeyword inpkg.upgradefor compatibility withpkg.uptodatestatepkg.holdandpkg.unholdfor compatibility withpkg.installedstateWhat issues does this PR fix or reference?
None
New Behavior
Better compatibility with
pkg.uptodateandpkg.installedstatesTests 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.