From be89e68454fbaa990c3477c1efebe5a2e37e7035 Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 22 May 2023 14:30:52 +0100 Subject: [PATCH] actions: retrieve dashboard URL Allow sunbeam to retrieve the public ingress URL for the dashboard to avoid the user having to use juju commands to interrogate the model directly. Change-Id: Ia35f66ecfd282c70f329d955413fa26f464a08a2 --- charms/horizon-k8s/actions.yaml | 4 ++-- charms/horizon-k8s/src/charm.py | 11 +++++++++++ charms/horizon-k8s/tests/actions.yaml | 1 + charms/horizon-k8s/tests/unit/test_dashboard_charm.py | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 120000 charms/horizon-k8s/tests/actions.yaml diff --git a/charms/horizon-k8s/actions.yaml b/charms/horizon-k8s/actions.yaml index 88e6195d..6d1a31bb 100644 --- a/charms/horizon-k8s/actions.yaml +++ b/charms/horizon-k8s/actions.yaml @@ -1,2 +1,2 @@ -# NOTE: no actions yet! -{ } +get-dashboard-url: + description: URL for access to the Horizon OpenStack Dashboard. diff --git a/charms/horizon-k8s/src/charm.py b/charms/horizon-k8s/src/charm.py index 92fc9215..78fb388a 100755 --- a/charms/horizon-k8s/src/charm.py +++ b/charms/horizon-k8s/src/charm.py @@ -84,6 +84,17 @@ class OpenstackDashboardOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm): "identity-credentials", } + def __init__(self, framework): + super().__init__(framework) + self.framework.observe( + self.on.get_dashboard_url_action, + self._get_dashboard_url_action, + ) + + def _get_dashboard_url_action(self, event): + """Retrieve the URL for the Horizon OpenStack Dashboard.""" + event.set_results({"url": self.public_url}) + @property def default_public_ingress_port(self): """Default public ingress port.""" diff --git a/charms/horizon-k8s/tests/actions.yaml b/charms/horizon-k8s/tests/actions.yaml new file mode 120000 index 00000000..9adaf92e --- /dev/null +++ b/charms/horizon-k8s/tests/actions.yaml @@ -0,0 +1 @@ +../actions.yaml \ No newline at end of file diff --git a/charms/horizon-k8s/tests/unit/test_dashboard_charm.py b/charms/horizon-k8s/tests/unit/test_dashboard_charm.py index c8016789..9600ee63 100644 --- a/charms/horizon-k8s/tests/unit/test_dashboard_charm.py +++ b/charms/horizon-k8s/tests/unit/test_dashboard_charm.py @@ -110,3 +110,11 @@ class TestDashboardOperatorCharm(test_utils.CharmTestCase): self.check_file( "openstack-dashboard", "/etc/openstack-dashboard/local_settings.py" ) + + def test_get_dashboard_url_action(self): + """Test admin account action.""" + action_event = mock.MagicMock() + self.harness.charm._get_dashboard_url_action(action_event) + action_event.set_results.assert_called_with( + {"url": "http://dashboard.juju:80"} + )