Package environment#48021
Conversation
meaksh
left a comment
There was a problem hiding this comment.
Looks good to me! Thanks for improving this!
There was a problem hiding this comment.
As noted in the header of this file, we are not adding new functions here. I don't see a natural home in the existing modules under salt/utils/, so this may need to go into its own file. salt/utils/environment.py perhaps?
There was a problem hiding this comment.
@terminalmage who reads the headers... my bad. But yeah, I thought about exactly this but hesitated. OK, salt/utils/environment.py it is.
There was a problem hiding this comment.
I'm not sure I like this structure. A lot of users aren't developers, and will thus not intrinsically grok the "module path" naming. From a user-friendliness standpoint, I think it would be more intuitive to do something like:
system-environment:
modules:
pkg:
FOO: bar
states:
pkg:
HELLO: world@cachedout thoughts on this?
There was a problem hiding this comment.
@cachedout please agree with the @terminalmage because I like his proposal more than mine. 😉
|
@terminalmage Fixed. With even different way: system-environment:
modules:
pkg:
_:
FOR: all
install:
FOR: install-only
states:
pkg:
_:
HELLO: worldIn some special case, when someone wants to make sure |
|
@rallytime ha, seems like not everything was mocked for Yum/Dnf unit tests! The systemd capability is actually called for real, hence on my side this test has been never failed, but does fail here. Will fix that. |
|
@isbm thanks, will re-review on Monday |
|
re-run py |
There was a problem hiding this comment.
We either need to use the full module namespace, or we need to import the function as a private function (i.e. as _get_module_environment). The reason for this is because the loader will add all public functions in the module into the __salt__ dunder.
There was a problem hiding this comment.
This will force a user to set LC_ALL and LANG. Would it be a good idea to set up some sort of default environment? Since we're passing globals() to get_module_environment(), we could maybe define it as a dunder in the global scope?
There was a problem hiding this comment.
These are just a left-overs from older times, since we're now got run_all properly and resetting the locale there right away.
There was a problem hiding this comment.
It's rare that we need to do ignore the retcode, I don't think this should be the default. Why not just remove this line and pass through ignore_retcode=True in the kwargs in the two places where we use it (autoremove and list_repo_pkgs)?
There was a problem hiding this comment.
Yes, that's would do, of course.
There was a problem hiding this comment.
Same as with apt, this would add get_module_environment to the __salt__ dunder.
There was a problem hiding this comment.
Same as with apt, I don't think we should make this the default. Turning this on means we won't get any logging when a command exits with a nonzero exit status. There are instances where this is useful, as some commands return nonzero exit status in non-error cases, but it's an exception, not the norm.
There was a problem hiding this comment.
Zypper actually doesn't do this. But I just moved it as a default behaviour (most of the time) in yumpkg module. By not ignoring the return code, could it be that the Salt won't succeed anymore running Yum? 😆
There was a problem hiding this comment.
Same as apt and yum, this will put get_module_environment in the __salt__ dunder.
|
@terminalmage done. |
dccd06f to
7f53d5a
Compare
What does this PR do?
New Behavior
It is now possible to configure an environment variables for each module and even its functions separately and reuse it with the
cmd.run*utility (or other similar matters). This is especially useful if there are package manager plugins that are communicating via environment variables. You find that a lot in Apt/dpkg module. E.g.: write a plugin for a package manager that detects (and records) an event so the package has been updated/installed just directly manually or from within Salt.Tests written?
Yes