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
This commit is contained in:
Felipe Reyes 2023-09-01 17:41:00 -04:00
parent 21c1ab037e
commit 484b7d8260
5 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1 @@
horizon_hooks.py

View File

@ -0,0 +1 @@
horizon_hooks.py

View File

@ -225,6 +225,7 @@ def config_changed():
websso_trusted_dashboard_changed() websso_trusted_dashboard_changed()
application_dashboard_relation_changed() application_dashboard_relation_changed()
dashboard_relation_changed()
@hooks.hook('identity-service-relation-joined') @hooks.hook('identity-service-relation-joined')
@ -464,6 +465,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(): def main():
try: try:
hooks.execute(sys.argv) hooks.execute(sys.argv)

View File

@ -24,6 +24,8 @@ provides:
scope: container scope: container
websso-trusted-dashboard: websso-trusted-dashboard:
interface: websso-trusted-dashboard interface: websso-trusted-dashboard
dashboard:
interface: dashboard
requires: requires:
identity-service: identity-service:
interface: keystone interface: keystone

View File

@ -252,6 +252,7 @@ class TestHorizonHooks(CharmTestCase):
], ],
'certificates': [], 'certificates': [],
'ha': [], 'ha': [],
'dashboard': [],
}[rname] }[rname]
self.relation_ids.side_effect = relation_ids_side_effect self.relation_ids.side_effect = relation_ids_side_effect
@ -525,3 +526,19 @@ class TestHorizonHooks(CharmTestCase):
"group": "[local] OpenStack" "group": "[local] OpenStack"
}) })
]) ])
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,
)