diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..26d33521af --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/bluechi.iml b/.idea/bluechi.iml new file mode 100644 index 0000000000..0eb4c41c90 --- /dev/null +++ b/.idea/bluechi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..105ce2da2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..013d4cf110 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..1efb59e2da --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/bluechi_test/bluechi_is_online.py b/tests/bluechi_test/bluechi_is_online.py index f090639dac..92de494143 100644 --- a/tests/bluechi_test/bluechi_is_online.py +++ b/tests/bluechi_test/bluechi_is_online.py @@ -34,3 +34,12 @@ def agent_is_online(self) -> bool: 0, ) return result == 0 + + def node_is_online(self, node_name: str) -> bool: + result, output = self.run( + "Checking controller status.", + f"node {node_name}", + False, + 0, + ) + return result == 0 diff --git a/tests/tests/tier0/bluechi-is-online-node/main.fmf b/tests/tests/tier0/bluechi-is-online-node/main.fmf new file mode 100644 index 0000000000..8a4c1e9415 --- /dev/null +++ b/tests/tests/tier0/bluechi-is-online-node/main.fmf @@ -0,0 +1,2 @@ +summary: on the controller machine test the connection of the given node to the controller +id: fa5a2ff8-fbea-4a0c-8106-a8cb2c295581 diff --git a/tests/tests/tier0/bluechi-is-online-node/test_bluechi_is_online_node.py b/tests/tests/tier0/bluechi-is-online-node/test_bluechi_is_online_node.py new file mode 100644 index 0000000000..47f0635a4a --- /dev/null +++ b/tests/tests/tier0/bluechi-is-online-node/test_bluechi_is_online_node.py @@ -0,0 +1,46 @@ +# +# Copyright Contributors to the Eclipse BlueChi project +# +# SPDX-License-Identifier: LGPL-2.1-or-later +from typing import Dict + +from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig +from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine +from bluechi_test.test import BluechiTest + +NODE_FOO = "node-foo" + + +def check_execs(ctrl: BluechiControllerMachine, node: BluechiAgentMachine): + # Check that the BlueChi controller is online at the startup + result = ctrl.bluechi_is_online.node_is_online(node_name=NODE_FOO) + assert result, f"bluechi-agent for node {node.name} should be online" + + # Stop the BlueChi controller + node.systemctl.stop_unit("bluechi-agent") + assert node.wait_for_unit_state_to_be("bluechi-agent", "inactive") + + # Check that the BlueChi controller is offline + result = ctrl.bluechi_is_online.node_is_online(node_name=NODE_FOO) + assert not result, f"bluechi-agent for node {node.name} should be offline" + + +def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): + node_foo = nodes.get(NODE_FOO) + check_execs(ctrl=ctrl, node=node_foo) + + +def test_bluechi_is_online_controller( + bluechi_test: BluechiTest, + bluechi_node_default_config: BluechiAgentConfig, + bluechi_ctrl_default_config: BluechiControllerConfig, +): + node_foo_cfg = bluechi_node_default_config.deep_copy() + node_foo_cfg.node_name = NODE_FOO + + bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO] + + bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) + bluechi_test.add_bluechi_agent_config(node_foo_cfg) + + bluechi_test.run(exec)