Skip to content

Commit 37c7488

Browse files
ianwphilpep
authored andcommitted
Add architecture to sysinfo
This allows you to switch on the host architecture easily. "uname -m" seems to be globally acceptable on unix-y hosts, Windows has %PROCESSOR_ARCHITECTURE%.
1 parent 9044fe4 commit 37c7488

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

test/test_modules.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ def test_uninstalled_package_version(host):
9090
def test_systeminfo(host, docker_image):
9191
assert host.system_info.type == "linux"
9292

93-
release, distribution, codename = {
94-
"alpine": (r"^3\.11\.", "alpine", None),
95-
"archlinux": ("rolling", "arch", None),
96-
"centos_6": (r"^6", "CentOS", None),
97-
"centos_7": (r"^7$", "centos", None),
98-
"debian_buster": (r"^10", "debian", "buster"),
99-
"ubuntu_xenial": (r"^16\.04$", "ubuntu", "xenial")
93+
release, distribution, codename, arch = {
94+
"alpine": (r"^3\.11\.", "alpine", None, 'x86_64'),
95+
"archlinux": ("rolling", "arch", None, 'x86_64'),
96+
"centos_6": (r"^6", "CentOS", None, 'x86_64'),
97+
"centos_7": (r"^7$", "centos", None, 'x86_64'),
98+
"debian_buster": (r"^10", "debian", "buster", 'x86_64'),
99+
"ubuntu_xenial": (r"^16\.04$", "ubuntu", "xenial", 'x86_64')
100100
}[docker_image]
101101

102102
assert host.system_info.distribution == distribution

testinfra/modules/systeminfo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def sysinfo(self):
2626
"distribution": None,
2727
"codename": None,
2828
"release": None,
29+
"arch": None,
2930
}
3031
uname = self.run_expect([0, 1], 'uname -s')
3132
if uname.rc == 1:
@@ -42,6 +43,8 @@ def sysinfo(self):
4243
sysinfo["release"] = self.check_output("uname -r")
4344
sysinfo["distribution"] = sysinfo["type"]
4445
sysinfo["codename"] = None
46+
47+
sysinfo["arch"] = self.check_output("uname -m")
4548
return sysinfo
4649

4750
def _get_linux_sysinfo(self):
@@ -128,6 +131,7 @@ def _get_windows_sysinfo(self):
128131
sysinfo["type"] = value.split(" ")[1].lower()
129132
elif key == "os_version":
130133
sysinfo["release"] = value
134+
sysinfo["arch"] = self.check_output('echo %PROCESSOR_ARCHITECTURE%')
131135
return sysinfo
132136

133137
@property
@@ -165,3 +169,12 @@ def codename(self):
165169
'buster'
166170
"""
167171
return self.sysinfo["codename"]
172+
173+
@property
174+
def arch(self):
175+
"""Host architecture
176+
177+
>>> host.system_info.arch
178+
'x86_64'
179+
"""
180+
return self.sysinfo["arch"]

0 commit comments

Comments
 (0)