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:
|
else:
|
||||||
self.unit.status = _result
|
self.unit.status = _result
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._stored.series_upgrade:
|
if self._stored.series_upgrade:
|
||||||
self.unit.status = BlockedStatus(
|
self.unit.status = BlockedStatus(
|
||||||
'Ready for do-release-upgrade and reboot. '
|
'Ready for do-release-upgrade and reboot. '
|
||||||
'Set complete when finished.')
|
'Set complete when finished.')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._stored.is_paused:
|
if self._stored.is_paused:
|
||||||
self.unit.status = MaintenanceStatus(
|
self.unit.status = MaintenanceStatus(
|
||||||
"Paused. Use 'resume' action to resume normal service.")
|
"Paused. Use 'resume' action to resume normal service.")
|
||||||
return
|
return
|
||||||
|
|
||||||
missing_relations = []
|
missing_relations = []
|
||||||
for relation in self.REQUIRED_RELATIONS:
|
for relation in self.REQUIRED_RELATIONS:
|
||||||
if not self.model.get_relation(relation):
|
if not self.model.get_relation(relation):
|
||||||
|
@ -165,6 +168,13 @@ class OSBaseCharm(CharmBase):
|
||||||
self.unit.status = BlockedStatus(
|
self.unit.status = BlockedStatus(
|
||||||
'Missing relations: {}'.format(', '.join(missing_relations)))
|
'Missing relations: {}'.format(', '.join(missing_relations)))
|
||||||
return
|
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:
|
if self._stored.is_started:
|
||||||
_unique = []
|
_unique = []
|
||||||
# Reverse sort the list so that a shorter message that has the same
|
# 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))
|
self.unit.status = ActiveStatus(', '.join(_unique))
|
||||||
else:
|
else:
|
||||||
self.unit.status = WaitingStatus('Charm configuration in progress')
|
self.unit.status = WaitingStatus('Charm configuration in progress')
|
||||||
|
|
||||||
logging.info("Status updated")
|
logging.info("Status updated")
|
||||||
|
|
||||||
def on_update_status(self, event):
|
def on_update_status(self, event):
|
||||||
|
|
|
@ -108,6 +108,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp(ops_openstack.core, self.PATCHES)
|
super().setUp(ops_openstack.core, self.PATCHES)
|
||||||
self.os_utils.manage_payload_services = MagicMock()
|
self.os_utils.manage_payload_services = MagicMock()
|
||||||
|
self.os_utils.ows_check_services_running = MagicMock()
|
||||||
self.harness = Harness(
|
self.harness = Harness(
|
||||||
OpenStackTestAPICharm,
|
OpenStackTestAPICharm,
|
||||||
meta='''
|
meta='''
|
||||||
|
@ -179,6 +180,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
fatal=True)
|
fatal=True)
|
||||||
|
|
||||||
def test_update_status(self):
|
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.add_relation('shared-db', 'mysql')
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.harness.charm._stored.is_started = True
|
self.harness.charm._stored.is_started = True
|
||||||
|
@ -191,6 +193,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
ActiveStatus)
|
ActiveStatus)
|
||||||
|
|
||||||
def test_update_status_custom_check_fail(self):
|
def test_update_status_custom_check_fail(self):
|
||||||
|
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||||
self.harness.update_config(
|
self.harness.update_config(
|
||||||
key_values={
|
key_values={
|
||||||
'custom-check-fail': 'True'})
|
'custom-check-fail': 'True'})
|
||||||
|
@ -206,6 +209,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
MaintenanceStatus)
|
MaintenanceStatus)
|
||||||
|
|
||||||
def test_update_status_not_started(self):
|
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.add_relation('shared-db', 'mysql')
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.harness.charm.on.update_status.emit()
|
self.harness.charm.on.update_status.emit()
|
||||||
|
@ -217,6 +221,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
WaitingStatus)
|
WaitingStatus)
|
||||||
|
|
||||||
def test_update_status_series_upgrade(self):
|
def test_update_status_series_upgrade(self):
|
||||||
|
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.harness.charm._stored.series_upgrade = True
|
self.harness.charm._stored.series_upgrade = True
|
||||||
self.harness.charm.on_update_status('An Event')
|
self.harness.charm.on_update_status('An Event')
|
||||||
|
@ -229,6 +234,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
BlockedStatus)
|
BlockedStatus)
|
||||||
|
|
||||||
def test_update_status_series_paused(self):
|
def test_update_status_series_paused(self):
|
||||||
|
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.harness.charm._stored.is_paused = True
|
self.harness.charm._stored.is_paused = True
|
||||||
self.harness.charm.on.update_status.emit()
|
self.harness.charm.on.update_status.emit()
|
||||||
|
@ -240,6 +246,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
MaintenanceStatus)
|
MaintenanceStatus)
|
||||||
|
|
||||||
def test_update_status_missing_relation(self):
|
def test_update_status_missing_relation(self):
|
||||||
|
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.harness.charm.on.update_status.emit()
|
self.harness.charm.on.update_status.emit()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -250,6 +257,7 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
BlockedStatus)
|
BlockedStatus)
|
||||||
|
|
||||||
def test_update_status_plugin_check_fail(self):
|
def test_update_status_plugin_check_fail(self):
|
||||||
|
self.os_utils.ows_check_services_running.return_value = (None, None)
|
||||||
self.harness.update_config(
|
self.harness.update_config(
|
||||||
key_values={
|
key_values={
|
||||||
'plugin1-check-fail': 'True',
|
'plugin1-check-fail': 'True',
|
||||||
|
@ -276,6 +284,21 @@ class TestOSBaseCharm(CharmTestCase):
|
||||||
self.harness.charm.unit.status,
|
self.harness.charm.unit.status,
|
||||||
BlockedStatus)
|
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):
|
def test_services(self):
|
||||||
self.harness.begin()
|
self.harness.begin()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue