From 3d2d3ea0b6372c29aedce320a649ad2ca712b4c0 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Fri, 1 Sep 2023 17:41:00 -0400 Subject: [PATCH] Add new interface 'dashboard' openstack-dashboard exposes the hostnames (and IP addresses) that can be used by users to load Horizon. There are 3 possible sources, they are juju units ingress-address, os-public-hostname and vip config options Closes-Bug: #2030094 Change-Id: I5eb524c6258f72980ef43175f2bed21d7ca078be (cherry picked from commit 484b7d82601bf4f493df7f564b5b74575819436d) (cherry picked from commit 83ffa9eb3a2418897bf2707d14efce725d775090) --- hooks/dashboard-relation-changed | 1 + hooks/dashboard-relation-joined | 1 + hooks/horizon_hooks.py | 20 ++++++++++++++++++++ metadata.yaml | 2 ++ unit_tests/test_horizon_hooks.py | 17 +++++++++++++++++ 5 files changed, 41 insertions(+) create mode 120000 hooks/dashboard-relation-changed create mode 120000 hooks/dashboard-relation-joined diff --git a/hooks/dashboard-relation-changed b/hooks/dashboard-relation-changed new file mode 120000 index 00000000..3195386e --- /dev/null +++ b/hooks/dashboard-relation-changed @@ -0,0 +1 @@ +horizon_hooks.py \ No newline at end of file diff --git a/hooks/dashboard-relation-joined b/hooks/dashboard-relation-joined new file mode 120000 index 00000000..3195386e --- /dev/null +++ b/hooks/dashboard-relation-joined @@ -0,0 +1 @@ +horizon_hooks.py \ No newline at end of file diff --git a/hooks/horizon_hooks.py b/hooks/horizon_hooks.py index 1bbfaa4b..66ee9a92 100755 --- a/hooks/horizon_hooks.py +++ b/hooks/horizon_hooks.py @@ -224,6 +224,7 @@ def config_changed(): ha_relation_joined(relation_id=relid) websso_trusted_dashboard_changed() + dashboard_relation_changed() @hooks.hook('identity-service-relation-joined') @@ -463,6 +464,25 @@ def websso_trusted_dashboard_changed(): }) +@hooks.hook('dashboard-relation-joined', + 'dashboard-relation-changed') +def dashboard_relation_changed(): + """ + Provide dashboard information. + """ + relations = relation_ids('dashboard') + if not relations: + return + + relation_settings = { + 'os-public-hostname': config('os-public-hostname'), + 'vip': config('vip'), + } + + for rel_id in relations: + relation_set(rel_id, relation_settings=relation_settings, app=True) + + def main(): try: hooks.execute(sys.argv) diff --git a/metadata.yaml b/metadata.yaml index 808f6fef..349ff248 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -23,6 +23,8 @@ provides: scope: container websso-trusted-dashboard: interface: websso-trusted-dashboard + dashboard: + interface: dashboard requires: identity-service: interface: keystone diff --git a/unit_tests/test_horizon_hooks.py b/unit_tests/test_horizon_hooks.py index b579d871..29d55e42 100644 --- a/unit_tests/test_horizon_hooks.py +++ b/unit_tests/test_horizon_hooks.py @@ -230,6 +230,7 @@ class TestHorizonHooks(CharmTestCase): ], 'certificates': [], 'ha': [], + 'dashboard': [], }[rname] self.relation_ids.side_effect = relation_ids_side_effect @@ -457,3 +458,19 @@ class TestHorizonHooks(CharmTestCase): self.register_configs().write_all.assert_called_with() _service_reload.assert_called_with('apache2') self.enable_ssl.assert_called_with() + + def test_dashboard_relation_changed(self): + self.relation_ids.return_value = None + hooks.dashboard_relation_changed() + + self.test_config.set('os-public-hostname', 'mydashboard.local') + self.test_config.set('vip', '1.2.3.4') + self.relation_ids.return_value = ['dashboard:0'] + hooks.dashboard_relation_changed() + + self.relation_set.assert_called_with( + 'dashboard:0', + relation_settings={'os-public-hostname': 'mydashboard.local', + 'vip': '1.2.3.4'}, + app=True, + )