Skip to content

Commit

Permalink
SystemInfo: Fallback to /etc/os-release
Browse files Browse the repository at this point in the history
  • Loading branch information
philpep committed May 20, 2015
1 parent cec4e92 commit 586656e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
24 changes: 18 additions & 6 deletions testinfra/modules/systeminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def sysinfo(self):
return self._sysinfo

def get_system_info(self):
sysinfo = {}
sysinfo = {
"type": None,
"distribution": None,
"codename": None,
"release": None,
}
sysinfo["type"] = self.check_output("uname -s").lower()
if sysinfo["type"] == "linux":
lsb = self.run("lsb_release -a")
Expand All @@ -50,14 +55,21 @@ def get_system_info(self):
elif key == "codename":
sysinfo["codename"] = value
else:
version = self.run("cat /etc/debian_version")
if version.rc == 0:
sysinfo["distribution"] = "debian"
sysinfo["release"] = version.stdout.splitlines()[0]
os_release = self.run("cat /etc/os-release")
if os_release.rc == 0:
for line in os_release.stdout.splitlines():
for key, attname in (
("ID=", "distribution"),
("VERSION_ID=", "release"),
):
if line.startswith(key):
sysinfo[attname] = (
line[len(key):].replace('"', "").
replace("'", "").strip())
else:
sysinfo["release"] = self.check_output("uname -r")
sysinfo["distribution"] = sysinfo["type"]
sysinfo["codename"] = ""
sysinfo["codename"] = None
return sysinfo

@property
Expand Down
7 changes: 7 additions & 0 deletions testinfra/test/integration/test_centos_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_ssh_service(Service):
ssh = Service("sshd")
assert ssh.is_running
assert ssh.is_enabled


def test_systeminfo(SystemInfo):
assert SystemInfo.type == "linux"
assert SystemInfo.release == "7"
assert SystemInfo.distribution == "centos"
assert SystemInfo.codename is None
7 changes: 7 additions & 0 deletions testinfra/test/integration/test_fedora_21.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_ssh_service(Service):
ssh = Service("sshd")
assert ssh.is_running
assert ssh.is_enabled


def test_systeminfo(SystemInfo):
assert SystemInfo.type == "linux"
assert SystemInfo.release == "21"
assert SystemInfo.distribution == "fedora"
assert SystemInfo.codename is None
7 changes: 7 additions & 0 deletions testinfra/test/integration/test_jessie.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_ssh_service(Service):
ssh = Service("ssh")
assert ssh.is_running
assert ssh.is_enabled


def test_systeminfo(SystemInfo):
assert SystemInfo.type == "linux"
assert SystemInfo.release == "8"
assert SystemInfo.distribution == "debian"
assert SystemInfo.codename is None
7 changes: 7 additions & 0 deletions testinfra/test/integration/test_trusty.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_ssh_service(Service):
ssh = Service("ssh")
assert ssh.is_running
assert ssh.is_enabled


def test_systeminfo(SystemInfo):
assert SystemInfo.type == "linux"
assert SystemInfo.release == "14.04"
assert SystemInfo.distribution == "ubuntu"
assert SystemInfo.codename == "trusty"
7 changes: 7 additions & 0 deletions testinfra/test/integration/test_wheezy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test_ssh_service(Service):
ssh = Service("ssh")
assert ssh.is_running
assert ssh.is_enabled


def test_systeminfo(SystemInfo):
assert SystemInfo.type == "linux"
assert SystemInfo.release == "7"
assert SystemInfo.distribution == "debian"
assert SystemInfo.codename is None

0 comments on commit 586656e

Please sign in to comment.