Skip to content

Commit

Permalink
Handle permissions access error when calling ls_release with the sa…
Browse files Browse the repository at this point in the history
…lt user

```
[ERROR   ] [SaltMaster(id='master-NkEYGW')] An un-handled exception was caught by Salt's global exception handler:
CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 126.
Traceback (most recent call last):
  File "/usr/bin/salt-master", line 11, in <module>
    sys.exit(salt_master())
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/scripts.py", line 88, in salt_master
    master.start()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/daemons.py", line 204, in start
    self.master.start()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/master.py", line 723, in start
    chan = salt.channel.server.PubServerChannel.factory(opts)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/channel/server.py", line 721, in factory
    return cls(opts, transport, presence_events=presence_events)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/channel/server.py", line 727, in __init__
    self.aes_funcs = salt.master.AESFuncs(self.opts)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/master.py", line 1233, in __init__
    self.mminion = salt.minion.MasterMinion(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/minion.py", line 974, in __init__
    self.opts = salt.config.mminion_config(
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/config/__init__.py", line 2332, in mminion_config
    opts["grains"] = salt.loader.grains(opts)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/__init__.py", line 1116, in grains
    ret = funcs[key]()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in __call__
    ret = self.loader.run(run_func, *args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/core.py", line 2602, in os_data
    grains.update(_linux_distribution_data())
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/core.py", line 2189, in _linux_distribution_data
    return _legacy_linux_distribution_data(grains, os_release, lsb_has_error)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/core.py", line 2324, in _legacy_linux_distribution_data
    x.strip('"').strip("'") for x in _linux_distribution()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/platform.py", line 21, in linux_distribution
    return distro.name(), distro.version(best=True), distro.codename()
  File "/opt/saltstack/salt/lib/python3.10/site-packages/distro.py", line 287, in version
    return _distro.version(pretty, best)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/distro.py", line 741, in version
    self.lsb_release_attr('release'),
  File "/opt/saltstack/salt/lib/python3.10/site-packages/distro.py", line 903, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/opt/saltstack/salt/lib/python3.10/site-packages/distro.py", line 556, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/opt/saltstack/salt/lib/python3.10/site-packages/distro.py", line 1014, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/opt/saltstack/salt/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/opt/saltstack/salt/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 126.
```

Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch committed Aug 22, 2023
1 parent 0b1503c commit 9b5b345
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2320,9 +2320,14 @@ def _legacy_linux_distribution_data(grains, os_release, lsb_has_error):
log.trace(
"Getting OS name, release, and codename from distro id, version, codename"
)
(osname, osrelease, oscodename) = (
x.strip('"').strip("'") for x in _linux_distribution()
)
try:
(osname, osrelease, oscodename) = (
x.strip('"').strip("'") for x in _linux_distribution()
)
except subprocess.CalledProcessError:
# When running under the salt user, a call to `lsb_release` might raise
# permissin errors.
return grains
# Try to assign these three names based on the lsb info, they tend to
# be more accurate than what python gets from /etc/DISTRO-release.
# It's worth noting that Ubuntu has patched their Python distribution
Expand Down

0 comments on commit 9b5b345

Please sign in to comment.