Fill out lsb_distrib_xxx grains (best guess) if lsb_release information unavailable

This commit is contained in:
David Murphy 2023-11-17 13:11:31 -07:00 committed by Pedro Algarvio
parent 28039bda69
commit cd279bd7d4
3 changed files with 30 additions and 2 deletions

1
changelog/64473.fixed.md Normal file
View file

@ -0,0 +1 @@
Fill out lsb_distrib_xxxx (best estimate) grains if problems with retrieving lsb_release data

View file

@ -2175,8 +2175,9 @@ def _linux_distribution_data():
"rocky",
"ubuntu",
):
# Solely use os-release data. See description of the function.
return grains
if lsb_has_error is False:
# Solely use os-release data. See description of the function.
return grains
except OSError:
os_release = {}

View file

@ -0,0 +1,26 @@
import logging
import pytest
log = logging.getLogger(__name__)
pytestmark = [
pytest.mark.skip_unless_on_linux,
pytest.mark.skipif(
'grains["os_family"] != "Debian"',
reason="Tests applicable only to Debian and Ubuntu",
),
]
def test_grains(grains):
log.warning(f"DGM test_grains '{grains}'")
assert "lsb_distrib_id" in grains
assert "lsb_distrib_release" in grains
assert "lsb_distrib_codename" in grains
assert grains["lsb_distrib_id"] == grains["osfullname"]
assert grains["lsb_distrib_release"] == grains["osrelease"]
assert grains["lsb_distrib_codename"] == grains["oscodename"]