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] mac_service with runas specified -> NameError: name '__salt__' is not defined #61816

Closed
lkubb opened this issue Mar 21, 2022 · 0 comments · Fixed by #61826
Closed

[BUG] mac_service with runas specified -> NameError: name '__salt__' is not defined #61816

lkubb opened this issue Mar 21, 2022 · 0 comments · Fixed by #61826
Assignees
Labels
Bug broken, incorrect, or confusing behavior MacOS pertains to the OS of fruit needs-triage

Comments

@lkubb
Copy link
Contributor

lkubb commented Mar 21, 2022

Description
Running service.get_enabled runas=user (or any other functions inside that module that expose runas that I tested) on MacOS [Monterey] results in an exception.

Setup
M1 Mac + MacOS Monterey

Steps to Reproduce the behavior

$ sudo /opt/salt/bin/salt-call service.get_enabled runas=username
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
NameError: name '__salt__' is not defined
Traceback (most recent call last):
  File "/opt/salt/bin/salt-call", line 11, in <module>
    load_entry_point('salt==3004', 'console_scripts', 'salt-call')()
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/scripts.py", line 432, in salt_call
    client.run()
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/cli/call.py", line 55, in run
    caller.run()
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/cli/caller.py", line 111, in run
    ret = self.call()
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/cli/caller.py", line 219, in call
    self.opts, data, func, args, kwargs
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/executors/direct_call.py", line 10, in execute
    return func(*args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/modules/mac_service.py", line 689, in get_enabled
    stdout = list_(runas=runas)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/modules/mac_service.py", line 354, in list_
    return launchctl("list", return_stdout=True, runas=runas)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/modules/mac_service.py", line 318, in launchctl
    return __utils__["mac_utils.launchctl"](sub_cmd, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1201, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/loader/lazy.py", line 1216, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/utils/mac_utils.py", line 311, in launchctl
    ret = __salt__["cmd.run_all"](cmd, **kwargs)
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/modules/cmdmod.py", line 986, in _run_all_quiet
    success_stderr=success_stderr,
  File "/opt/salt/lib/python3.7/site-packages/salt-3004-py3.7.egg/salt/modules/cmdmod.py", line 442, in _run
    user_shell = __salt__["user.info"](runas)["shell"]

Expected behavior
Returns a list of launchctl services, including user-specific ones.

Versions Report

Salt Version:
          Salt: 3004

Dependency Versions:
          cffi: 1.14.6
      cherrypy: unknown
      dateutil: 2.8.0
     docker-py: Not Installed
         gitdb: 4.0.5
     gitpython: 3.1.12
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.4
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.19
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.7.4 (default, Oct 12 2021, 12:57:44)
  python-gnupg: 0.4.4
        PyYAML: 5.4.1
         PyZMQ: 18.0.1
         smmap: 3.0.2
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.1

System Versions:
          dist: darwin 21.3.0
        locale: UTF-8
       machine: x86_64
       release: 21.3.0
        system: Darwin
       version: 10.16 x86_64

Additional context
Related issue: #47705

I already diagnosed it:

PR incoming. Just need to figure out how to write the test.

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 MacOS pertains to the OS of fruit needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants