From 539bccb39b8f8d6219cf9b18bddf5b3a80c1afe2 Mon Sep 17 00:00:00 2001 From: Diego Alonso Alvarez Date: Wed, 30 Oct 2024 15:06:11 +0000 Subject: [PATCH 1/5] :wrench: Add ROOT_CONTROLLER_URL to settings. --- drunc_ui/settings/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/drunc_ui/settings/settings.py b/drunc_ui/settings/settings.py index bbe8901..e288bfc 100644 --- a/drunc_ui/settings/settings.py +++ b/drunc_ui/settings/settings.py @@ -147,6 +147,7 @@ DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html" PROCESS_MANAGER_URL = os.getenv("PROCESS_MANAGER_URL", "localhost:10054") +ROOT_CONTROLLER_URL = os.getenv("ROOT_CONTROLLER_URL", "localhost:3333") INSTALLED_APPS += ["crispy_forms", "crispy_bootstrap5"] CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" From f52b54b95db582c63efada81917d5b68223ac94f Mon Sep 17 00:00:00 2001 From: Diego Alonso Alvarez Date: Wed, 30 Oct 2024 15:28:37 +0000 Subject: [PATCH 2/5] :sparkles: Add minimal controller interface. --- controller/controller_interface.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 controller/controller_interface.py diff --git a/controller/controller_interface.py b/controller/controller_interface.py new file mode 100644 index 0000000..b18f14c --- /dev/null +++ b/controller/controller_interface.py @@ -0,0 +1,17 @@ +"""Module providing functions to interact with the drunc controller.""" + +from django.conf import settings +from drunc.controller.controller_driver import ControllerDriver +from drunc.utils.shell_utils import create_dummy_token_from_uname +from druncschema.request_response_pb2 import Description + + +def get_controller_driver() -> ControllerDriver: + """Get a ControllerDriver instance.""" + token = create_dummy_token_from_uname() + return ControllerDriver(settings.ROOT_CONTROLLER_URL, token=token, aio_channel=True) + + +def get_controller_status() -> Description: + """Get the controller status.""" + return get_controller_driver().get_status() From 9b3aedc15030f23f61348fd0a407173b7b2cdb6a Mon Sep 17 00:00:00 2001 From: Diego Alonso Alvarez Date: Wed, 30 Oct 2024 15:29:07 +0000 Subject: [PATCH 3/5] :sparkles: Add testing script. --- scripts/talk_to_controller.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 scripts/talk_to_controller.py diff --git a/scripts/talk_to_controller.py b/scripts/talk_to_controller.py new file mode 100644 index 0000000..48d67b6 --- /dev/null +++ b/scripts/talk_to_controller.py @@ -0,0 +1,21 @@ +"""Example script used to check communication with the controller. + +This is intended to be run within docker from the `app` service, i.e.: + +``` +docker compose exec app python scripts/talk_to_controller.py +``` + +and provides a basic proof of principle of communicating with the controller via +gRPC. +""" + +from drunc.controller.controller_driver import ControllerDriver +from drunc.utils.shell_utils import create_dummy_token_from_uname + +if __name__ == "__main__": + token = create_dummy_token_from_uname() + controller = ControllerDriver("localhost:3333", token=token, aio_channel=True) + + val = controller.get_status() + print(val) From 4b6bc0f5f39d44ba818d7255dc03a3ccca8428d8 Mon Sep 17 00:00:00 2001 From: Diego Alonso Alvarez Date: Wed, 30 Oct 2024 15:33:38 +0000 Subject: [PATCH 4/5] :white_check_mark: Add test_get_controller_status. --- tests/controller/test_controller_interface.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/controller/test_controller_interface.py diff --git a/tests/controller/test_controller_interface.py b/tests/controller/test_controller_interface.py new file mode 100644 index 0000000..8b5d713 --- /dev/null +++ b/tests/controller/test_controller_interface.py @@ -0,0 +1,7 @@ +def test_get_controller_status(mocker): + """Test the _boot_process function.""" + from controller.controller_interface import get_controller_status + + mock = mocker.patch("controller.controller_interface.get_controller_driver") + get_controller_status() + mock.assert_called_once() From 6151985c0ee0278abe342afe9babf4a6a5fc06a1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Alvarez Date: Thu, 31 Oct 2024 11:58:37 +0000 Subject: [PATCH 5/5] :recycle: Use drunc as the URL. --- scripts/talk_to_controller.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/talk_to_controller.py b/scripts/talk_to_controller.py index 48d67b6..a330de3 100644 --- a/scripts/talk_to_controller.py +++ b/scripts/talk_to_controller.py @@ -15,7 +15,6 @@ if __name__ == "__main__": token = create_dummy_token_from_uname() - controller = ControllerDriver("localhost:3333", token=token, aio_channel=True) - + controller = ControllerDriver("drunc:3333", token=token, aio_channel=True) val = controller.get_status() print(val)