Skip to content

Commit

Permalink
add bluechi_is_online system integration test
Browse files Browse the repository at this point in the history
Signed-off-by: nsimsolo <[email protected]>
  • Loading branch information
nsimsolo committed Dec 10, 2024
1 parent bdc597e commit f91ee9e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/tests/tier0/bluechi-is-online-system/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: on the controller machine test the connection of all nodes to the controller
id: 353da9bd-1a92-431a-8f32-e4940b8aa3e2
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# Copyright Contributors to the Eclipse BlueChi project
#
# SPDX-License-Identifier: LGPL-2.1-or-later
import logging
from typing import Dict

from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
from bluechi_test.test import BluechiTest

LOGGER = logging.getLogger(__name__)

AGENT_ONE = "agent-one"
AGENT_TWO = "agent-two"


def check_exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
agent_one = nodes[AGENT_ONE]
agent_two = nodes[AGENT_TWO]

# Test 1: Both agents and controller are online
LOGGER.debug("Testing with both agents and controller online.")
result, output = ctrl.exec_run("bluechi-is-online system")
assert result == 0, "Expected successful execution of bluechi-is-online system"
assert not output, "Expected no output when all agents are online"

# Test 2: Agent-one offline
LOGGER.debug("Stopping agent-one.")
agent_one.systemctl.stop_unit("bluechi-agent")
assert agent_one.wait_for_unit_state_to_be("bluechi-agent", "inactive")

result, output = ctrl.exec_run("bluechi-is-online system")
assert (
result != 0
), "Expected failure of bluechi-is-online system when agent-one is offline"

# Bring agent-one back online
LOGGER.debug("Starting agent-one.")
agent_one.systemctl.start_unit("bluechi-agent")
assert agent_one.wait_for_unit_state_to_be("bluechi-agent", "active")

# Test 3: Agent-two offline
LOGGER.debug("Stopping agent-two.")
agent_two.systemctl.stop_unit("bluechi-agent")
assert agent_two.wait_for_unit_state_to_be("bluechi-agent", "inactive")

result, output = ctrl.exec_run("bluechi-is-online system")
assert (
result != 0
), "Expected failure of bluechi-is-online system when agent-two is offline"

# Bring agent-two back online
LOGGER.debug("Starting agent-two.")
agent_two.systemctl.start_unit("bluechi-agent")
assert agent_two.wait_for_unit_state_to_be("bluechi-agent", "active")

# Test 4: Controller offline
LOGGER.debug("Stopping the controller.")
ctrl.systemctl.stop_unit("bluechi-controller")
assert ctrl.wait_for_unit_state_to_be("bluechi-controller", "inactive")

result, output = ctrl.exec_run("bluechi-is-online system")
assert (
result != 0
), "Expected failure of bluechi-is-online system when the controller is offline"

# Restart the controller
LOGGER.debug("Starting the controller.")
ctrl.systemctl.start_unit("bluechi-controller")
assert ctrl.wait_for_unit_state_to_be("bluechi-controller", "active")


def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
check_exec(
ctrl=ctrl, nodes={AGENT_ONE: nodes[AGENT_ONE], AGENT_TWO: nodes[AGENT_TWO]}
)


def test_bluechi_is_online_system(
bluechi_test: BluechiTest,
bluechi_node_default_config: BluechiAgentConfig,
bluechi_ctrl_default_config: BluechiControllerConfig,
):

agent_one_cfg = bluechi_node_default_config.deep_copy()
agent_one_cfg.node_name = AGENT_ONE

agent_two_cfg = bluechi_node_default_config.deep_copy()
agent_two_cfg.node_name = AGENT_TWO

bluechi_ctrl_default_config.allowed_node_names = [AGENT_ONE, AGENT_TWO]

bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
bluechi_test.add_bluechi_agent_config(agent_one_cfg)
bluechi_test.add_bluechi_agent_config(agent_two_cfg)

bluechi_test.run(exec)

0 comments on commit f91ee9e

Please sign in to comment.