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

[BUG] pip.installed show stacktrace when user does not exists on testing #65458

Closed
scornelissen85 opened this issue Oct 25, 2023 · 2 comments · Fixed by #65466
Closed

[BUG] pip.installed show stacktrace when user does not exists on testing #65458

scornelissen85 opened this issue Oct 25, 2023 · 2 comments · Fixed by #65466
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@scornelissen85
Copy link
Contributor

scornelissen85 commented Oct 25, 2023

Description
When I'm creating a state with pip.installed, with an user given and will apply this state with test=True then there will be a stacktrace because it's trying to figure out which packages are installed under that user. However the user does not exists, so it will fail to check.

Setup

Install Salt 3006.3 on local linux machine. Install pip with your preferred package manager.

Steps to Reproduce the behavior
Create this state:

pip.sls:

Flask:
  pip.installed:
    - user: fred

The user fred does not exists. I'm applying the state:

# salt-call --local state.apply pip test=True
[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

local:
----------
          ID: Flask
    Function: pip.installed
      Result: False
     Comment: 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
     Started: 12:08:06.766475
    Duration: 182.321 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time: 182.321 ms

Expected behavior

When applying the state and test=True, something like this should be shown:

local:
----------
          ID: Flask
    Function: pip.installed
      Result: None
     Comment: User fred does not exist
     Started: 12:00:07.722631
    Duration: 216.618 ms
     Changes:
              ----------
              Flask:
                  ----------
                  new:
                      installed
                  old:

Summary for local
------------
Succeeded: 1 (unchanged=1, changed=1)
Failed:    0
------------
Total states run:     1
Total run time: 216.618 ms

Versions Report

salt --versions-report
Salt Version:
          Salt: 3007.0

Python Version:
        Python: 3.9.16 (main, Jun 30 2023, 08:01:58)

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.2
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.19.0
        pygit2: Not Installed
  python-gnupg: Not Installed
        PyYAML: 6.0.1
         PyZMQ: 25.1.1
        relenv: Not Installed
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: almalinux 8.8 Sapphire Caracal
        locale: utf-8
       machine: x86_64
       release: 5.15.90.1-microsoft-standard-WSL2
        system: Linux
       version: AlmaLinux 8.8 Sapphire Caracal

Additional context
I have installed Salt from the github repository with pip, checked out on tag v3006.3.

@scornelissen85 scornelissen85 added Bug broken, incorrect, or confusing behavior needs-triage labels Oct 25, 2023
@scornelissen85
Copy link
Contributor Author

scornelissen85 commented Oct 25, 2023

I'm not sure if the changes should be shown. Maybe, the result should even be False, because the user isn't found and it cannot check if the package should be installed.

It would then return something like:

[ERROR   ] User fred does not exist
local:
----------
          ID: Flask
    Function: pip.installed
      Result: False
     Comment: User fred does not exist
     Started: 12:11:19.009667
    Duration: 185.8 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time: 185.800 ms

Which is I think more the way it should be?

@scornelissen85
Copy link
Contributor Author

When I'm lookung further into it, I even think that it should alsof fail with the same error when not running in dry-run mode. Currently, If I'm applying a pip.installed state with an unknown user I get the same stacktrace. This should also be the neat output like:

[ERROR   ] User fred does not exist
local:
----------
          ID: Flask
    Function: pip.installed
      Result: False
     Comment: User fred does not exist
     Started: 07:05:28.388716
    Duration: 182.767 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time: 182.767 ms

scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 26, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 27, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Oct 27, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Nov 7, 2023
scornelissen85 added a commit to scornelissen85/salt that referenced this issue Nov 18, 2023
s0undt3ch pushed a commit that referenced this issue Nov 20, 2023
s0undt3ch pushed a commit to s0undt3ch/salt that referenced this issue Nov 20, 2023
(cherry picked from commit 15cef7d)
s0undt3ch pushed a commit to s0undt3ch/salt that referenced this issue Nov 21, 2023
(cherry picked from commit 15cef7d)
s0undt3ch pushed a commit that referenced this issue Nov 22, 2023
(cherry picked from commit 15cef7d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant