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

Adds minimal controller interface #193

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
17 changes: 17 additions & 0 deletions controller/controller_interface.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions drunc_ui/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions scripts/talk_to_controller.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/controller/test_controller_interface.py
Original file line number Diff line number Diff line change
@@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being pedantic, we probably want to check that the get_status() method was called and not just get_controller_driver