Skip to content

Commit ce543e2

Browse files
dorianmphilpep
andauthored
Fix is_masked method on systemd service (#569)
systemctl is-enabled my-service` rc is 1 if the service is masked. Add test for is_masked method on systemd service Co-authored-by: Philippe Pepiot <[email protected]>
1 parent 8d124dc commit ce543e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

test/test_modules.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ def test_ssh_service(host, docker_image):
132132
assert ssh.is_enabled
133133

134134

135+
def test_service_systemd_mask(host):
136+
ssh = host.service("ssh")
137+
assert not ssh.is_masked
138+
host.run("systemctl mask ssh")
139+
assert ssh.is_masked
140+
host.run("systemctl unmask ssh")
141+
assert not ssh.is_masked
142+
143+
135144
@pytest.mark.parametrize("name,running,enabled", [
136145
("ntp", False, True),
137146
("salt-minion", False, False),

testinfra/modules/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def is_valid(self):
153153
@property
154154
def is_masked(self):
155155
cmd = self.run_test("systemctl is-enabled %s", self.name)
156-
return cmd.rc == 0 and cmd.stdout.strip() == "masked"
156+
return cmd.stdout.strip() == "masked"
157157

158158

159159
class UpstartService(SysvService):

0 commit comments

Comments
 (0)