Correctly handle the systemd-detect-virt output to identify a Podman
container running systemd as what it is instead of as a physical machine.
Signed-off-by: Georg Pfuetzenreuter <georg.pfuetzenreuter@suse.com>
```
[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 <palgarvio@vmware.com>
Most Linux distributions ship an os-release file by default. Some do not
ship lsb-release information, but they can be installed afterwards.
Installing/Removing lsb-release can lead to different OS grain values.
| OS | grain | without lsb-release | with lsb-release |
|------------------|------------|----------------------------------|------------------|
| AlmaLinux 8 | oscodename | AlmaLinux 8.5 (Arctic Sphynx) | ArcticSphynx |
| Astra CE | os | Astra (Orel) | AstraLinuxCE |
| Astra CE | os_family | Astra (Orel) | Debian |
| Astra CE | osfullname | Astra Linux (Orel) | AstraLinuxCE |
| Astra CE 2.12.40 | osfinger | Astra Linux (Orel)-2 | AstraLinuxCE-2 |
| Debian | osfullname | Debian GNU/Linux | Debian |
| Mendel | osfullname | Mendel GNU/Linux | Mendel |
| Mendel 10 | osfinger | Mendel GNU/Linux-10 | Mendel-10 |
| Mint | osfullname | Linux Mint | Linuxmint |
| Mint 20.3 | osfinger | Linuxmint-20 | Linux Mint-20 |
| Pop | osfullname | Pop!_OS | Pop |
| Pop 20.04 | osfinger | Pop!_OS-20 | Pop-20 |
| Rocky | osfullname | Rocky Linux | Rocky |
| Rocky 8 | osfinger | Rocky Linux-8 | Rocky-8 |
| Rocky 8 | oscodename | Rocky Linux 8.5 (Green Obsidian) | GreenObsidian |
The current code that determines the OS grains on Linux is a mess: First
lsb-release is queried. If that fails, fall back to read os-release and
parse some `/etc/*-release` files. Then query `_linux_distribution` and
use a mixtures of those for the OS grains. `_linux_distribution` queries
the Python `distro` library. `distro` queries the os-release file,
lsb-release, and then `/etc/*-release`.
Rewrite the code that determines the OS grains on Linux. Solely rely on
the data provided by the os-release file. To not cause regressions, only
switch the distribution that has been tested. All other distributions
will use the legacy code (which was moved to
`_legacy_linux_distribution_data`).
The new code derives the `os_family` grain from the `ID_LIKE` field from
os-release (see https://github.com/saltstack/salt/issues/59061 for this
feature request). To enable this feature, the new code needs to be used
by default (and not just for selected distributions).
This commit introduces a few changes to the OS grains:
* AlmaLinux and Rocky Linux extract the codename from the `VERSION` field
now instead of using the full `PRETTY_NAME`.
* Mendel uses now `Mendel GNU/Linux` as `osfullname` and correctly
extracts the `osrelease` from `PRETTY_NAME`.
* Pop!_OS changes the `osfullname` from `Pop` to `Pop!_OS`.
* Astra Linux changes the `osfullname` from `AstraLinuxCE` to
`Astra Linux (Orel)` and `AstraLinuxSE` to `Astra Linux (Smolensk)`
respectively.
Fixes https://github.com/saltstack/salt/issues/61618
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Pop!_OS uses the same version scheme than Ubuntu (YY.MM) and releases
every six month in April and October. Using only the year from the
version in the `osfinger` does not allow differentiating between 20.04
and 20.10. Both has the `osfinger` set to `Pop-20`.
So include the full version in the `osfinger` grain.
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Python 3.10 introduced `platform.freedesktop_os_release` which does the
same as `_parse_os_release("/etc/os-release", "/usr/lib/os-release")`.
The parsing of the os-release files is nearly identical and differs only
slightly in the used regular expressions. In contrast to
`_parse_os_release`, `platform.freedesktop_os_release` caches the result
of the parsed os-release file.
Use `platform.freedesktop_os_release` when available. When salt drops
the support for Python < 3.10 (some time in the distant future),
`_parse_os_release` can be removed.
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
Change `_parse_os_release` to behave nearly identical to
`platform.freedesktop_os_release` from Python >= 3.10, if called with
("/etc/os-release", "/usr/lib/os-release").
There are no os-release files for Pop!_OS and therefore the test cases
would fail with an `OSError` now.
Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>