Skip to content

Commit 2212173

Browse files
Add "--" delimiter to support mount unit for /
The mount unit for the / filesystem is named -.mount. It is treated like an option because it begins with a “-”. It is fixed with the delimiter “--”, which is inserted before the unit.
1 parent 6b0d230 commit 2212173

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

test/test_modules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_service_systemd_ssh(host, docker_image):
147147
assert ssh_service.is_running
148148

149149

150+
@pytest.mark.testinfra_hosts("docker://rockylinux9")
150151
def test_service_systemd_root_mount(host):
151152
root_mount_service = host.service("-.mount") # systemd unit for mounting /
152153
assert root_mount_service.exists
@@ -176,6 +177,7 @@ def test_service_systemd_root_mount_is_enabled(host):
176177
assert not root_mount_service.is_enabled
177178

178179

180+
@pytest.mark.testinfra_hosts("docker://rockylinux9")
179181
def test_service_systemd_tmp_mount(host):
180182
tmp = host.service("tmp.mount")
181183
assert tmp.exists

testinfra/modules/service.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SystemdService(SysvService):
169169

170170
def _has_systemd_suffix(self):
171171
"""
172-
Check if service name has a known systemd unit suffix
172+
Check if the service name has a known systemd unit suffix
173173
"""
174174
unit_suffix = self.name.split(".")[-1]
175175
return unit_suffix in self.suffix_list
@@ -182,7 +182,7 @@ def exists(self):
182182
# 2: unused
183183
# 3: unit is not active
184184
# 4: no such unit
185-
cmd = self.run_expect([0, 1, 3, 4], "systemctl status %s", self.name)
185+
cmd = self.run_expect([0, 1, 3, 4], "systemctl status -- %s", self.name)
186186
return cmd.rc < 4
187187

188188
@property
@@ -192,15 +192,15 @@ def is_running(self):
192192
# 1: program is dead and pid file exists
193193
# 3: not running and pid file does not exists
194194
# 4: Unable to determine status (no such unit)
195-
out = self.run_expect([0, 1, 3, 4], "systemctl is-active %s", self.name)
195+
out = self.run_expect([0, 1, 3, 4], "systemctl is-active -- %s", self.name)
196196
if out.rc == 1:
197197
# Failed to connect to bus: No such file or directory
198198
return super().is_running
199199
return out.rc == 0
200200

201201
@property
202202
def is_enabled(self):
203-
cmd = self.run_test("systemctl is-enabled %s", self.name)
203+
cmd = self.run_test("systemctl is-enabled -- %s", self.name)
204204
if cmd.rc == 0:
205205
return True
206206
if cmd.stdout.strip() == "disabled":
@@ -217,7 +217,7 @@ def is_enabled(self):
217217
def is_valid(self):
218218
# systemd-analyze requires a full unit name.
219219
name = self.name if self._has_systemd_suffix() else f"{self.name}.service"
220-
cmd = self.run("systemd-analyze verify %s", name)
220+
cmd = self.run("systemd-analyze verify -- %s", name)
221221
# A bad unit file still returns a rc of 0, so check the
222222
# stdout for anything. Nothing means no warns/errors.
223223
# Docs at https://www.freedesktop.org/software/systemd/man/systemd
@@ -240,16 +240,17 @@ def is_valid(self):
240240
]
241241

242242
stderr = "".join(stderr_lines)
243-
return (cmd.stdout, stderr) == ("", "")
243+
return (cmd.stdout, stderr)
244+
# return (cmd.stdout, stderr) == ("", "")
244245

245246
@property
246247
def is_masked(self):
247-
cmd = self.run_test("systemctl is-enabled %s", self.name)
248+
cmd = self.run_test("systemctl is-enabled -- %s", self.name)
248249
return cmd.stdout.strip() == "masked"
249250

250251
@functools.cached_property
251252
def systemd_properties(self):
252-
out = self.check_output("systemctl show %s", self.name)
253+
out = self.check_output("systemctl show -- %s", self.name)
253254
out_d = {}
254255
if out:
255256
# maxsplit is required because values can contain `=`

0 commit comments

Comments
 (0)