Run relation_set() in dashboard_relation_changed() on leader

The commit 484b7d8260 introduced a new relation that relies on an
application databag to exchange data, although only the leader can write
to it, and the original patch didn't guard the relation_set() call with
a is_leader(), this patch addresses that problem wich produces a hook
failure on follower units when openstack-dashboard is deployed in HA.

Closes-Bug: #2046257
Related-Bug: #2030094
Change-Id: I1930b0b96f65cb627f896db67dddc6370cf6a413
(cherry picked from commit 4d5581438a)
This commit is contained in:
Felipe Reyes 2023-12-12 11:06:29 -03:00
parent 4dd78134d8
commit 4b428abc59
2 changed files with 15 additions and 3 deletions

View File

@ -480,8 +480,13 @@ def dashboard_relation_changed():
'vip': config('vip'),
}
for rel_id in relations:
relation_set(rel_id, relation_settings=relation_settings, app=True)
if is_leader():
log("Setting dashboard access information on 'dashboard' relation",
level="INFO")
for rel_id in relations:
relation_set(rel_id, relation_settings=relation_settings, app=True)
else:
log("Skipping relation_set, because not leader.", level="DEBUG")
def main():

View File

@ -527,13 +527,15 @@ class TestHorizonHooks(CharmTestCase):
})
])
def test_dashboard_relation_changed(self):
@patch.object(hooks, 'is_leader')
def test_dashboard_relation_changed(self, is_leader):
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']
is_leader.return_value = True
hooks.dashboard_relation_changed()
self.relation_set.assert_called_with(
@ -542,3 +544,8 @@ class TestHorizonHooks(CharmTestCase):
'vip': '1.2.3.4'},
app=True,
)
self.relation_set.reset_mock()
is_leader.return_value = False
hooks.dashboard_relation_changed()
self.relation_set.assert_not_called()