Skip to content

Commit 88a0aa1

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 0ed9d7a commit 88a0aa1

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
@@ -146,6 +146,7 @@ def test_service_systemd_ssh(host, docker_image):
146146
assert ssh.is_running
147147

148148

149+
@pytest.mark.testinfra_hosts("docker://rockylinux9")
149150
def test_service_systemd_root_mount(host):
150151
root = host.service("-.mount") # systemd unit for mounting /
151152
assert root.exists
@@ -154,6 +155,7 @@ def test_service_systemd_root_mount(host):
154155
assert root.is_running
155156

156157

158+
@pytest.mark.testinfra_hosts("docker://rockylinux9")
157159
def test_service_systemd_tmp_mount(host):
158160
tmp = host.service("tmp.mount")
159161
assert tmp.exists

testinfra/modules/service.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ 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
176176

177177
@property
178178
def exists(self):
179-
cmd = self.run_test('systemctl list-unit-files | grep -q "^%s"', self.name)
179+
cmd = self.run_test('systemctl list-unit-files | grep -q -- "^%s"', self.name)
180180
return cmd.rc == 0
181181

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

195195
@property
196196
def is_enabled(self):
197-
cmd = self.run_test("systemctl is-enabled %s", self.name)
197+
cmd = self.run_test("systemctl is-enabled -- %s", self.name)
198198
if cmd.rc == 0:
199199
return True
200200
if cmd.stdout.strip() == "disabled":
@@ -211,7 +211,7 @@ def is_enabled(self):
211211
def is_valid(self):
212212
# systemd-analyze requires a full unit name.
213213
name = self.name if self._has_systemd_suffix() else f"{self.name}.service"
214-
cmd = self.run("systemd-analyze verify %s", name)
214+
cmd = self.run("systemd-analyze verify -- %s", name)
215215
# A bad unit file still returns a rc of 0, so check the
216216
# stdout for anything. Nothing means no warns/errors.
217217
# Docs at https://www.freedesktop.org/software/systemd/man/systemd
@@ -230,16 +230,17 @@ def is_valid(self):
230230
]
231231

232232
stderr = "".join(stderr_lines)
233-
return (cmd.stdout, stderr) == ("", "")
233+
return (cmd.stdout, stderr)
234+
# return (cmd.stdout, stderr) == ("", "")
234235

235236
@property
236237
def is_masked(self):
237-
cmd = self.run_test("systemctl is-enabled %s", self.name)
238+
cmd = self.run_test("systemctl is-enabled -- %s", self.name)
238239
return cmd.stdout.strip() == "masked"
239240

240241
@functools.cached_property
241242
def systemd_properties(self):
242-
out = self.check_output("systemctl show %s", self.name)
243+
out = self.check_output("systemctl show -- %s", self.name)
243244
out_d = {}
244245
if out:
245246
# maxsplit is required because values can contain `=`

0 commit comments

Comments
 (0)