Report non running services in unit status
Depends on https://github.com/juju/charm-helpers/pull/658 Change-Id: I655251eb582ead491c61c4f2672d1e6d25991ba5
This commit is contained in:
parent
eb21629e5f
commit
79c3414d77
|
@ -148,15 +148,18 @@ class OSBaseCharm(CharmBase):
|
|||
else:
|
||||
self.unit.status = _result
|
||||
return
|
||||
|
||||
if self._stored.series_upgrade:
|
||||
self.unit.status = BlockedStatus(
|
||||
'Ready for do-release-upgrade and reboot. '
|
||||
'Set complete when finished.')
|
||||
return
|
||||
|
||||
if self._stored.is_paused:
|
||||
self.unit.status = MaintenanceStatus(
|
||||
"Paused. Use 'resume' action to resume normal service.")
|
||||
return
|
||||
|
||||
missing_relations = []
|
||||
for relation in self.REQUIRED_RELATIONS:
|
||||
if not self.model.get_relation(relation):
|
||||
|
@ -165,6 +168,13 @@ class OSBaseCharm(CharmBase):
|
|||
self.unit.status = BlockedStatus(
|
||||
'Missing relations: {}'.format(', '.join(missing_relations)))
|
||||
return
|
||||
|
||||
_, services_not_running_msg = os_utils.ows_check_services_running(
|
||||
self.services(), ports=[])
|
||||
if services_not_running_msg is not None:
|
||||
self.unit.status = BlockedStatus(services_not_running_msg)
|
||||
return
|
||||
|
||||
if self._stored.is_started:
|
||||
_unique = []
|
||||
# Reverse sort the list so that a shorter message that has the same
|
||||
|
@ -178,6 +188,7 @@ class OSBaseCharm(CharmBase):
|
|||
self.unit.status = ActiveStatus(', '.join(_unique))
|
||||
else:
|
||||
self.unit.status = WaitingStatus('Charm configuration in progress')
|
||||
|
||||
logging.info("Status updated")
|
||||
|
||||
def on_update_status(self, event):
|
||||
|
|
|
@ -108,6 +108,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
def setUp(self):
|
||||
super().setUp(ops_openstack.core, self.PATCHES)
|
||||
self.os_utils.manage_payload_services = MagicMock()
|
||||
self.os_utils.ows_check_services_running = MagicMock()
|
||||
self.harness = Harness(
|
||||
OpenStackTestAPICharm,
|
||||
meta='''
|
||||
|
@ -179,6 +180,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
fatal=True)
|
||||
|
||||
def test_update_status(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.add_relation('shared-db', 'mysql')
|
||||
self.harness.begin()
|
||||
self.harness.charm._stored.is_started = True
|
||||
|
@ -191,6 +193,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
ActiveStatus)
|
||||
|
||||
def test_update_status_custom_check_fail(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.update_config(
|
||||
key_values={
|
||||
'custom-check-fail': 'True'})
|
||||
|
@ -206,6 +209,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
MaintenanceStatus)
|
||||
|
||||
def test_update_status_not_started(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.add_relation('shared-db', 'mysql')
|
||||
self.harness.begin()
|
||||
self.harness.charm.on.update_status.emit()
|
||||
|
@ -217,6 +221,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
WaitingStatus)
|
||||
|
||||
def test_update_status_series_upgrade(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.begin()
|
||||
self.harness.charm._stored.series_upgrade = True
|
||||
self.harness.charm.on_update_status('An Event')
|
||||
|
@ -229,6 +234,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
BlockedStatus)
|
||||
|
||||
def test_update_status_series_paused(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.begin()
|
||||
self.harness.charm._stored.is_paused = True
|
||||
self.harness.charm.on.update_status.emit()
|
||||
|
@ -240,6 +246,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
MaintenanceStatus)
|
||||
|
||||
def test_update_status_missing_relation(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.begin()
|
||||
self.harness.charm.on.update_status.emit()
|
||||
self.assertEqual(
|
||||
|
@ -250,6 +257,7 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
BlockedStatus)
|
||||
|
||||
def test_update_status_plugin_check_fail(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||
self.harness.update_config(
|
||||
key_values={
|
||||
'plugin1-check-fail': 'True',
|
||||
|
@ -276,6 +284,21 @@ class TestOSBaseCharm(CharmTestCase):
|
|||
self.harness.charm.unit.status,
|
||||
BlockedStatus)
|
||||
|
||||
def test_update_status_service_not_running(self):
|
||||
self.os_utils.ows_check_services_running.return_value = (
|
||||
'blocked', 'apache2 is not running')
|
||||
self.harness.add_relation('shared-db', 'mysql')
|
||||
self.harness.begin()
|
||||
self.harness.charm.on.update_status.emit()
|
||||
self.assertEqual(
|
||||
self.harness.charm.unit.status.message,
|
||||
'apache2 is not running')
|
||||
self.assertIsInstance(
|
||||
self.harness.charm.unit.status,
|
||||
BlockedStatus)
|
||||
self.os_utils.ows_check_services_running.assert_called_once_with(
|
||||
['apache2', 'ks-api'], ports=[])
|
||||
|
||||
def test_services(self):
|
||||
self.harness.begin()
|
||||
self.assertEqual(
|
||||
|
|
Loading…
Reference in New Issue