-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bluechi_is_online module and initial test
- Adds bluechi_is_online module to provide bluechi-is-online methods to Python code. - Adds a test to verify `bluechi-is-online agent` invocation without additional parameters. Signed-off-by: Dana Orr <[email protected]>
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union | ||
|
||
from bluechi_test.client import Client | ||
|
||
|
||
class BluechiIsOnline: | ||
|
||
binary_name = "bluechi-is-online" | ||
|
||
def __init__(self, client: Client) -> None: | ||
self.client = client | ||
self.tracked_services: Dict[str, List[str]] = dict() | ||
|
||
def run( | ||
self, log_txt: str, cmd: str, check_result: bool, expected_result: int | ||
) -> Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]: | ||
result, output = self.client.exec_run(f"{BluechiIsOnline.binary_name} {cmd}") | ||
if check_result and result != expected_result: | ||
raise Exception( | ||
f"{log_txt} failed with {result} (expected {expected_result}): {output}" | ||
) | ||
return result, output | ||
|
||
def agent_is_online(self) -> bool: | ||
result, output = self.run( | ||
"Checking if agent is active.", | ||
"agent", | ||
False, | ||
0, | ||
) | ||
return result == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
summary: On the agent machine test the connection of the agent to the controller | ||
id: 4af7b1da-39e7-46d5-bf00-586a8df17f1b |
46 changes: 46 additions & 0 deletions
46
tests/tests/tier0/bluechi-is-online-agent/test_bluechi_is_online_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(node: BluechiAgentMachine): | ||
# check that bluechi-agent is online at the test startup | ||
result = node.bluechi_is_online.agent_is_online() | ||
assert result, f"bluechi-agent on node {node.name} should be online" | ||
|
||
# stop bluechi-agent | ||
node.systemctl.stop_unit("bluechi-agent") | ||
assert node.wait_for_unit_state_to_be("bluechi-agent", "inactive") | ||
|
||
# check that bluechi-agent is offline | ||
result = node.bluechi_is_online.agent_is_online() | ||
assert not result, f"bluechi-agent on node {node.name} should be offline" | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): | ||
node_foo = nodes[NODE_FOO] | ||
check_execs(node=node_foo) | ||
|
||
|
||
def test_bluechi_is_online( | ||
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) |