Skip to content

Commit

Permalink
CA-396658: check xapi is enabled before checking SR health
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <mark.syms@cloud.com>
  • Loading branch information
MarkSymsCtx committed Sep 24, 2024
1 parent 8e5e0ac commit 32ba246
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/sr_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sr_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 32ba246

Please sign in to comment.