Skip to content

Commit 29d9b34

Browse files
Ignore useless messages from "systemd-analyze verify"
1 parent dca7b05 commit 29d9b34

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

test/test_modules.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,34 @@ def test_ssh_service(host, docker_image):
127127
assert ssh.is_enabled
128128

129129

130-
def test_service_systemd_mask(host):
131-
ssh = host.service("ssh")
130+
def test_service_systemd_mask(host, docker_image):
131+
name = "sshd" if docker_image == "rockylinux9" else "ssh"
132+
ssh = host.service(name)
132133
assert not ssh.is_masked
133134
host.run("systemctl mask ssh")
134135
assert ssh.is_masked
135136
host.run("systemctl unmask ssh")
136137
assert not ssh.is_masked
137138

138139

140+
def test_service_systemd_is_valid(host, docker_image):
141+
name = "sshd" if docker_image == "rockylinux9" else "ssh"
142+
ssh = host.service(name)
143+
assert ssh.exists
144+
assert ssh.is_valid
145+
assert ssh.is_active
146+
147+
root = host.service("-.mount") # systemd unit for mounting /
148+
assert root.exists
149+
assert root.is_valid
150+
assert root.is_active
151+
152+
tmp = host.service("tmp.mount")
153+
assert tmp.exists
154+
assert tmp.is_valid
155+
assert tmp.is_active
156+
157+
139158
def test_salt(host):
140159
ssh_version = host.salt("pkg.version", "openssh-server", local=True)
141160
assert ssh_version.startswith("1:9.2")

testinfra/modules/service.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,16 @@ def is_valid(self):
216216
# stdout for anything. Nothing means no warns/errors.
217217
# Docs at https://www.freedesktop.org/software/systemd/man/systemd
218218
# -analyze.html#Examples%20for%20verify
219-
assert (cmd.stdout, cmd.stderr) == ("", "")
220-
return True
219+
220+
# ignore "Unit is bound to inactive unit" messages
221+
stderr_lines = [
222+
l
223+
for l in cmd.stderr.splitlines()
224+
if "Unit is bound to inactive unit" not in l
225+
]
226+
227+
stderr = "".join(stderr_lines)
228+
return (cmd.stdout, stderr) == ("", "")
221229

222230
@property
223231
def is_masked(self):

0 commit comments

Comments
 (0)