Skip to content

Commit

Permalink
Test /etc/os-release first
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dirkmueller authored and philpep committed Aug 24, 2023
1 parent ca5bf83 commit fee868d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions testinfra/modules/systeminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fee868d

Please sign in to comment.