From a770b661ea8bad5411ec260a6e01b19da928996a Mon Sep 17 00:00:00 2001 From: Martin Perina Date: Tue, 20 Feb 2024 15:09:55 +0100 Subject: [PATCH] Add test for disable service in bluechictl We have a test to verify bluechictl can enable disabled service. This commit also add test if bluechictl can disable enabled service. Signed-off-by: Martin Perina --- tests/bluechi_test/bluechictl.py | 9 +++++++++ .../tests/tier0/bluechi-enable-disable-service/main.fmf | 2 ++ .../systemd/simple.service | 0 .../test_bluechi_enable_disable_service.py} | 5 +++++ tests/tests/tier0/bluechi-enable-service/main.fmf | 2 -- 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/tests/tier0/bluechi-enable-disable-service/main.fmf rename tests/tests/tier0/{bluechi-enable-service => bluechi-enable-disable-service}/systemd/simple.service (100%) rename tests/tests/tier0/{bluechi-enable-service/test_bluechi_enable_service.py => bluechi-enable-disable-service/test_bluechi_enable_disable_service.py} (87%) delete mode 100644 tests/tests/tier0/bluechi-enable-service/main.fmf diff --git a/tests/bluechi_test/bluechictl.py b/tests/bluechi_test/bluechictl.py index 50435c3efe..0782690d66 100644 --- a/tests/bluechi_test/bluechictl.py +++ b/tests/bluechi_test/bluechictl.py @@ -78,6 +78,15 @@ def enable_unit(self, node_name: str, unit_name: str, check_result: bool = True, expected_result ) + def disable_unit(self, node_name: str, unit_name: str, check_result: bool = True, expected_result: int = 0) \ + -> Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]: + return self._run( + f"Disabling unit '{unit_name}' on node '{node_name}'", + f"disable {node_name} {unit_name}", + check_result, + expected_result + ) + def freeze_unit(self, node_name: str, unit_name: str, check_result: bool = True, expected_result: int = 0) \ -> Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]: return self._run( diff --git a/tests/tests/tier0/bluechi-enable-disable-service/main.fmf b/tests/tests/tier0/bluechi-enable-disable-service/main.fmf new file mode 100644 index 0000000000..42f09faeac --- /dev/null +++ b/tests/tests/tier0/bluechi-enable-disable-service/main.fmf @@ -0,0 +1,2 @@ +summary: Test if a disabled systemd service can be enabled and then disabled again using bluechictl +id: e3ec3cb3-1010-4205-9b99-507233c6a8f1 diff --git a/tests/tests/tier0/bluechi-enable-service/systemd/simple.service b/tests/tests/tier0/bluechi-enable-disable-service/systemd/simple.service similarity index 100% rename from tests/tests/tier0/bluechi-enable-service/systemd/simple.service rename to tests/tests/tier0/bluechi-enable-disable-service/systemd/simple.service diff --git a/tests/tests/tier0/bluechi-enable-service/test_bluechi_enable_service.py b/tests/tests/tier0/bluechi-enable-disable-service/test_bluechi_enable_disable_service.py similarity index 87% rename from tests/tests/tier0/bluechi-enable-service/test_bluechi_enable_service.py rename to tests/tests/tier0/bluechi-enable-disable-service/test_bluechi_enable_disable_service.py index b116d6792a..be05ac7841 100644 --- a/tests/tests/tier0/bluechi-enable-service/test_bluechi_enable_service.py +++ b/tests/tests/tier0/bluechi-enable-disable-service/test_bluechi_enable_disable_service.py @@ -29,6 +29,11 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): if not foo.systemctl.is_unit_enabled(simple_service, check_result=False): raise Exception(f"Unit {simple_service} expected to be enabled, but is not") + ctrl.bluechictl.disable_unit(node_foo_name, simple_service) + + if not foo.systemctl.is_unit_disabled(simple_service, check_result=False): + raise Exception(f"Unit {simple_service} expected to be disabled, but is not") + def test_proxy_service_start( bluechi_test: BluechiTest, diff --git a/tests/tests/tier0/bluechi-enable-service/main.fmf b/tests/tests/tier0/bluechi-enable-service/main.fmf deleted file mode 100644 index c027c76a92..0000000000 --- a/tests/tests/tier0/bluechi-enable-service/main.fmf +++ /dev/null @@ -1,2 +0,0 @@ -summary: Test if a disabled systemd service can be enabled using bluechictl -id: e3ec3cb3-1010-4205-9b99-507233c6a8f1