Skip to content

Commit

Permalink
CA-396655: check xapi is enabled before starting multipath reporting
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 130615c commit 8e5e0ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ def check_devconfig(devconfig, sm_config, config, remove, add, mpath_status=None
else:
update_config(key, i, config[key], remove, add, mpath_status)


def check_xapi_is_enabled(session, hostref):
host = session.xenapi.host.get_record(hostref)
if not host['enabled']:
util.SMlog("Xapi is not enabled, exiting")
mpc_exit(session, 0)


if __name__ == '__main__':
try:
session = util.get_localAPI_session()
Expand All @@ -207,6 +215,7 @@ def check_devconfig(devconfig, sm_config, config, remove, add, mpath_status=None
sys.exit(-1)

localhost = session.xenapi.host.get_by_uuid(get_localhost_uuid())
check_xapi_is_enabled(session, localhost)
# Check whether multipathing is enabled (either for root dev or SRs)
try:
if get_root_dev_major() != get_dm_major():
Expand Down
26 changes: 26 additions & 0 deletions tests/test_mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,29 @@ def test_exit_log_out_error(self, mock_exit):
# Assert
mock_exit.assert_called_once_with(0)
session.xenapi.session.logout.assert_called_once()

@mock.patch('mpathcount.sys.exit', autospec=True)
def test_check_xapi_enabled_yes(self, mock_exit):
# Arrange
session = mock.MagicMock()
session.xenapi.host.get_record.return_value = {'enabled': True}
hostref = mock.MagicMock()

# Act
mpathcount.check_xapi_is_enabled(session, hostref)

# Assert
mock_exit.assert_not_called()

@mock.patch('mpathcount.sys.exit', autospec=True)
def test_check_xapi_enabled_no(self, mock_exit):
# Arrange
session = mock.MagicMock()
session.xenapi.host.get_record.return_value = {'enabled': False}
hostref = mock.MagicMock()

# Act
mpathcount.check_xapi_is_enabled(session, hostref)

# Assert
mock_exit.assert_called_once_with(0)

0 comments on commit 8e5e0ac

Please sign in to comment.