Skip to content

Commit 5d1bcde

Browse files
committedNov 16, 2021
linux: fix get_systemd_version not parsing raw type correctly
The newly added test of get_systemd_status failed for old systemd with > assert status['systemd-resolved.service']["type"] == '' E assert '"' == '' E + " tests/test_linux.py:36: AssertionError so refactor parsing of path_and_id to fix that. Signed-off-by: Adam Trhon <adam.trhon@tbs-biometrics.com>
1 parent f7e1af1 commit 5d1bcde

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎tests/test_linux.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
from labgridhelper import linux
2+
import pytest
23

34
def test_get_systemd_version(command, monkeypatch):
45
systemd_version = 'systemd 249 (249.5-2-arch)\n+PAM +AUDIT -SELINUX\n'
56

67
monkeypatch.setattr(command, 'run_check', lambda cmd: [systemd_version])
78

89
assert linux.get_systemd_version(command) == 249
10+
11+
@pytest.mark.parametrize("systemd_version", [230, 240])
12+
def test_get_systemd_status(command, monkeypatch, systemd_version):
13+
monkeypatch.setattr(linux, 'get_systemd_version', lambda cmd: systemd_version)
14+
15+
status = {
16+
230: 'a(ssssssouso) 1 "systemd-resolved.service" "Network Name Resolution" "loaded" "active"' + \
17+
' "running" "" "/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice" 0 "" "/"',
18+
240: '{"type":"a(ssssssouso)","data":[[["systemd-resolved.service",' + \
19+
'"Network Name Resolution","loaded","active","running","",' + \
20+
'"/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice",0,"","/"]]]}',
21+
}
22+
23+
monkeypatch.setattr(command, 'run_check', lambda cmd: [status[systemd_version]])
24+
25+
status = linux.get_systemd_status(command)
26+
27+
assert len(status.keys()) == 1
28+
assert status['systemd-resolved.service']["description"] == 'Network Name Resolution'
29+
assert status['systemd-resolved.service']["load"] == 'loaded'
30+
assert status['systemd-resolved.service']["active"] == 'active'
31+
assert status['systemd-resolved.service']["sub"] == 'running'
32+
assert status['systemd-resolved.service']["follow"] == ''
33+
assert status['systemd-resolved.service']["path"] == '/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice'
34+
assert status['systemd-resolved.service']["id"] == 0
35+
assert status['systemd-resolved.service']["type"] == ''
36+
assert status['systemd-resolved.service']["objpath"] == '/'

0 commit comments

Comments
 (0)