Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bluechi_is_online system integration test #1006

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/bluechi_test/bluechi_is_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ def node_is_online(self, node_name: str) -> bool:
0,
)
return result == 0

def system_is_online(self) -> bool:
result, output = self.run(
"Checking system status.",
"system",
False,
0,
)
return result == 0
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: Test that the system check of bluechi-is-online works as expected for connections 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,92 @@
#
# 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 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.")
assert ctrl.bluechi_is_online.system_is_online(), "Expected system to be online"

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

assert (
not ctrl.bluechi_is_online.system_is_online()
), "Expected system to report offline when agent-one is inactive"

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

# Test 3: Agent-two offline
engelmi marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.debug("Stopping agent-two.")
agent_two.systemctl.stop_unit("bluechi-agent")

assert (
not ctrl.bluechi_is_online.system_is_online()
), "Expected system to report offline when agent-two is inactive"

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

# Test 4: Both agents are offline
LOGGER.debug("Stopping both agents.")
agent_one.systemctl.stop_unit("bluechi-agent")
agent_two.systemctl.stop_unit("bluechi-agent")

assert (
not ctrl.bluechi_is_online.system_is_online()
), "Expected system to report offline when any agent is inactive"

# Bring both agents back online
LOGGER.debug("Starting both agents.")
agent_one.systemctl.start_unit("bluechi-agent")
agent_two.systemctl.start_unit("bluechi-agent")

# Test 5: Controller offline
LOGGER.debug("Stopping the controller.")
ctrl.systemctl.stop_unit("bluechi-controller")

assert not ctrl.bluechi_is_online.system_is_online(), (
"Expected system to report offline when the controller is " "inactive"
)


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)
Loading