salt icon indicating copy to clipboard operation
salt copied to clipboard

Fix OS grain inconsistencies if lsb-release is installed or not

Open bdrung opened this issue 3 years ago • 1 comments

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

This merge request contains the commits from the merge request https://github.com/saltstack/salt/pull/61597, https://github.com/saltstack/salt/pull/61589, and https://github.com/saltstack/salt/pull/61619. So I recommend to review and merge those first.

bdrung avatar Feb 11 '22 01:02 bdrung

Added the fix for Astra Linux.

bdrung avatar Feb 11 '22 16:02 bdrung

The first pull request in this series https://github.com/saltstack/salt/pull/61597 got merged. The next pull request in this series is https://github.com/saltstack/salt/pull/61589

bdrung avatar Sep 26 '22 22:09 bdrung

The next pull request in this series https://github.com/saltstack/salt/pull/61589 got merged. The next pull request in this series is https://github.com/saltstack/salt/pull/61619.

bdrung avatar Sep 30 '22 19:09 bdrung

Pull request https://github.com/saltstack/salt/pull/61619 got merged. I rebased this merge request on master now.

bdrung avatar Sep 30 '22 21:09 bdrung

Some test cases fail due to https://github.com/saltstack/salt/pull/62220#issuecomment-1264063935

bdrung avatar Sep 30 '22 22:09 bdrung

Lint errors are unrelated to this PR.

garethgreenaway avatar Oct 01 '22 00:10 garethgreenaway

This should fix things https://github.com/saltstack/salt/pull/62790

garethgreenaway avatar Oct 01 '22 00:10 garethgreenaway

re-run all

MKLeb avatar Oct 27 '22 20:10 MKLeb

The failing tests might be related.

repo_content = "deb {opts} [https://repo.saltproject.io/py3/{}/{}/{arch}/latest](https://repo.saltproject.io/py3/%7B%7D/%7B%7D/%7Barch%7D/latest) {} main".format(
                self.fullname,
>               self.grains["lsb_distrib_release"],
                self.grains["oscodename"],
                arch=self.grains["osarch"],
                opts=opts,
            )
E           KeyError: 'lsb_distrib_release'

twangboy avatar Oct 28 '22 20:10 twangboy

@bdrung Just making sure you saw the failing tests on this PR and that they seem to be related to your changes. Thanks!

garethgreenaway avatar Nov 04 '22 01:11 garethgreenaway

Fixed failing Debian tests.

bdrung avatar Nov 20 '22 14:11 bdrung