Redfish: Adding the ability to get and set iSCSI initiator
This commits adds new functions 'set_iscsi_initiator_info' and 'get_iscsi_initiator_info' of iLO. Change-Id: I802f7bb8ccf351e8c6be530bd7f743d75f22a0c2
This commit is contained in:
parent
ed291b5ce0
commit
b86754f50a
|
@ -89,6 +89,8 @@ SUPPORTED_REDFISH_METHODS = [
|
|||
'get_essential_properties',
|
||||
'set_iscsi_boot_info',
|
||||
'unset_iscsi_boot_info',
|
||||
'get_iscsi_initiator_info',
|
||||
'set_iscsi_initiator_info',
|
||||
]
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
|
|
@ -953,3 +953,51 @@ class RedfishOperations(operations.IloOperations):
|
|||
else:
|
||||
msg = 'iSCSI boot is not supported in the BIOS boot mode'
|
||||
raise exception.IloCommandNotSupportedInBiosError(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: IloCommandNotSupportedInBiosError, if the system is
|
||||
in the BIOS boot mode.
|
||||
"""
|
||||
sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
|
||||
if(self._is_boot_mode_uefi()):
|
||||
iscsi_data = {'iSCSIInitiatorName': initiator_iqn}
|
||||
try:
|
||||
(sushy_system.bios_settings.iscsi_resource.
|
||||
iscsi_settings.update_iscsi_settings(iscsi_data))
|
||||
except sushy.exceptions.SushyError as e:
|
||||
msg = (self._("The Redfish controller has failed to update "
|
||||
"iSCSI settings. Error %(error)s") %
|
||||
{'error': str(e)})
|
||||
LOG.debug(msg)
|
||||
raise exception.IloError(msg)
|
||||
else:
|
||||
msg = 'iSCSI initiator cannot be updated in BIOS boot mode'
|
||||
raise exception.IloCommandNotSupportedInBiosError(msg)
|
||||
|
||||
def get_iscsi_initiator_info(self):
|
||||
"""Give iSCSI initiator information of iLO.
|
||||
|
||||
:returns: iSCSI initiator information.
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedInBiosError, if the system is
|
||||
in the BIOS boot mode.
|
||||
"""
|
||||
sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
|
||||
if(self._is_boot_mode_uefi()):
|
||||
try:
|
||||
iscsi_initiator = (
|
||||
sushy_system.bios_settings.iscsi_resource.iscsi_initiator)
|
||||
except sushy.exceptions.SushyError as e:
|
||||
msg = (self._('The Redfish controller has failed to get the '
|
||||
'iSCSI initiator. Error %(error)s')
|
||||
% {'error': str(e)})
|
||||
LOG.debug(msg)
|
||||
raise exception.IloError(msg)
|
||||
return iscsi_initiator
|
||||
else:
|
||||
msg = 'iSCSI initiator cannot be retrieved in BIOS boot mode'
|
||||
raise exception.IloCommandNotSupportedInBiosError(msg)
|
||||
|
|
|
@ -23,6 +23,8 @@ class ISCSIResource(base.ResourceBase):
|
|||
This class extends the functionality of base resource class
|
||||
from sushy.
|
||||
"""
|
||||
iscsi_initiator = base.Field("iSCSIInitiatorName")
|
||||
|
||||
_iscsi_settings = None
|
||||
|
||||
def is_iscsi_boot_supported(self):
|
||||
|
|
|
@ -89,6 +89,16 @@ class ISCSIResourceTestCase(testtools.TestCase):
|
|||
self.assertIsInstance(actual_settings,
|
||||
iscsi.ISCSISettings)
|
||||
|
||||
def test_attributes(self):
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi.json', 'r') as f:
|
||||
iscsi_initiator = (
|
||||
json.loads(f.read())['iSCSIInitiatorName'])
|
||||
|
||||
self.assertEqual(
|
||||
iscsi_initiator,
|
||||
self.iscsi_inst.iscsi_initiator)
|
||||
|
||||
|
||||
class ISCSISettingsTestCase(testtools.TestCase):
|
||||
|
||||
|
|
|
@ -1269,3 +1269,138 @@ class RedfishOperationsTestCase(testtools.TestCase):
|
|||
'settings.',
|
||||
self.rf_client._change_iscsi_target_settings,
|
||||
iscsi_variable)
|
||||
|
||||
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
|
||||
def test_set_iscsi_initiator_info(
|
||||
self, get_system_mock, _uefi_boot_mode_mock,
|
||||
update_iscsi_settings_mock):
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/system.json', 'r') as f:
|
||||
system_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/bios.json', 'r') as f:
|
||||
bios_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi.json', 'r') as f:
|
||||
iscsi_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi_settings.json', 'r') as f:
|
||||
iscsi_settings_json = json.loads(f.read())
|
||||
|
||||
self.conn = mock.Mock()
|
||||
self.conn.get.return_value.json.side_effect = [
|
||||
system_json['default'], bios_json['Default'],
|
||||
iscsi_json, iscsi_settings_json['Default']]
|
||||
self.sys_inst = pro_sys.HPESystem(self.conn,
|
||||
'/redfish/v1/Systems/437XR1138R2',
|
||||
redfish_version='1.0.2')
|
||||
get_system_mock.return_value = self.sys_inst
|
||||
_uefi_boot_mode_mock.return_value = True
|
||||
initiator = 'iqn.2015-02.com.hpe:uefi-U31'
|
||||
data = {'iSCSIInitiatorName': initiator}
|
||||
self.rf_client.set_iscsi_initiator_info(initiator)
|
||||
update_iscsi_settings_mock.assert_called_once_with(
|
||||
data)
|
||||
|
||||
@mock.patch.object(iscsi.ISCSISettings, 'update_iscsi_settings')
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
|
||||
def test_set_iscsi_initiator_info_update_failed(
|
||||
self, get_system_mock, _uefi_boot_mode_mock,
|
||||
update_iscsi_settings_mock):
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/system.json', 'r') as f:
|
||||
system_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/bios.json', 'r') as f:
|
||||
bios_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi.json', 'r') as f:
|
||||
iscsi_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi_settings.json', 'r') as f:
|
||||
iscsi_settings_json = json.loads(f.read())
|
||||
|
||||
self.conn = mock.Mock()
|
||||
self.conn.get.return_value.json.side_effect = [
|
||||
system_json['default'], bios_json['Default'],
|
||||
iscsi_json, iscsi_settings_json['Default']]
|
||||
self.sys_inst = pro_sys.HPESystem(self.conn,
|
||||
'/redfish/v1/Systems/437XR1138R2',
|
||||
redfish_version='1.0.2')
|
||||
get_system_mock.return_value = self.sys_inst
|
||||
_uefi_boot_mode_mock.return_value = True
|
||||
initiator = 'iqn.2015-02.com.hpe:uefi-U31'
|
||||
update_iscsi_settings_mock.side_effect = (
|
||||
sushy.exceptions.SushyError)
|
||||
self.assertRaisesRegex(
|
||||
exception.IloError,
|
||||
'The Redfish controller has failed to update iSCSI '
|
||||
'settings.',
|
||||
self.rf_client.set_iscsi_initiator_info,
|
||||
initiator)
|
||||
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
def test_set_iscsi_initiator_info_bios(self, _uefi_boot_mode_mock):
|
||||
_uefi_boot_mode_mock.return_value = False
|
||||
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
|
||||
'iSCSI initiator cannot be updated in '
|
||||
'BIOS boot mode',
|
||||
self.rf_client.set_iscsi_initiator_info,
|
||||
'iqn.2015-02.com.hpe:uefi-U31')
|
||||
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
|
||||
def test_get_iscsi_initiator_info(
|
||||
self, get_system_mock, _uefi_boot_mode_mock):
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/system.json', 'r') as f:
|
||||
system_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/bios.json', 'r') as f:
|
||||
bios_json = json.loads(f.read())
|
||||
with open('proliantutils/tests/redfish/'
|
||||
'json_samples/iscsi.json', 'r') as f:
|
||||
iscsi_json = json.loads(f.read())
|
||||
self.conn = mock.Mock()
|
||||
self.conn.get.return_value.json.side_effect = [
|
||||
system_json['default'], bios_json['Default'],
|
||||
iscsi_json]
|
||||
self.sys_inst = pro_sys.HPESystem(self.conn,
|
||||
'/redfish/v1/Systems/437XR1138R2',
|
||||
redfish_version='1.0.2')
|
||||
get_system_mock.return_value = self.sys_inst
|
||||
_uefi_boot_mode_mock.return_value = True
|
||||
ret = self.rf_client.get_iscsi_initiator_info()
|
||||
self.assertEqual('iqn.2015-02.com.hpe:uefi-U31', ret)
|
||||
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
|
||||
def test_get_iscsi_initiator_info_failed(
|
||||
self, get_system_mock, _uefi_boot_mode_mock):
|
||||
_uefi_boot_mode_mock.return_value = True
|
||||
iscsi_resource_mock = mock.PropertyMock(
|
||||
side_effect=sushy.exceptions.SushyError)
|
||||
type(get_system_mock.return_value.bios_settings).iscsi_resource = (
|
||||
iscsi_resource_mock)
|
||||
self.assertRaisesRegex(
|
||||
exception.IloError,
|
||||
'The Redfish controller has failed to get the '
|
||||
'iSCSI initiator.',
|
||||
self.rf_client.get_iscsi_initiator_info)
|
||||
|
||||
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi',
|
||||
autospec=True)
|
||||
def test_get_iscsi_initiator_info_bios(self, _uefi_boot_mode_mock):
|
||||
_uefi_boot_mode_mock.return_value = False
|
||||
self.assertRaisesRegex(exception.IloCommandNotSupportedInBiosError,
|
||||
'iSCSI initiator cannot be retrieved in '
|
||||
'BIOS boot mode',
|
||||
self.rf_client.get_iscsi_initiator_info)
|
||||
|
|
Loading…
Reference in New Issue