Skip to content

Commit 0ed9d7a

Browse files
Ignore non-relevant messages from "systemd-analyze verify"
1 parent dca7b05 commit 0ed9d7a

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

test/test_modules.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,41 @@ 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_ssh(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_enabled
146+
assert ssh.is_running
147+
148+
149+
def test_service_systemd_root_mount(host):
150+
root = host.service("-.mount") # systemd unit for mounting /
151+
assert root.exists
152+
assert root.is_valid
153+
assert root.is_enabled
154+
assert root.is_running
155+
156+
157+
def test_service_systemd_tmp_mount(host):
158+
tmp = host.service("tmp.mount")
159+
assert tmp.exists
160+
assert tmp.is_valid
161+
assert tmp.is_enabled
162+
assert tmp.is_running
163+
164+
139165
def test_salt(host):
140166
ssh_version = host.salt("pkg.version", "openssh-server", local=True)
141167
assert ssh_version.startswith("1:9.2")

testinfra/modules/service.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,24 @@ def is_valid(self):
213213
name = self.name if self._has_systemd_suffix() else f"{self.name}.service"
214214
cmd = self.run("systemd-analyze verify %s", name)
215215
# A bad unit file still returns a rc of 0, so check the
216-
# stdout for anything. Nothing means no warns/errors.
216+
# 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 non-relevant messages from the output of "systemd-analyze
221+
# verify":
222+
# "Unit is bound to inactive unit"
223+
# "ssh.service: Command 'man sshd(8)' failed with code"
224+
# --man=no: suppress the man page existence check
225+
# implemented in Systemd 235 (2017-10-06)
226+
stderr_lines = [
227+
i
228+
for i in cmd.stderr.splitlines()
229+
if "Unit is bound to inactive unit" not in i and ": Command 'man" not in i
230+
]
231+
232+
stderr = "".join(stderr_lines)
233+
return (cmd.stdout, stderr) == ("", "")
221234

222235
@property
223236
def is_masked(self):

0 commit comments

Comments
 (0)