From fee868d05a4a37d19f6c3e74d7b2c88f525bc657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Thu, 3 Aug 2023 22:12:30 +0200 Subject: [PATCH] Test /etc/os-release first On systems lsb_release could be patched to return a "compatible" distribution, not the native one. so prefer the modern /etc/os-release over lsb_release. --- testinfra/modules/systeminfo.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/testinfra/modules/systeminfo.py b/testinfra/modules/systeminfo.py index 3c2ee131..86565a47 100644 --- a/testinfra/modules/systeminfo.py +++ b/testinfra/modules/systeminfo.py @@ -50,21 +50,6 @@ def sysinfo(self): def _get_linux_sysinfo(self): sysinfo = {} - # LSB - lsb = self.run("lsb_release -a") - if lsb.rc == 0: - for line in lsb.stdout.splitlines(): - key, value = line.split(":", 1) - key = key.strip().lower() - value = value.strip().lower() - if key == "distributor id": - sysinfo["distribution"] = value - elif key == "release": - sysinfo["release"] = value - elif key == "codename": - sysinfo["codename"] = value - return sysinfo - # https://www.freedesktop.org/software/systemd/man/os-release.html os_release = self.run("cat /etc/os-release") if os_release.rc == 0: @@ -100,6 +85,21 @@ def _get_linux_sysinfo(self): sysinfo["release"] = alpine_release.stdout.strip() return sysinfo + # LSB + lsb = self.run("lsb_release -a") + if lsb.rc == 0: + for line in lsb.stdout.splitlines(): + key, value = line.split(":", 1) + key = key.strip().lower() + value = value.strip().lower() + if key == "distributor id": + sysinfo["distribution"] = value + elif key == "release": + sysinfo["release"] = value + elif key == "codename": + sysinfo["codename"] = value + return sysinfo + return sysinfo def _get_darwin_sysinfo(self):