From 48c52fafddef84f54c68cf2a208d9195e0a46dbb Mon Sep 17 00:00:00 2001 From: Samuel Walladge Date: Thu, 13 Jan 2022 07:42:39 +1030 Subject: [PATCH] Display information if missing OSD relation When ceph-mon is blocked on waiting for enough OSDs to be available, it will display a message to that effect. But this is misleading if ceph-mon has not been related to ceph-osd. So if the two are not related, and ceph-mon is waiting for OSDS, then display a message about the relation missing. Closes-Bug: #1886558 Change-Id: Ic5ee9d33d2bb874af7fc7c325773f88c5661fcc6 --- hooks/ceph_hooks.py | 2 ++ unit_tests/test_status.py | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index ea05a470..557903a7 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -1296,6 +1296,8 @@ def assess_status(): expected_osd_count = config('expected-osd-count') or 3 if sufficient_osds(expected_osd_count): status_set('active', 'Unit is ready and clustered') + elif not relation_ids('osd'): + status_set('blocked', 'Missing relation: OSD') else: status_set( 'waiting', diff --git a/unit_tests/test_status.py b/unit_tests/test_status.py index ff181e16..fffe17ff 100644 --- a/unit_tests/test_status.py +++ b/unit_tests/test_status.py @@ -102,6 +102,54 @@ class ServiceStatusTestCase(test_utils.CharmTestCase): self.status_set.assert_called_with('active', mock.ANY) self.application_version_set.assert_called_with('10.2.2') + @mock.patch.object(hooks, 'relation_ids') + @mock.patch.object(hooks, 'get_osd_settings') + @mock.patch.object(hooks, 'has_rbd_mirrors') + @mock.patch.object(hooks, 'sufficient_osds') + @mock.patch.object(hooks, 'get_peer_units') + def test_assess_status_no_osd_relation( + self, + _peer_units, + _sufficient_osds, + _has_rbd_mirrors, + _get_osd_settings, + _relation_ids + ): + _peer_units.return_value = ENOUGH_PEERS_COMPLETE + _sufficient_osds.return_value = False + _relation_ids.return_value = [] + self.ceph.is_bootstrapped.return_value = True + self.ceph.is_quorum.return_value = True + _has_rbd_mirrors.return_value = False + _get_osd_settings.return_value = {} + hooks.assess_status() + self.status_set.assert_called_with('blocked', 'Missing relation: OSD') + self.application_version_set.assert_called_with('10.2.2') + + @mock.patch.object(hooks, 'relation_ids') + @mock.patch.object(hooks, 'get_osd_settings') + @mock.patch.object(hooks, 'has_rbd_mirrors') + @mock.patch.object(hooks, 'sufficient_osds') + @mock.patch.object(hooks, 'get_peer_units') + def test_assess_status_osd_relation_but_insufficient_osds( + self, + _peer_units, + _sufficient_osds, + _has_rbd_mirrors, + _get_osd_settings, + _relation_ids + ): + _peer_units.return_value = ENOUGH_PEERS_COMPLETE + _sufficient_osds.return_value = False + _relation_ids.return_value = ['osd:1'] + self.ceph.is_bootstrapped.return_value = True + self.ceph.is_quorum.return_value = True + _has_rbd_mirrors.return_value = False + _get_osd_settings.return_value = {} + hooks.assess_status() + self.status_set.assert_called_with('waiting', mock.ANY) + self.application_version_set.assert_called_with('10.2.2') + @mock.patch.object(hooks, 'get_osd_settings') @mock.patch.object(hooks, 'has_rbd_mirrors') @mock.patch.object(hooks, 'sufficient_osds')