Skip to content

Package environment#48021

Merged
terminalmage merged 71 commits intosaltstack:developfrom
isbm:isbm-pkg_environ
Jun 14, 2018
Merged

Package environment#48021
terminalmage merged 71 commits intosaltstack:developfrom
isbm:isbm-pkg_environ

Conversation

@isbm
Copy link
Copy Markdown
Contributor

@isbm isbm commented Jun 7, 2018

What does this PR do?

  • Adds feature of configurable environment for the modules
  • Numerous bugfixes for Apt and Yum/Dnf

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

@ghost ghost self-requested a review June 7, 2018 14:29
Copy link
Copy Markdown
Contributor

@meaksh meaksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for improving this!

@rallytime rallytime requested a review from terminalmage June 7, 2018 15:03
Comment thread salt/utils/__init__.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terminalmage who reads the headers... my bad. But yeah, I thought about exactly this but hesitated. OK, salt/utils/environment.py it is.

Comment thread salt/utils/__init__.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cachedout please agree with the @terminalmage because I like his proposal more than mine. 😉

@isbm isbm changed the title Isbm pkg environ Package environment Jun 8, 2018
@isbm
Copy link
Copy Markdown
Contributor Author

isbm commented Jun 8, 2018

@terminalmage Fixed. With even different way:

system-environment:
  modules:
    pkg:
      _:
        FOR: all
      install:
        FOR: install-only
  states:
    pkg:
      _:
        HELLO: world

In some special case, when someone wants to make sure pkg.foo has different stuff than pkg.bar, say a Yum plugin wants to react differently if you installing or upgrading or updating; or Nagios wants to deploy a plugin or fetch it etc.

@isbm
Copy link
Copy Markdown
Contributor Author

isbm commented Jun 9, 2018

@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.

@terminalmage
Copy link
Copy Markdown
Contributor

@isbm thanks, will re-review on Monday

@isbm
Copy link
Copy Markdown
Contributor Author

isbm commented Jun 13, 2018

re-run py

Comment thread salt/modules/aptpkg.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread salt/modules/aptpkg.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just a left-overs from older times, since we're now got run_all properly and resetting the locale there right away.

Comment thread salt/modules/aptpkg.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's would do, of course.

Comment thread salt/modules/yumpkg.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with apt, this would add get_module_environment to the __salt__ dunder.

Comment thread salt/modules/yumpkg.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 😆

Comment thread salt/modules/zypper.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as apt and yum, this will put get_module_environment in the __salt__ dunder.

@isbm
Copy link
Copy Markdown
Contributor Author

isbm commented Jun 14, 2018

@terminalmage done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants