Protect against empty request health check

This change handles the case where the health check returns None.

Change-Id: I684ced87b41925baa94095a5db926336dbfa7fc2
Closes-Bug: #1779730
This commit is contained in:
David Ames 2018-07-10 13:23:32 -07:00
parent e003088277
commit df11a312a5
2 changed files with 28 additions and 0 deletions

View File

@ -582,7 +582,16 @@ def _assess_status():
health = None
if service_running('vault'):
health = vault.get_vault_health()
else:
status_set('blocked', 'Vault service not running')
return
if health.get('version'):
application_version_set(health.get('version'))
else:
application_version_set('Unknown')
status_set('blocked', 'Vault health check failed')
return
_missing_interfaces = []
_incomplete_interfaces = []

View File

@ -315,6 +315,25 @@ class TestHandlers(unit_tests.test_utils.CharmTestCase):
incomplete_interfaces=mock.ANY),
])
@patch.object(handlers.vault, 'get_vault_health')
def test_assess_status_service_not_running(self, get_vault_health):
self.is_flag_set.return_value = False
self.service_running.return_value = False
handlers._assess_status()
self.status_set.assert_called_with(
'blocked', 'Vault service not running')
@patch.object(handlers.vault, 'get_vault_health')
def test_assess_status_empty_health(self, get_vault_health):
self.is_flag_set.return_value = False
self.service_running.return_value = True
get_vault_health.return_value = {}
handlers._assess_status()
self.application_version_set.assert_called_with(
'Unknown')
self.status_set.assert_called_with(
'blocked', 'Vault health check failed')
def test_assess_status_invalid_channel(self):
statuses = {
'snap.channel.invalid': True,