Fix status handling for non-leaders
Closes-bug: 2039763 Change-Id: Ic24b5885c1289c2653f4280f7fe2815b1c2afb15
This commit is contained in:
23
src/charm.py
23
src/charm.py
@@ -370,17 +370,32 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _configure_dashboard(self, _event) -> None:
|
def _configure_dashboard(self, event) -> None:
|
||||||
"""Configure dashboard"""
|
"""Configure dashboard"""
|
||||||
if not self.mon.mons_ready:
|
if not self.mon.mons_ready:
|
||||||
logging.info("Not configuring dashboard, mons not ready")
|
logging.info("Not configuring dashboard, mons not ready")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not ceph_utils.is_dashboard_enabled():
|
if ceph_utils.is_dashboard_enabled():
|
||||||
|
if not self.unit.is_leader():
|
||||||
|
# leader already enabled the dashboard and also handles config,
|
||||||
|
# we don't need to do anything except set ourselves as ready
|
||||||
|
logging.debug("Dashboard already enabled, setting ready.")
|
||||||
|
self._stored.is_started = True
|
||||||
|
self.update_status()
|
||||||
|
return
|
||||||
|
else:
|
||||||
if self.unit.is_leader():
|
if self.unit.is_leader():
|
||||||
|
# we're the leader, enable dashboard and continue
|
||||||
|
# configuration below
|
||||||
|
logging.debug("Enabling dashboard as leader.")
|
||||||
ceph_utils.mgr_enable_dashboard()
|
ceph_utils.mgr_enable_dashboard()
|
||||||
else:
|
else:
|
||||||
logging.info("Dashboard not enabled, deferring event.")
|
# non-leader, defer event until leader has enabled and
|
||||||
|
# configured the dashboard
|
||||||
|
logging.info("Dashboard not enabled, deferring event on "
|
||||||
|
"non-leader")
|
||||||
|
event.defer()
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.unit.is_leader():
|
if self.unit.is_leader():
|
||||||
@@ -743,6 +758,7 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._configure_tls_from_charm_config()
|
self._configure_tls_from_charm_config()
|
||||||
|
self.update_status()
|
||||||
|
|
||||||
# Certificates relation handle.
|
# Certificates relation handle.
|
||||||
def _enable_ssl_from_relation(self, event) -> None:
|
def _enable_ssl_from_relation(self, event) -> None:
|
||||||
@@ -763,6 +779,7 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
|
|||||||
return # SSL is already configured.
|
return # SSL is already configured.
|
||||||
|
|
||||||
self._configure_tls_from_relation()
|
self._configure_tls_from_relation()
|
||||||
|
self.update_status()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -356,15 +356,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
|
|||||||
'ceph-mon/0',
|
'ceph-mon/0',
|
||||||
{
|
{
|
||||||
'mon-ready': 'True'})
|
'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)
|
|
||||||
self.ceph_utils.mgr_config_set.assert_called_once_with(
|
|
||||||
'mgr/dashboard/server1/server_addr',
|
|
||||||
'10.0.0.10')
|
|
||||||
|
|
||||||
self.ceph_utils.mgr_config_set.reset_mock()
|
self.ceph_utils.mgr_config_set.reset_mock()
|
||||||
self.ceph_utils.is_dashboard_enabled.return_value = True
|
self.ceph_utils.is_dashboard_enabled.return_value = True
|
||||||
self.harness.set_leader()
|
self.harness.set_leader()
|
||||||
|
|||||||
Reference in New Issue
Block a user