Add RIS support for updating boot device
Added methods:- get_persistent_boot_device() update_persistent_boot() get_one_time_boot() set_one_time_boot() Removed these methods from IloClient as they are not used by drivers:- get_persistent_boot() set_persistent_boot() Change-Id: I5e9b89e73d560404bc8395d029db8d2fd9fa64d2
This commit is contained in:
@@ -25,7 +25,9 @@ SUPPORTED_RIS_METHODS = [
|
||||
'get_current_boot_mode',
|
||||
'get_host_power_status',
|
||||
'get_http_boot_url',
|
||||
'get_one_time_boot',
|
||||
'get_pending_boot_mode',
|
||||
'get_persistent_boot_device',
|
||||
'get_product_name',
|
||||
'get_secure_boot_mode',
|
||||
'get_vm_status',
|
||||
@@ -34,11 +36,13 @@ SUPPORTED_RIS_METHODS = [
|
||||
'reset_ilo_credential',
|
||||
'reset_secure_boot_keys',
|
||||
'set_http_boot_url',
|
||||
'set_one_time_boot',
|
||||
'set_pending_boot_mode',
|
||||
'set_secure_boot_mode',
|
||||
'get_server_capabilities',
|
||||
'set_iscsi_boot_info',
|
||||
'set_vm_status'
|
||||
'set_vm_status',
|
||||
'update_persistent_boot',
|
||||
]
|
||||
|
||||
|
||||
@@ -184,18 +188,10 @@ class IloClient(operations.IloOperations):
|
||||
"""Sets the boot mode of the system for next boot."""
|
||||
return self._call_method('set_pending_boot_mode', value)
|
||||
|
||||
def get_persistent_boot(self):
|
||||
"""Retrieves the boot order of the host."""
|
||||
return self._call_method('get_persistent_boot')
|
||||
|
||||
def get_persistent_boot_device(self):
|
||||
"""Get the current persistent boot device set for the host."""
|
||||
return self._call_method('get_persistent_boot_device')
|
||||
|
||||
def set_persistent_boot(self, values=[]):
|
||||
"""Configures to boot from a specific device."""
|
||||
return self._call_method('set_persistent_boot', values)
|
||||
|
||||
def update_persistent_boot(self, device_type=[]):
|
||||
"""Updates persistent boot based on the boot mode."""
|
||||
return self._call_method('update_persistent_boot', device_type)
|
||||
|
||||
@@ -39,3 +39,10 @@ def wait_for_ilo_after_reset(ilo_object):
|
||||
else:
|
||||
msg = ('iLO is not up after reset.')
|
||||
raise exception.IloConnectionError(msg)
|
||||
|
||||
|
||||
def isDisk(result):
|
||||
"""Checks if result has a disk related strings."""
|
||||
|
||||
disk_identifier = ["Logical Drive", "HDD", "Storage", "LogVol"]
|
||||
return any(e in result for e in disk_identifier)
|
||||
|
||||
@@ -412,7 +412,7 @@ class RIBCLOperations(operations.IloOperations):
|
||||
'SET_PENDING_BOOT_MODE', 'SERVER_INFO', 'write', dic)
|
||||
return data
|
||||
|
||||
def get_persistent_boot(self):
|
||||
def _get_persistent_boot(self):
|
||||
"""Retrieves the current boot mode settings."""
|
||||
data = self._execute_command(
|
||||
'GET_PERSISTENT_BOOT', 'SERVER_INFO', 'read')
|
||||
@@ -421,7 +421,7 @@ class RIBCLOperations(operations.IloOperations):
|
||||
|
||||
def get_persistent_boot_device(self):
|
||||
"""Get the current persistent boot device set for the host."""
|
||||
result = self.get_persistent_boot()
|
||||
result = self._get_persistent_boot()
|
||||
boot_mode = self._check_boot_mode(result)
|
||||
|
||||
if boot_mode == 'bios':
|
||||
@@ -434,13 +434,13 @@ class RIBCLOperations(operations.IloOperations):
|
||||
elif 'NIC' in value or 'PXE' in value:
|
||||
return 'NETWORK'
|
||||
|
||||
elif self._isDisk(value):
|
||||
elif common.isDisk(value):
|
||||
return 'HDD'
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
def set_persistent_boot(self, values=[]):
|
||||
def _set_persistent_boot(self, values=[]):
|
||||
"""Configures a boot from a specific device."""
|
||||
|
||||
xml = self._create_dynamic_xml(
|
||||
@@ -471,10 +471,10 @@ class RIBCLOperations(operations.IloOperations):
|
||||
raise exception.IloInvalidInputError(
|
||||
"Invalid input. Valid devices: NETWORK, HDD or CDROM.")
|
||||
|
||||
result = self.get_persistent_boot()
|
||||
result = self._get_persistent_boot()
|
||||
boot_mode = self._check_boot_mode(result)
|
||||
if boot_mode == 'bios':
|
||||
self.set_persistent_boot(device_type)
|
||||
self._set_persistent_boot(device_type)
|
||||
return
|
||||
|
||||
device_list = []
|
||||
@@ -497,7 +497,7 @@ class RIBCLOperations(operations.IloOperations):
|
||||
% {'device': device_type[0], 'platform': platform})
|
||||
raise (exception.IloInvalidInputError(msg))
|
||||
|
||||
self.set_persistent_boot(device_list)
|
||||
self._set_persistent_boot(device_list)
|
||||
|
||||
def _check_boot_mode(self, result):
|
||||
|
||||
@@ -528,15 +528,11 @@ class RIBCLOperations(operations.IloOperations):
|
||||
all_nics = pxe_nic_list + nic_list + iscsi_nic_list
|
||||
return all_nics
|
||||
|
||||
def _isDisk(self, result):
|
||||
disk_identifier = ["Logical Drive", "HDD", "Storage", "LogVol"]
|
||||
return any(e in result for e in disk_identifier)
|
||||
|
||||
def _get_disk_boot_devices(self, result):
|
||||
disk_list = []
|
||||
try:
|
||||
for item in result:
|
||||
if self._isDisk(item["DESCRIPTION"]):
|
||||
if common.isDisk(item["DESCRIPTION"]):
|
||||
disk_list.append(item["value"])
|
||||
except KeyError as e:
|
||||
msg = "_get_disk_boot_devices failed with the KeyError:%s"
|
||||
|
||||
@@ -34,6 +34,13 @@ related API's .
|
||||
|
||||
TODO : Add rest of the API's that exists in RIBCL. """
|
||||
|
||||
DEVICE_COMMON_TO_RIS = {'NETWORK': 'Pxe',
|
||||
'CDROM': 'Cd',
|
||||
'HDD': 'Hdd',
|
||||
}
|
||||
DEVICE_RIS_TO_COMMON = dict(
|
||||
(v, k) for (k, v) in DEVICE_COMMON_TO_RIS.items())
|
||||
|
||||
|
||||
class RISOperations(operations.IloOperations):
|
||||
|
||||
@@ -1140,3 +1147,168 @@ class RISOperations(operations.IloOperations):
|
||||
if status >= 300:
|
||||
msg = self._get_extended_error(response)
|
||||
raise exception.IloError(msg)
|
||||
|
||||
def _get_persistent_boot_devices(self):
|
||||
"""Get details of persistent boot devices, its order
|
||||
|
||||
:returns: List of dictionary of boot sources and
|
||||
list of boot device order
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
# Check if the BIOS resource if exists.
|
||||
headers_bios, bios_uri, bios_settings = self._check_bios_resource()
|
||||
|
||||
# Get the Boot resource.
|
||||
boot_settings = self._get_bios_boot_resource(bios_settings)
|
||||
|
||||
# Get the BootSources resource
|
||||
try:
|
||||
boot_sources = boot_settings['BootSources']
|
||||
except KeyError:
|
||||
msg = ("BootSources resource not found.")
|
||||
raise exception.IloError(msg)
|
||||
|
||||
try:
|
||||
boot_order = boot_settings['PersistentBootConfigOrder']
|
||||
except KeyError:
|
||||
msg = ("PersistentBootConfigOrder resource not found.")
|
||||
raise exception.IloCommandNotSupportedError(msg)
|
||||
|
||||
return boot_sources, boot_order
|
||||
|
||||
def get_persistent_boot_device(self):
|
||||
"""Get current persistent boot device set for the host
|
||||
|
||||
:returns: persistent boot device for the system
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
system = self._get_host_details()
|
||||
try:
|
||||
# Return boot device if it is persistent.
|
||||
if system['Boot']['BootSourceOverrideEnabled'] == 'Continuous':
|
||||
device = system['Boot']['BootSourceOverrideTarget']
|
||||
if device in DEVICE_RIS_TO_COMMON:
|
||||
return DEVICE_RIS_TO_COMMON[device]
|
||||
return device
|
||||
except KeyError as e:
|
||||
msg = "get_persistent_boot_device failed with the KeyError:%s"
|
||||
raise exception.IloError((msg) % e)
|
||||
|
||||
# Check if we are in BIOS boot mode.
|
||||
# There is no resource to fetch boot device order for BIOS boot mode
|
||||
if not self._validate_uefi_boot_mode():
|
||||
return None
|
||||
|
||||
# Get persistent boot device order for UEFI
|
||||
boot_sources, boot_devices = self._get_persistent_boot_devices()
|
||||
|
||||
boot_string = ""
|
||||
try:
|
||||
for source in boot_sources:
|
||||
if (source["StructuredBootString"] == boot_devices[0]):
|
||||
boot_string = source["BootString"]
|
||||
break
|
||||
except KeyError as e:
|
||||
msg = "get_persistent_boot_device failed with the KeyError:%s"
|
||||
raise exception.IloError((msg) % e)
|
||||
|
||||
if 'HP iLO Virtual USB CD' in boot_string:
|
||||
return 'CDROM'
|
||||
|
||||
elif ('NIC' in boot_string or
|
||||
'PXE' in boot_string or
|
||||
"iSCSI" in boot_string):
|
||||
return 'NETWORK'
|
||||
|
||||
elif common.isDisk(boot_string):
|
||||
return 'HDD'
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
def _update_persistent_boot(self, device_type=[], persistent=False):
|
||||
"""Changes the persistent boot device order in BIOS boot mode for host
|
||||
|
||||
Note: It uses first boot device from the device_type and ignores rest.
|
||||
|
||||
:param device_type: ordered list of boot devices
|
||||
:param persistent: Boolean flag to indicate if the device to be set as
|
||||
a persistent boot device
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
tenure = 'Once'
|
||||
new_device = device_type[0]
|
||||
|
||||
# If it is a standard device, we need to convert in RIS convention
|
||||
if device_type[0].upper() in DEVICE_COMMON_TO_RIS:
|
||||
new_device = DEVICE_COMMON_TO_RIS[device_type[0].upper()]
|
||||
|
||||
if persistent:
|
||||
tenure = 'Continuous'
|
||||
|
||||
new_boot_settings = {}
|
||||
new_boot_settings['Boot'] = {'BootSourceOverrideEnabled': tenure,
|
||||
'BootSourceOverrideTarget': new_device}
|
||||
systems_uri = "/rest/v1/Systems/1"
|
||||
|
||||
status, headers, response = self._rest_patch(systems_uri, None,
|
||||
new_boot_settings)
|
||||
if status >= 300:
|
||||
msg = self._get_extended_error(response)
|
||||
raise exception.IloError(msg)
|
||||
|
||||
def update_persistent_boot(self, device_type=[]):
|
||||
"""Changes the persistent boot device order for the host
|
||||
|
||||
:param device_type: ordered list of boot devices
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
# Check if the input is valid
|
||||
for item in device_type:
|
||||
if item.upper() not in DEVICE_COMMON_TO_RIS:
|
||||
raise exception.IloInvalidInputError(
|
||||
"Invalid input. Valid devices: NETWORK, HDD or CDROM.")
|
||||
|
||||
self._update_persistent_boot(device_type, persistent=True)
|
||||
|
||||
def set_one_time_boot(self, device):
|
||||
"""Configures a single boot from a specific device.
|
||||
|
||||
:param device: Device to be set as a one time boot device
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
self._update_persistent_boot([device], persistent=False)
|
||||
|
||||
def get_one_time_boot(self):
|
||||
"""Retrieves the current setting for the one time boot.
|
||||
|
||||
:returns: Returns the first boot device that would be used in next
|
||||
boot. Returns 'Normal' is no device is set.
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
system = self._get_host_details()
|
||||
try:
|
||||
if system['Boot']['BootSourceOverrideEnabled'] == 'Once':
|
||||
device = system['Boot']['BootSourceOverrideTarget']
|
||||
if device in DEVICE_RIS_TO_COMMON:
|
||||
return DEVICE_RIS_TO_COMMON[device]
|
||||
return device
|
||||
else:
|
||||
# value returned by RIBCL if one-time boot setting are absent
|
||||
return 'Normal'
|
||||
|
||||
except KeyError as e:
|
||||
msg = "get_one_time_boot failed with the KeyError:%s"
|
||||
raise exception.IloError((msg) % e)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -179,11 +179,6 @@ class IloClientTestCase(testtools.TestCase):
|
||||
self.client.set_pending_boot_mode('UEFI')
|
||||
call_mock.assert_called_once_with('set_pending_boot_mode', 'UEFI')
|
||||
|
||||
@mock.patch.object(client.IloClient, '_call_method')
|
||||
def test_get_persistent_boot(self, call_mock):
|
||||
self.client.get_persistent_boot()
|
||||
call_mock.assert_called_once_with('get_persistent_boot')
|
||||
|
||||
@mock.patch.object(client.IloClient, '_call_method')
|
||||
def test_get_persistent_boot_device(self, call_mock):
|
||||
self.client.get_persistent_boot_device()
|
||||
@@ -427,3 +422,51 @@ class IloClientTestCase(testtools.TestCase):
|
||||
device='FLOPPY')
|
||||
insert_virtual_media_mock.assert_called_once_with("http://ilo/fpy.iso",
|
||||
"FLOPPY")
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'get_one_time_boot')
|
||||
def test_get_one_time_boot_gen9(self, get_one_time_boot_mock):
|
||||
self.client.model = 'Gen9'
|
||||
self.client.get_one_time_boot()
|
||||
get_one_time_boot_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'get_one_time_boot')
|
||||
def test_get_one_time_boot_gen8(self, get_one_time_boot_mock):
|
||||
self.client.model = 'Gen8'
|
||||
self.client.get_one_time_boot()
|
||||
get_one_time_boot_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'set_one_time_boot')
|
||||
def test_set_one_time_boot_gen9(self, set_one_time_boot_mock):
|
||||
self.client.model = 'Gen9'
|
||||
self.client.set_one_time_boot('cdrom')
|
||||
set_one_time_boot_mock.assert_called_once_with('cdrom')
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'set_one_time_boot')
|
||||
def test_set_one_time_boot_gen8(self, set_one_time_boot_mock):
|
||||
self.client.model = 'Gen8'
|
||||
self.client.set_one_time_boot('cdrom')
|
||||
set_one_time_boot_mock.assert_called_once_with('cdrom')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'update_persistent_boot')
|
||||
def test_update_persistent_boot_gen9(self, update_persistent_boot_mock):
|
||||
self.client.model = 'Gen9'
|
||||
self.client.update_persistent_boot(['cdrom'])
|
||||
update_persistent_boot_mock.assert_called_once_with(['cdrom'])
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'update_persistent_boot')
|
||||
def test_update_persistent_boot_gen8(self, update_persistent_boot_mock):
|
||||
self.client.model = 'Gen8'
|
||||
self.client.update_persistent_boot(['cdrom'])
|
||||
update_persistent_boot_mock.assert_called_once_with(['cdrom'])
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'get_persistent_boot_device')
|
||||
def test_get_persistent_boot_device_gen9(self, get_pers_boot_device_mock):
|
||||
self.client.model = 'Gen9'
|
||||
self.client.get_persistent_boot_device()
|
||||
get_pers_boot_device_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'get_persistent_boot_device')
|
||||
def test_get_persistent_boot_device_gen8(self, get_pers_boot_device_mock):
|
||||
self.client.model = 'Gen8'
|
||||
self.client.get_persistent_boot_device()
|
||||
get_pers_boot_device_mock.assert_called_once_with()
|
||||
|
||||
@@ -318,7 +318,7 @@ class IloRibclTestCase(unittest.TestCase):
|
||||
self.assertEqual(result, 'CDROM')
|
||||
self.assertTrue(request_ilo_mock.called)
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_request_ilo')
|
||||
def test_update_persistent_boot_uefi_cdrom(self,
|
||||
request_ilo_mock,
|
||||
@@ -329,7 +329,7 @@ class IloRibclTestCase(unittest.TestCase):
|
||||
self.assertTrue(request_ilo_mock.called)
|
||||
set_persist_boot_mock.assert_called_once_with(['Boot000B'])
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_request_ilo')
|
||||
def test_update_persistent_boot_uefi_hdd(self,
|
||||
request_ilo_mock,
|
||||
@@ -340,7 +340,7 @@ class IloRibclTestCase(unittest.TestCase):
|
||||
self.assertTrue(request_ilo_mock.called)
|
||||
set_persist_boot_mock.assert_called_once_with(['Boot0007'])
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_request_ilo')
|
||||
def test_update_persistent_boot_uefi_nic(self,
|
||||
request_ilo_mock,
|
||||
@@ -367,7 +367,7 @@ class IloRibclTestCase(unittest.TestCase):
|
||||
self.assertRaises(exception.IloInvalidInputError,
|
||||
self.ilo.update_persistent_boot, ['Other'])
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, 'set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_set_persistent_boot')
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_request_ilo')
|
||||
def test_update_persistent_boot_bios(self,
|
||||
request_ilo_mock,
|
||||
|
||||
@@ -602,6 +602,165 @@ class IloRisTestCase(testtools.TestCase):
|
||||
get_vm_device_mock.assert_called_once_with('CDROM')
|
||||
patch_mock.assert_called_once_with(vm_uri, None, vm_patch)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_one_time_boot_not_set(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP)
|
||||
get_host_details_mock.return_value = system_data
|
||||
ret = self.client.get_one_time_boot()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, 'Normal')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_one_time_boot_cdrom(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.RESP_BODY_FOR_SYSTEM_WITH_CDROM)
|
||||
get_host_details_mock.return_value = system_data
|
||||
ret = self.client.get_one_time_boot()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, 'CDROM')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_one_time_boot_UefiShell(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.RESP_BODY_WITH_UEFI_SHELL)
|
||||
get_host_details_mock.return_value = system_data
|
||||
ret = self.client.get_one_time_boot()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, 'UefiShell')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_one_time_boot_exc(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.RESP_BODY_FOR_SYSTEM_WITHOUT_BOOT)
|
||||
get_host_details_mock.return_value = system_data
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client.get_one_time_boot)
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_update_persistent_boot')
|
||||
def test_set_one_time_boot_cdrom(self, update_persistent_boot_mock):
|
||||
self.client.set_one_time_boot('cdrom')
|
||||
update_persistent_boot_mock.assert_called_once_with(['cdrom'],
|
||||
persistent=False)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_cdrom(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.SYSTEM_WITH_CDROM_CONT)
|
||||
get_host_details_mock.return_value = system_data
|
||||
ret = self.client.get_persistent_boot_device()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, 'CDROM')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_UefiShell(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.SYSTEM_WITH_UEFISHELL_CONT)
|
||||
get_host_details_mock.return_value = system_data
|
||||
ret = self.client.get_persistent_boot_device()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, 'UefiShell')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_exc(self, get_host_details_mock):
|
||||
system_data = json.loads(ris_outputs.RESP_BODY_FOR_SYSTEM_WITHOUT_BOOT)
|
||||
get_host_details_mock.return_value = system_data
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client.get_persistent_boot_device)
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_bios(self, get_host_details_mock,
|
||||
validate_uefi_boot_mode_mock):
|
||||
system_data = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP)
|
||||
get_host_details_mock.return_value = system_data
|
||||
validate_uefi_boot_mode_mock.return_value = False
|
||||
ret = self.client.get_persistent_boot_device()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, None)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_persistent_boot_devices')
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def _test_get_persistent_boot_device_uefi(self, get_host_details_mock,
|
||||
validate_uefi_boot_mode_mock,
|
||||
boot_devices_mock,
|
||||
boot_devices,
|
||||
boot_sources,
|
||||
exp_ret_value=None):
|
||||
system_data = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP)
|
||||
get_host_details_mock.return_value = system_data
|
||||
validate_uefi_boot_mode_mock.return_value = True
|
||||
boot_devices_mock.return_value = boot_sources, boot_devices
|
||||
|
||||
ret = self.client.get_persistent_boot_device()
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
validate_uefi_boot_mode_mock.assert_called_once_with()
|
||||
boot_devices_mock.assert_called_once_with()
|
||||
self.assertEqual(ret, exp_ret_value)
|
||||
|
||||
def test_get_persistent_boot_device_uefi_pxe(self):
|
||||
boot_devs = ris_outputs.UEFI_BOOT_DEVICE_ORDER_PXE
|
||||
boot_srcs = json.loads(ris_outputs.UEFI_BootSources)
|
||||
|
||||
self._test_get_persistent_boot_device_uefi(boot_devices=boot_devs,
|
||||
boot_sources=boot_srcs,
|
||||
exp_ret_value='NETWORK')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_uefi_cd(self, get_host_details_mock,
|
||||
validate_uefi_boot_mode_mock):
|
||||
boot_devs = ris_outputs.UEFI_BOOT_DEVICE_ORDER_CD
|
||||
boot_srcs = json.loads(ris_outputs.UEFI_BootSources)
|
||||
|
||||
self._test_get_persistent_boot_device_uefi(boot_devices=boot_devs,
|
||||
boot_sources=boot_srcs,
|
||||
exp_ret_value='CDROM')
|
||||
|
||||
def test_get_persistent_boot_device_uefi_hdd(self):
|
||||
boot_devs = ris_outputs.UEFI_BOOT_DEVICE_ORDER_HDD
|
||||
boot_srcs = json.loads(ris_outputs.UEFI_BootSources)
|
||||
|
||||
self._test_get_persistent_boot_device_uefi(boot_devices=boot_devs,
|
||||
boot_sources=boot_srcs,
|
||||
exp_ret_value='HDD')
|
||||
|
||||
def test_get_persistent_boot_device_uefi_none(self):
|
||||
boot_devs = ris_outputs.UEFI_BOOT_DEVICE_ORDER_ERR
|
||||
boot_srcs = json.loads(ris_outputs.UEFI_BootSources)
|
||||
|
||||
self._test_get_persistent_boot_device_uefi(boot_devices=boot_devs,
|
||||
boot_sources=boot_srcs,
|
||||
exp_ret_value=None)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_persistent_boot_devices')
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
@mock.patch.object(ris.RISOperations, '_get_host_details')
|
||||
def test_get_persistent_boot_device_uefi_exp(self, get_host_details_mock,
|
||||
validate_uefi_boot_mode_mock,
|
||||
boot_devices_mock):
|
||||
system_data = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP)
|
||||
get_host_details_mock.return_value = system_data
|
||||
validate_uefi_boot_mode_mock.return_value = True
|
||||
devices = ris_outputs.UEFI_BOOT_DEVICE_ORDER_HDD
|
||||
sources = json.loads(ris_outputs.UEFI_BOOT_SOURCES_ERR)
|
||||
boot_devices_mock.return_value = sources, devices
|
||||
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client.get_persistent_boot_device)
|
||||
get_host_details_mock.assert_called_once_with()
|
||||
validate_uefi_boot_mode_mock.assert_called_once_with()
|
||||
boot_devices_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_update_persistent_boot')
|
||||
def test_update_persistent_boot_cdrom(self, update_persistent_boot_mock):
|
||||
self.client.update_persistent_boot(['cdrom'])
|
||||
update_persistent_boot_mock.assert_called_once_with(['cdrom'],
|
||||
persistent=True)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_update_persistent_boot')
|
||||
def test_update_persistent_boot_exc(self, update_persistent_boot_mock):
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client.update_persistent_boot, ['fake'])
|
||||
self.assertFalse(update_persistent_boot_mock.called)
|
||||
|
||||
|
||||
class TestRISOperationsPrivateMethods(testtools.TestCase):
|
||||
|
||||
@@ -1199,3 +1358,102 @@ class TestRISOperationsPrivateMethods(testtools.TestCase):
|
||||
ilo_details_mock.assert_called_once_with()
|
||||
collection_mock.assert_called_once_with(vmedia_uri)
|
||||
get_mock.assert_called_once_with(member_uri)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
def test__update_persistent_boot_once(self, rest_patch_mock):
|
||||
systems_uri = "/rest/v1/Systems/1"
|
||||
new_boot_settings = {}
|
||||
new_boot_settings['Boot'] = {'BootSourceOverrideEnabled': 'Once',
|
||||
'BootSourceOverrideTarget': 'Cd'}
|
||||
rest_patch_mock.return_value = (200, ris_outputs.GET_HEADERS,
|
||||
ris_outputs.REST_POST_RESPONSE)
|
||||
self.client._update_persistent_boot(['cdrom'], persistent=False)
|
||||
rest_patch_mock.assert_called_once_with(systems_uri, None,
|
||||
new_boot_settings)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
def test__update_persistent_boot_for_continuous(self, rest_patch_mock):
|
||||
systems_uri = "/rest/v1/Systems/1"
|
||||
new_boot_settings = {}
|
||||
new_boot_settings['Boot'] = {'BootSourceOverrideEnabled': 'Continuous',
|
||||
'BootSourceOverrideTarget': 'Cd'}
|
||||
rest_patch_mock.return_value = (200, ris_outputs.GET_HEADERS,
|
||||
ris_outputs.REST_POST_RESPONSE)
|
||||
self.client._update_persistent_boot(['cdrom'], persistent=True)
|
||||
rest_patch_mock.assert_called_once_with(systems_uri, None,
|
||||
new_boot_settings)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
def test__update_persistent_boot_for_UefiShell(self, rest_patch_mock):
|
||||
systems_uri = "/rest/v1/Systems/1"
|
||||
new_boot_settings = {}
|
||||
new_boot_settings['Boot'] = {'BootSourceOverrideEnabled': 'Continuous',
|
||||
'BootSourceOverrideTarget': 'UefiShell'}
|
||||
rest_patch_mock.return_value = (200, ris_outputs.GET_HEADERS,
|
||||
ris_outputs.REST_POST_RESPONSE)
|
||||
self.client._update_persistent_boot(['UefiShell'], persistent=True)
|
||||
rest_patch_mock.assert_called_once_with(systems_uri, None,
|
||||
new_boot_settings)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_rest_patch')
|
||||
def test__update_persistent_boot_fail(self, rest_patch_mock):
|
||||
systems_uri = "/rest/v1/Systems/1"
|
||||
new_boot_settings = {}
|
||||
new_boot_settings['Boot'] = {'BootSourceOverrideEnabled': 'Continuous',
|
||||
'BootSourceOverrideTarget': 'FakeDevice'}
|
||||
rest_patch_mock.return_value = (301, ris_outputs.GET_HEADERS,
|
||||
ris_outputs.REST_POST_RESPONSE)
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client._update_persistent_boot,
|
||||
['FakeDevice'], persistent=True)
|
||||
rest_patch_mock.assert_called_once_with(systems_uri, None,
|
||||
new_boot_settings)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_bios_boot_resource')
|
||||
@mock.patch.object(ris.RISOperations, '_check_bios_resource')
|
||||
def test__get_persistent_boot_devices_no_boot_order(self,
|
||||
check_bios_mock,
|
||||
boot_mock):
|
||||
bios_uri = '/rest/v1/systems/1/bios'
|
||||
bios_settings = json.loads(ris_outputs.GET_BIOS_SETTINGS)
|
||||
check_bios_mock.return_value = (ris_outputs.GET_HEADERS,
|
||||
bios_uri, bios_settings)
|
||||
boot_settings = json.loads(ris_outputs.BOOT_PERS_DEV_ORDER_MISSING)
|
||||
boot_mock.return_value = boot_settings
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client._get_persistent_boot_devices)
|
||||
check_bios_mock.assert_called_once_with()
|
||||
boot_mock.assert_called_once_with(bios_settings)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_bios_boot_resource')
|
||||
@mock.patch.object(ris.RISOperations, '_check_bios_resource')
|
||||
def test__get_persistent_boot_devices(self, check_bios_mock, boot_mock):
|
||||
bios_uri = '/rest/v1/systems/1/bios'
|
||||
bios_settings = json.loads(ris_outputs.GET_BIOS_SETTINGS)
|
||||
check_bios_mock.return_value = (ris_outputs.GET_HEADERS,
|
||||
bios_uri, bios_settings)
|
||||
boot_settings = json.loads(ris_outputs.GET_BIOS_BOOT)
|
||||
boot_mock.return_value = boot_settings
|
||||
exp_boot_src = json.loads(ris_outputs.UEFI_BootSources)
|
||||
exp_boot_order = ris_outputs.UEFI_PERS_BOOT_DEVICES
|
||||
boot_src, boot_order = self.client._get_persistent_boot_devices()
|
||||
check_bios_mock.assert_called_once_with()
|
||||
boot_mock.assert_called_once_with(bios_settings)
|
||||
self.assertEqual(boot_src, exp_boot_src)
|
||||
self.assertEqual(boot_order, exp_boot_order)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_bios_boot_resource')
|
||||
@mock.patch.object(ris.RISOperations, '_check_bios_resource')
|
||||
def test__get_persistent_boot_devices_no_bootsources(self,
|
||||
check_bios_mock,
|
||||
boot_mock):
|
||||
bios_uri = '/rest/v1/systems/1/bios'
|
||||
bios_settings = json.loads(ris_outputs.GET_BIOS_SETTINGS)
|
||||
check_bios_mock.return_value = (ris_outputs.GET_HEADERS,
|
||||
bios_uri, bios_settings)
|
||||
boot_settings = json.loads(ris_outputs.UEFI_BOOTSOURCES_MISSING)
|
||||
boot_mock.return_value = boot_settings
|
||||
self.assertRaises(exception.IloError,
|
||||
self.client._get_persistent_boot_devices)
|
||||
check_bios_mock.assert_called_once_with()
|
||||
boot_mock.assert_called_once_with(bios_settings)
|
||||
|
||||
Reference in New Issue
Block a user