Add support to set iSCSI initiator information

This commit adds support to set iSCSI initiator information
of iLO using RIS.

Change-Id: I0a239727b395b4361447aef3bd8a763c96cf574e
This commit is contained in:
paresh-sao 2017-10-24 08:25:45 +00:00
parent 9d3b681841
commit 579b71710a
5 changed files with 87 additions and 0 deletions

View File

@ -53,6 +53,7 @@ SUPPORTED_RIS_METHODS = [
'set_iscsi_boot_info',
'unset_iscsi_boot_info',
'get_iscsi_initiator_info',
'set_iscsi_initiator_info',
'set_vm_status',
'update_firmware',
'update_persistent_boot',
@ -310,6 +311,16 @@ class IloClient(operations.IloOperations):
"""
return self._call_method('get_iscsi_initiator_info')
def set_iscsi_initiator_info(self, initiator_iqn):
"""Set iSCSI initiator information in iLO.
:param initiator_iqn: Initiator iqn for iLO.
:raises: IloError, on an error from iLO.
:raises: IloCommandNotSupportedInBiosError, if the system is
in the bios boot mode.
"""
return self._call_method('set_iscsi_initiator_info', initiator_iqn)
def get_one_time_boot(self):
"""Retrieves the current setting for the one time boot."""
return self._call_method('get_one_time_boot')

View File

@ -106,6 +106,16 @@ class IloOperations(object):
"""
raise exception.IloCommandNotSupportedError(ERRMSG)
def set_iscsi_initiator_info(self, initiator_iqn):
"""Set iSCSI initiator information in iLO.
:param initiator_iqn: Initiator iqn for iLO.
:raises: IloError, on an error from iLO.
:raises: IloCommandNotSupportedError, if the system is
in the bios boot mode.
"""
raise exception.IloCommandNotSupportedError(ERRMSG)
def get_one_time_boot(self):
"""Retrieves the current setting for the one time boot."""
raise exception.IloCommandNotSupportedError(ERRMSG)

View File

@ -979,6 +979,26 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations):
'does not exist')
raise exception.IloCommandNotSupportedError(msg)
def set_iscsi_initiator_info(self, initiator_iqn):
"""Set iSCSI initiator information in iLO.
:param initiator_iqn: Initiator iqn for iLO.
:raises: IloError, on an error from iLO.
:raises: IloCommandNotSupportedError, if the system is
in the bios boot mode.
"""
if(self._is_boot_mode_uefi() is True):
iscsi_uri = self._check_iscsi_rest_patch_allowed()
initiator_info = {'iSCSIInitiatorName': initiator_iqn}
status, headers, response = self._rest_patch(iscsi_uri,
None, initiator_info)
if status >= 300:
msg = self._get_extended_error(response)
raise exception.IloError(msg)
else:
msg = 'iscsi initiator cannot be set in the BIOS boot mode'
raise exception.IloCommandNotSupportedError(msg)
def get_current_boot_mode(self):
"""Retrieves the current boot mode of the server.

View File

@ -380,6 +380,12 @@ class IloClientTestCase(testtools.TestCase):
self.client.unset_iscsi_boot_info('c456')
call_mock.assert_called_once_with('unset_iscsi_boot_info', 'c456')
@mock.patch.object(client.IloClient, '_call_method')
def test_set_iscsi_initiator_info(self, call_mock):
self.client.set_iscsi_initiator_info('iqn.2011-07.com:example:123')
call_mock.assert_called_once_with('set_iscsi_initiator_info',
'iqn.2011-07.com:example:123')
@mock.patch.object(client.IloClient, '_call_method')
def test_get_product_name(self, call_mock):
self.client.get_product_name()

View File

@ -103,6 +103,46 @@ class IloRisTestCase(testtools.TestCase):
'http://10.10.1.30:8081/startup.nsh')
_uefi_boot_mode_mock.assert_called_once_with()
@mock.patch.object(ris.RISOperations, '_rest_patch')
@mock.patch.object(ris.RISOperations, '_check_iscsi_rest_patch_allowed')
@mock.patch.object(ris.RISOperations, '_is_boot_mode_uefi')
def test_set_iscsi_initiator_info_uefi(self, _uefi_boot_mode_mock,
check_iscsi_mock, patch_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_uri = '/rest/v1/systems/1/bios/iScsi/Settings'
check_iscsi_mock.return_value = iscsi_uri
initiator_iqn = 'iqn.2011-07.com.example.server:test1'
initiator_info = {'iSCSIInitiatorName': initiator_iqn}
patch_mock.return_value = (200, ris_outputs.GET_HEADERS,
ris_outputs.REST_POST_RESPONSE)
self.client.set_iscsi_initiator_info(initiator_iqn)
patch_mock.assert_called_once_with(iscsi_uri, None, initiator_info)
@mock.patch.object(ris.RISOperations, '_rest_patch')
@mock.patch.object(ris.RISOperations, '_check_iscsi_rest_patch_allowed')
@mock.patch.object(ris.RISOperations, '_is_boot_mode_uefi')
def test_set_iscsi_initiator_info_failed(self, _uefi_boot_mode_mock,
check_iscsi_mock, patch_mock):
_uefi_boot_mode_mock.return_value = True
iscsi_uri = '/rest/v1/systems/1/bios/iScsi/Settings'
check_iscsi_mock.return_value = iscsi_uri
initiator_iqn = 'iqn.2011-07.com.example.server:test1'
initiator_info = {'iSCSIInitiatorName': initiator_iqn}
patch_mock.return_value = (302, ris_outputs.GET_HEADERS,
ris_outputs.REST_POST_RESPONSE)
self.assertRaises(exception.IloError,
self.client.set_iscsi_initiator_info,
initiator_iqn)
patch_mock.assert_called_once_with(iscsi_uri, None, initiator_info)
@mock.patch.object(ris.RISOperations, '_is_boot_mode_uefi')
def test_set_iscsi_initiator_info_bios(self, _uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
self.assertRaises(exception.IloCommandNotSupportedError,
self.client.set_iscsi_initiator_info,
'iqn.2011-07.com.example.server:test1')
_uefi_boot_mode_mock.assert_called_once_with()
@mock.patch.object(ris.RISOperations, '_change_iscsi_settings')
@mock.patch.object(ris.RISOperations, '_is_boot_mode_uefi')
def test_set_iscsi_boot_info_uefi(self, _uefi_boot_mode_mock,