summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMina Galić <me+git@igalic.co>2022-10-06 16:38:46 +0100
committerGitHub <noreply@github.com>2022-10-06 09:38:46 -0600
commitd7c6419bea0525965e08bab615c392c9c3aeb153 (patch)
tree449f7230e34ecea4b1ada7023423925c79122d76
parent0f005bf4973c093aab6fe8728bd50702126d511e (diff)
downloadcloud-init-git-d7c6419bea0525965e08bab615c392c9c3aeb153.tar.gz
distros/manage_services: add support to disable service (#1772)
in order to support some modules on BSD, which could replace base-services, we'll need to be able to disable those base-services. This PR adds support for the "disable" command to 'systemct', BSD 'service', and OpenBSD 'rcctl', which currently suppor that. For SysV init 'service', we follow the 'enable' path, and 'stop' the service instead. LP: #1991024 Sponsored by: FreeBSD Foundation
-rw-r--r--cloudinit/distros/__init__.py2
-rw-r--r--cloudinit/distros/freebsd.py1
-rw-r--r--cloudinit/distros/openbsd.py1
-rw-r--r--tests/unittests/distros/test_manage_service.py10
4 files changed, 12 insertions, 2 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 6fee7328..5ba61b1e 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -920,6 +920,7 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta):
"stop": ["stop", service],
"start": ["start", service],
"enable": ["enable", service],
+ "disable": ["disable", service],
"restart": ["restart", service],
"reload": ["reload-or-restart", service],
"try-reload": ["reload-or-try-restart", service],
@@ -930,6 +931,7 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta):
"stop": [service, "stop"],
"start": [service, "start"],
"enable": [service, "start"],
+ "disable": [service, "stop"],
"restart": [service, "restart"],
"reload": [service, "restart"],
"try-reload": [service, "restart"],
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index 68a9f300..b9fd37b8 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -49,6 +49,7 @@ class Distro(cloudinit.distros.bsd.BSD):
"stop": [service, "stop"],
"start": [service, "start"],
"enable": [service, "enable"],
+ "disable": [service, "disable"],
"restart": [service, "restart"],
"reload": [service, "restart"],
"try-reload": [service, "restart"],
diff --git a/cloudinit/distros/openbsd.py b/cloudinit/distros/openbsd.py
index 9ef33bf2..72e9bc45 100644
--- a/cloudinit/distros/openbsd.py
+++ b/cloudinit/distros/openbsd.py
@@ -36,6 +36,7 @@ class Distro(cloudinit.distros.netbsd.NetBSD):
"stop": ["stop", service],
"start": ["start", service],
"enable": ["enable", service],
+ "disable": ["disable", service],
"restart": ["restart", service],
"reload": ["restart", service],
"try-reload": ["restart", service],
diff --git a/tests/unittests/distros/test_manage_service.py b/tests/unittests/distros/test_manage_service.py
index e53baf9a..a6b8a3dc 100644
--- a/tests/unittests/distros/test_manage_service.py
+++ b/tests/unittests/distros/test_manage_service.py
@@ -52,5 +52,11 @@ class TestManageService(CiTestCase):
["systemctl", "start", "myssh"], capture=True
)
-
-# vi: ts=4 sw=4 expandtab
+ @mock.patch.object(MockDistro, "uses_systemd", return_value=True)
+ @mock.patch("cloudinit.distros.subp.subp")
+ def test_manage_service_disable_systemctl(self, m_subp, m_sysd):
+ self.dist.init_cmd = ["ignore"]
+ self.dist.manage_service("disable", "myssh")
+ m_subp.assert_called_with(
+ ["systemctl", "disable", "myssh"], capture=True
+ )