Skip to content
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

[master] Fix bug in pip.installed state when user does not exists #65466

Merged
merged 4 commits into from
Nov 20, 2023

Conversation

scornelissen85
Copy link
Contributor

What does this PR do?

This will fix that pip will give a stacktrace when the pip.installed state is executed with an specified user that does not exists.

What issues does this PR fix or reference?

Fixes: #65458

Previous Behavior

Without this fix, pip will throw a stacktrace like this:

[ERROR   ] Pre-caching of PIP packages during states.pip.installed failed by exception from pip.list: User 'fred' is not available
Traceback (most recent call last):
  File "/salt/salt/modules/cmdmod.py", line 485, in _run
    pwd.getpwnam(runas)
KeyError: "getpwnam(): name not found: 'fred'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/salt/salt/states/pip_state.py", line 852, in installed
    pip_list = __salt__["pip.list"](
  File "/salt/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/salt/salt/modules/pip.py", line 1353, in list_
    result = __salt__["cmd.run_all"](cmd, **cmd_kwargs)
  File "/salt/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/salt/salt/modules/cmdmod.py", line 2329, in run_all
    ret = _run(
  File "/salt/salt/modules/cmdmod.py", line 487, in _run
    raise CommandExecutionError("User '{}' is not available".format(runas))
salt.exceptions.CommandExecutionError: User 'fred' is not available
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/salt/salt/modules/cmdmod.py", line 485, in _run
    pwd.getpwnam(runas)
KeyError: "getpwnam(): name not found: 'fred'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/salt/salt/state.py", line 2381, in call
    ret = self.states[cdata["full"]](
  File "/salt/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1293, in wrapper
    return f(*args, **kwargs)
  File "/salt/salt/states/pip_state.py", line 865, in installed
    out = _check_if_installed(
  File "/salt/salt/states/pip_state.py", line 276, in _check_if_installed
    or __salt__["pip.list"](
  File "/salt/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/salt/salt/modules/pip.py", line 1353, in list_
    result = __salt__["cmd.run_all"](cmd, **cmd_kwargs)
  File "/salt/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/salt/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/salt/salt/modules/cmdmod.py", line 2329, in run_all
    ret = _run(
  File "/salt/salt/modules/cmdmod.py", line 487, in _run
    raise CommandExecutionError("User '{}' is not available".format(runas))
salt.exceptions.CommandExecutionError: User 'fred' is not available

New Behavior

With this fix the output of de state.apply will be this:

----------
          ID: Flask
    Function: pip.installed
      Result: False
     Comment: User fred does not exist
     Started: 07:47:15.282932
    Duration: 179.845 ms
     Changes:

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@scornelissen85 scornelissen85 requested a review from a team as a code owner October 26, 2023 08:02
@scornelissen85 scornelissen85 requested review from cmcmarrow and removed request for a team October 26, 2023 08:02
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Fix bug in pip.installed state when user does not exists [master] Fix bug in pip.installed state when user does not exists Oct 26, 2023
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:19 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:19 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:21 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:21 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:22 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 08:22 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:22 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:22 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:23 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:23 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:23 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 09:23 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 12:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@scornelissen85 scornelissen85 temporarily deployed to ci October 26, 2023 13:09 — with GitHub Actions Inactive
@s0undt3ch s0undt3ch merged commit a686ce0 into saltstack:master Nov 20, 2023
416 checks passed
@s0undt3ch s0undt3ch added the backport:3006.x Backport PR to 3006.x branch label Nov 20, 2023
@s0undt3ch s0undt3ch added backport:complete PR Backported labels Nov 20, 2023
@s0undt3ch
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
3006.x

Questions ?

Please refer to the Backport tool documentation

3 similar comments
@s0undt3ch
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
3006.x

Questions ?

Please refer to the Backport tool documentation

@s0undt3ch
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
3006.x

Questions ?

Please refer to the Backport tool documentation

@s0undt3ch
Copy link
Collaborator

💚 All backports created successfully

Status Branch Result
3006.x

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:complete PR Backported backport:3006.x Backport PR to 3006.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] pip.installed show stacktrace when user does not exists on testing
3 participants