-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
55922ea
commit 9fbee9c
Showing
2 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
from labgridhelper import linux | ||
import pytest | ||
|
||
def test_get_systemd_version(command, monkeypatch): | ||
systemd_version = 'systemd 249 (249.5-2-arch)\n+PAM +AUDIT -SELINUX\n' | ||
|
||
monkeypatch.setattr(command, 'run_check', lambda cmd: [systemd_version]) | ||
|
||
assert linux.get_systemd_version(command) == 249 | ||
|
||
@pytest.mark.parametrize("systemd_version", [230, 240]) | ||
def test_get_systemd_status(command, monkeypatch, systemd_version): | ||
monkeypatch.setattr(linux, 'get_systemd_version', lambda cmd: systemd_version) | ||
|
||
status = { | ||
230: 'a(ssssssouso) 1 "systemd-resolved.service" "Network Name Resolution" "loaded" "active"' + \ | ||
' "running" "" "/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice" 0 "" "/"', | ||
240: '{"type":"a(ssssssouso)","data":[[["systemd-resolved.service",' + \ | ||
'"Network Name Resolution","loaded","active","running","",' + \ | ||
'"/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice",0,"","/"]]]}', | ||
} | ||
|
||
monkeypatch.setattr(command, 'run_check', lambda cmd: [status[systemd_version]]) | ||
|
||
status = linux.get_systemd_status(command) | ||
|
||
assert len(status.keys()) == 1 | ||
assert status['systemd-resolved.service']["description"] == 'Network Name Resolution' | ||
assert status['systemd-resolved.service']["load"] == 'loaded' | ||
assert status['systemd-resolved.service']["active"] == 'active' | ||
assert status['systemd-resolved.service']["sub"] == 'running' | ||
assert status['systemd-resolved.service']["follow"] == '' | ||
assert status['systemd-resolved.service']["path"] == '/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice' | ||
assert status['systemd-resolved.service']["id"] == 0 | ||
assert status['systemd-resolved.service']["type"] == '' | ||
assert status['systemd-resolved.service']["objpath"] == '/' |