Skip to content

Commit

Permalink
Fix is_masked method on systemd service (#569)
Browse files Browse the repository at this point in the history
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 <phil@philpep.org>
  • Loading branch information
dorianm and philpep committed Sep 3, 2020
1 parent 8d124dc commit ce543e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ def test_ssh_service(host, docker_image):
assert ssh.is_enabled


def test_service_systemd_mask(host):
ssh = host.service("ssh")
assert not ssh.is_masked
host.run("systemctl mask ssh")
assert ssh.is_masked
host.run("systemctl unmask ssh")
assert not ssh.is_masked


@pytest.mark.parametrize("name,running,enabled", [
("ntp", False, True),
("salt-minion", False, False),
Expand Down
2 changes: 1 addition & 1 deletion testinfra/modules/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def is_valid(self):
@property
def is_masked(self):
cmd = self.run_test("systemctl is-enabled %s", self.name)
return cmd.rc == 0 and cmd.stdout.strip() == "masked"
return cmd.stdout.strip() == "masked"


class UpstartService(SysvService):
Expand Down

0 comments on commit ce543e2

Please sign in to comment.