-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a status and disconnected timestamp property to the agent interface
Fixes #543 In order to enable other applications on the managed node to react to connection loss of the agent with the controller, add two new properties: Status and DisconnectTimestamp If the status will change, the agent will emit a property changed signal on which other applications can listen. To provide information for later when the disconnect happened, the timestamp property can be queried. This change also includes extending the D-Bus API description and adding an integration test to it. Signed-off-by: Michael Engel <mengel@redhat.com>
- Loading branch information
Showing
9 changed files
with
274 additions
and
19 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
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
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
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 @@ | ||
summary: Test if the bluechi agent emits a status changed signal when it disconnects from the controller, e.g. when the controller goes down |
20 changes: 20 additions & 0 deletions
20
tests/tests/tier0/monitor-agent-loses-connection/python/is_agent_connected.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,20 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import unittest | ||
|
||
from bluechi.api import Agent | ||
|
||
# Test to verify that the agent on the node is connected to the controller | ||
# and the properties for status and disconnected timestamp are set | ||
|
||
|
||
class TestAgentIsConnected(unittest.TestCase): | ||
|
||
def test_agent_is_connected(self): | ||
agent = Agent() | ||
assert agent.status == "online" | ||
assert agent.disconnect_timestamp == 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
51 changes: 51 additions & 0 deletions
51
tests/tests/tier0/monitor-agent-loses-connection/python/monitor_ctrl_down.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,51 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import unittest | ||
|
||
from dasbus.error import DBusError | ||
from dasbus.loop import EventLoop | ||
from dasbus.typing import Variant | ||
|
||
from bluechi.api import Node, Agent | ||
|
||
|
||
class TestMonitorCtrlDown(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
super().setUp() | ||
|
||
self.agent_state = None | ||
self.agent_disconnected_timestamp = 0 | ||
self.agent_on_node = Agent() | ||
|
||
def test_monitor_ctrl_down(self): | ||
loop = EventLoop() | ||
|
||
def on_state_change(state: Variant): | ||
self.agent_state = state.get_string() | ||
self.agent_disconnected_timestamp = self.agent_on_node.disconnect_timestamp | ||
loop.quit() | ||
|
||
self.agent_on_node.on_status_changed(on_state_change) | ||
|
||
# stop the bluechi controller service to trigger a disconnected message in the agent | ||
# hacky solution to cause a disconnect: | ||
# stop the controller service | ||
# problem: | ||
# dasbus will raise a DBusError for connection timeout on v1.4, v1.7 doesn't | ||
# the command will be executed anyway, resulting in the desired shutdown of the node | ||
# therefore, the DBusError is silenced for now, but all other errors are still raised | ||
try: | ||
node = Node("node-foo") | ||
node.stop_unit('bluechi.service', 'replace') | ||
except DBusError: | ||
pass | ||
|
||
loop.run() | ||
|
||
assert self.agent_state == "offline" | ||
assert self.agent_disconnected_timestamp != 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
51 changes: 51 additions & 0 deletions
51
tests/tests/tier0/monitor-agent-loses-connection/test_monitor_agent_loses_connection.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,51 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import os | ||
from typing import Dict | ||
|
||
from bluechi_test.test import BluechiTest | ||
from bluechi_test.container import BluechiControllerContainer, BluechiNodeContainer | ||
from bluechi_test.config import BluechiControllerConfig, BluechiNodeConfig | ||
|
||
node_foo_name = "node-foo" | ||
|
||
|
||
def start_agent_in_ctrl_container(ctrl: BluechiControllerContainer): | ||
assert ctrl.wait_for_unit_state_to_be("bluechi", "active") | ||
|
||
node_foo_config = BluechiNodeConfig( | ||
file_name="agent.conf", | ||
node_name=node_foo_name, | ||
manager_host="localhost", | ||
manager_port=ctrl.config.port, | ||
) | ||
ctrl.create_file(node_foo_config.get_confd_dir(), node_foo_config.file_name, node_foo_config.serialize()) | ||
result, _ = ctrl.exec_run("systemctl start bluechi-agent") | ||
assert result == 0 | ||
assert ctrl.wait_for_unit_state_to_be("bluechi-agent", "active") | ||
|
||
|
||
def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer]): | ||
start_agent_in_ctrl_container(ctrl) | ||
|
||
# bluechi-agent is running, check if it is connected in Agent | ||
result, output = ctrl.run_python(os.path.join("python", "is_agent_connected.py")) | ||
if result != 0: | ||
raise Exception(output) | ||
|
||
# stop bluechi service and verify that the agent emits a status changed signal | ||
result, output = ctrl.run_python(os.path.join("python", "monitor_ctrl_down.py")) | ||
if result != 0: | ||
raise Exception(output) | ||
|
||
|
||
def test_monitor_agent_loses_connection( | ||
bluechi_test: BluechiTest, | ||
bluechi_ctrl_default_config: BluechiControllerConfig): | ||
|
||
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name] | ||
|
||
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) | ||
# don't add node_foo_config to bluechi_test to prevent it being started | ||
# as separate container | ||
bluechi_test.run(exec) |