diff --git a/drivers/sr_health_check.py b/drivers/sr_health_check.py index 204733c79..1146ae35f 100755 --- a/drivers/sr_health_check.py +++ b/drivers/sr_health_check.py @@ -24,6 +24,11 @@ import util import xs_errors +def check_xapi_is_enabled(session, hostref): + host = session.xenapi.host.get_record(hostref) + return host['enabled'] + + def main(): """ For all locally plugged SRs check that they are healthy @@ -36,6 +41,9 @@ def main(): try: localhost = util.get_localhost_ref(session) + if not check_xapi_is_enabled(session, localhost): + # Xapi not enabled, skip and let the next timer trigger this + return sm_types = [x['type'] for x in session.xenapi.SM.get_all_records_where( 'field "required_api_version" = "1.0"').values()] diff --git a/tests/test_sr_health_check.py b/tests/test_sr_health_check.py index c104e962d..47c592123 100644 --- a/tests/test_sr_health_check.py +++ b/tests/test_sr_health_check.py @@ -91,3 +91,15 @@ def test_health_check_run_sr_check(self): # Assert mock_sr.check_sr.assert_called_with(SR_UUID) + + def test_check_xapi_enabled_no(self): + # Arrange + self.mock_session.xenapi.host.get_record.return_value = {'enabled': False} + mock_sr = mock.create_autospec(SR) + self.mock_sr.from_uuid.return_value = mock_sr + + # Act + sr_health_check.main() + + # Assert + mock_sr.check_sr.assert_not_called()