Skip to content

Commit 146962c

Browse files
F
1 parent 88a0aa1 commit 146962c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

test/test_modules.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def test_service_systemd_mask(host, docker_image):
137137
assert not ssh.is_masked
138138

139139

140+
@all_images
140141
def test_service_systemd_ssh(host, docker_image):
141142
name = "sshd" if docker_image == "rockylinux9" else "ssh"
142143
ssh = host.service(name)
@@ -149,19 +150,23 @@ def test_service_systemd_ssh(host, docker_image):
149150
@pytest.mark.testinfra_hosts("docker://rockylinux9")
150151
def test_service_systemd_root_mount(host):
151152
root = host.service("-.mount") # systemd unit for mounting /
152-
assert root.exists
153-
assert root.is_valid
154-
assert root.is_enabled
155-
assert root.is_running
153+
x = host.run("systemctl status -- -.mount")
154+
raise AssertionError(f"{x.stdout}\n{x.stderr}")
155+
# assert root.exists
156+
# x = root.is_valid
157+
# raise AssertionError(f"{x}")
158+
# assert root.is_valid
159+
# assert root.is_enabled
160+
# assert root.is_running
156161

157162

158163
@pytest.mark.testinfra_hosts("docker://rockylinux9")
159164
def test_service_systemd_tmp_mount(host):
160165
tmp = host.service("tmp.mount")
161166
assert tmp.exists
162167
assert tmp.is_valid
163-
assert tmp.is_enabled
164-
assert tmp.is_running
168+
assert not tmp.is_enabled
169+
assert not tmp.is_running
165170

166171

167172
def test_salt(host):

testinfra/modules/service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ def _has_systemd_suffix(self):
176176

177177
@property
178178
def exists(self):
179-
cmd = self.run_test('systemctl list-unit-files | grep -q -- "^%s"', self.name)
180-
return cmd.rc == 0
179+
# systemctl return codes based on https://man7.org/linux/man-pages/man1/systemctl.1.html:
180+
# 0: unit is active
181+
# 1: unit not failed (used by is-failed)
182+
# 2: unused
183+
# 3: unit is not active
184+
# 4: no such unit
185+
cmd = self.run_expect([0, 1, 3, 4], "systemctl status -- %s", self.name)
186+
return cmd.rc < 4
181187

182188
@property
183189
def is_running(self):

0 commit comments

Comments
 (0)