From c47749889ae6598c5631cf7ecdc91c6cdb57d716 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Fri, 8 Mar 2024 16:46:48 +0100 Subject: [PATCH] added integration test for internal hello method Fixes: https://github.com/eclipse-bluechi/bluechi/issues/798 Adding an integration test that verifies the internal API method 'Hello' works as expected. Signed-off-by: Michael Engel --- .../tier0/bluechi-internal-hello/main.fmf | 2 ++ .../python/call_internal_hello.py | 31 +++++++++++++++++++ .../test_bluechi_internal_hello.py | 28 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/tests/tier0/bluechi-internal-hello/main.fmf create mode 100644 tests/tests/tier0/bluechi-internal-hello/python/call_internal_hello.py create mode 100644 tests/tests/tier0/bluechi-internal-hello/test_bluechi_internal_hello.py diff --git a/tests/tests/tier0/bluechi-internal-hello/main.fmf b/tests/tests/tier0/bluechi-internal-hello/main.fmf new file mode 100644 index 0000000000..433e57b199 --- /dev/null +++ b/tests/tests/tier0/bluechi-internal-hello/main.fmf @@ -0,0 +1,2 @@ +summary: Test internal peer dbus hello method on controller +id: eafc86bc-e69c-47a4-9ca9-907f7a6201fa diff --git a/tests/tests/tier0/bluechi-internal-hello/python/call_internal_hello.py b/tests/tests/tier0/bluechi-internal-hello/python/call_internal_hello.py new file mode 100644 index 0000000000..ba1f2a9aff --- /dev/null +++ b/tests/tests/tier0/bluechi-internal-hello/python/call_internal_hello.py @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +import unittest + +from dasbus.connection import AddressedMessageBus + +node = "node-foo" + + +class TestListenerAddedAsPeer(unittest.TestCase): + + def test_call_internal_hello(self): + + port = "" + with open("/tmp/port", "r") as f: + port = f.read().strip() + assert port is not None + + # connect to controller locally + peer_bus = AddressedMessageBus(f"tcp:host=127.0.0.1,port={port}") + peer_proxy = peer_bus.get_proxy( + service_name="org.eclipse.bluechi", + object_path="/org/freedesktop/DBus", + interface_name="org.freedesktop.DBus" + ) + resp = peer_proxy.Hello() + assert resp == ":1.0" + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/tests/tier0/bluechi-internal-hello/test_bluechi_internal_hello.py b/tests/tests/tier0/bluechi-internal-hello/test_bluechi_internal_hello.py new file mode 100644 index 0000000000..31d4b8d7b2 --- /dev/null +++ b/tests/tests/tier0/bluechi-internal-hello/test_bluechi_internal_hello.py @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +import os + +from typing import Dict +from bluechi_test.test import BluechiTest +from bluechi_test.machine import BluechiControllerMachine, BluechiAgentMachine +from bluechi_test.config import BluechiControllerConfig + +NODE_FOO = "node-foo" + + +def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): + + # pass port information to machine + ctrl.create_file(os.path.join("/", "tmp"), "port", ctrl.config.port) + + result, output = ctrl.run_python(os.path.join("python", "call_internal_hello.py")) + if result != 0: + raise Exception(output) + + +def test_bluechi_internal_hello(bluechi_test: BluechiTest, bluechi_ctrl_default_config: BluechiControllerConfig): + + bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO] + bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) + + bluechi_test.run(exec)