Watch for config changed and gate on mons
Setup observer for config-changed events and get configuring the dashboard on all the mons reporting ready. Change-Id: I6a90d7afde2266e2dfa535d05e022a544914124a
This commit is contained in:
parent
302fed17b0
commit
765c7cfd58
@ -48,6 +48,9 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
|
||||
"""Setup adapters and observers."""
|
||||
super().__init__(*args)
|
||||
super().register_status_check(self.check_dashboard)
|
||||
self.framework.observe(
|
||||
self.on.config_changed,
|
||||
self._configure_dashboard)
|
||||
self.mon = interface_dashboard.CephDashboardRequires(
|
||||
self,
|
||||
'dashboard')
|
||||
@ -112,6 +115,9 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
|
||||
|
||||
def _configure_dashboard(self, _) -> None:
|
||||
"""Configure dashboard"""
|
||||
if not self.mon.mons_ready:
|
||||
logging.info("Not configuring dashboard, mons not ready")
|
||||
return
|
||||
if self.unit.is_leader() and not ceph_utils.is_dashboard_enabled():
|
||||
ceph_utils.mgr_enable_dashboard()
|
||||
ceph_utils.mgr_config_set(
|
||||
|
@ -31,12 +31,23 @@ class CephDashboardRequires(Object):
|
||||
charm.on[relation_name].relation_changed,
|
||||
self.on_changed)
|
||||
|
||||
@property
|
||||
def mons_ready(self) -> bool:
|
||||
"""Check that all mons have reported ready."""
|
||||
ready = False
|
||||
if self.dashboard_relation:
|
||||
# There will only be one unit as this is a subordinate relation.
|
||||
for unit in self.dashboard_relation.units:
|
||||
unit_data = self.dashboard_relation.data[unit]
|
||||
if unit_data.get(self.READY_KEY) == 'True':
|
||||
ready = True
|
||||
return ready
|
||||
|
||||
def on_changed(self, event):
|
||||
"""Emit mon_ready if mons are ready."""
|
||||
logging.debug("CephDashboardRequires on_changed")
|
||||
for u in self.dashboard_relation.units:
|
||||
if self.dashboard_relation.data[u].get(self.READY_KEY) == 'True':
|
||||
logging.debug("Emitting mon ready")
|
||||
self.on.mon_ready.emit()
|
||||
if self.mons_ready:
|
||||
self.on.mon_ready.emit()
|
||||
|
||||
@property
|
||||
def dashboard_relation(self):
|
||||
|
@ -9,7 +9,7 @@ applications:
|
||||
options:
|
||||
osd-devices: '/dev/test-non-existent'
|
||||
ceph-mon:
|
||||
charm: cs:~gnuoy/ceph-mon-26
|
||||
charm: cs:~openstack-charmers-next/ceph-mon
|
||||
num_units: 3
|
||||
options:
|
||||
monitor-count: '3'
|
||||
|
@ -239,9 +239,19 @@ class TestCephDashboardCharmBase(CharmTestCase):
|
||||
self.ceph_utils.mgr_enable_dashboard.assert_called_once_with()
|
||||
|
||||
def test__configure_dashboard(self):
|
||||
self.harness.begin()
|
||||
|
||||
self.ceph_utils.is_dashboard_enabled.return_value = True
|
||||
rel_id = self.harness.add_relation('dashboard', 'ceph-mon')
|
||||
self.harness.begin()
|
||||
self.harness.add_relation_unit(
|
||||
rel_id,
|
||||
'ceph-mon/0')
|
||||
self.harness.update_relation_data(
|
||||
rel_id,
|
||||
'ceph-mon/0',
|
||||
{
|
||||
'mon-ready': 'True'})
|
||||
|
||||
self.ceph_utils.mgr_config_set.reset_mock()
|
||||
self.harness.set_leader(False)
|
||||
self.harness.charm._configure_dashboard(None)
|
||||
self.assertFalse(self.ceph_utils.mgr_enable_dashboard.called)
|
||||
|
@ -96,3 +96,26 @@ class TestCephDashboardRequires(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
self.harness.charm.seen_events,
|
||||
['MonReadyEvent'])
|
||||
self.assertTrue(
|
||||
self.harness.charm.mon.mons_ready)
|
||||
|
||||
def test_on_changed_not_ready_unit(self):
|
||||
self.harness.begin()
|
||||
# No MonReadyEvent as relation is absent
|
||||
self.assertEqual(
|
||||
self.harness.charm.seen_events,
|
||||
[])
|
||||
rel_id = self.add_dashboard_relation()
|
||||
# No MonReadyEvent as ceph-mon has not declared it is ready.
|
||||
self.assertEqual(
|
||||
self.harness.charm.seen_events,
|
||||
[])
|
||||
self.harness.update_relation_data(
|
||||
rel_id,
|
||||
'ceph-mon/0',
|
||||
{})
|
||||
self.assertEqual(
|
||||
self.harness.charm.seen_events,
|
||||
[])
|
||||
self.assertFalse(
|
||||
self.harness.charm.mon.mons_ready)
|
||||
|
Loading…
Reference in New Issue
Block a user