Redfish: Adding the ability to get persistent boot device

This commits adds new function 'get_persistent_boot_device' to
get persistent boot device for server.

Change-Id: Id8fcec3a821d9ff003ff0f80fd33215c2c08a90d
Depends-on: I85c1376457698bda81120b74f54e08e5236c9974
This commit is contained in:
kesper 2017-07-06 11:37:34 +00:00
parent e17153856b
commit 1ab6b07eb5
7 changed files with 616 additions and 3 deletions

View File

@ -72,6 +72,8 @@ SUPPORTED_REDFISH_METHODS = [
'insert_virtual_media',
'set_vm_status'
'update_firmware',
'set_vm_status',
'get_persistent_boot_device',
]
LOG = log.get_logger(__name__)

View File

@ -46,7 +46,8 @@ DEVICE_COMMON_TO_REDFISH = {
'NETWORK': sushy.BOOT_SOURCE_TARGET_PXE,
'HDD': sushy.BOOT_SOURCE_TARGET_HDD,
'CDROM': sushy.BOOT_SOURCE_TARGET_CD,
'ISCSI': sushy.BOOT_SOURCE_TARGET_UEFI_TARGET
'ISCSI': sushy.BOOT_SOURCE_TARGET_UEFI_TARGET,
'NONE': sushy.BOOT_SOURCE_TARGET_NONE
}
DEVICE_REDFISH_TO_COMMON = {v: k for k, v in DEVICE_COMMON_TO_REDFISH.items()}
@ -58,6 +59,14 @@ BOOT_MODE_MAP = {
BOOT_MODE_MAP_REV = (
utils.revert_dictionary(BOOT_MODE_MAP))
PERSISTENT_BOOT_MAP = {
sushy.BOOT_SOURCE_TARGET_PXE: 'NETWORK',
sushy.BOOT_SOURCE_TARGET_HDD: 'HDD',
sushy.BOOT_SOURCE_TARGET_CD: 'CDROM',
sushy.BOOT_SOURCE_TARGET_UEFI_TARGET: 'NETWORK',
sushy.BOOT_SOURCE_TARGET_NONE: 'NONE'
}
# Assuming only one sushy_system and sushy_manager present as part of
# collection, as we are dealing with iLO's here.
PROLIANT_MANAGER_ID = '1'
@ -445,3 +454,38 @@ class RedfishOperations(operations.IloOperations):
{'file': file_url, 'error': str(e)})
LOG.debug(msg)
raise exception.IloError(msg)
def _is_boot_mode_uefi(self):
"""Checks if the system is in uefi boot mode.
:return: 'True' if the boot mode is uefi else 'False'
"""
boot_mode = self.get_current_boot_mode()
return (boot_mode == BOOT_MODE_MAP.get(sys_cons.BIOS_BOOT_MODE_UEFI))
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.
"""
sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
# Return boot device if it is persistent.
if ((sushy_system.
boot.enabled) == sushy.BOOT_SOURCE_ENABLED_CONTINUOUS):
return PERSISTENT_BOOT_MAP.get(sushy_system.boot.target)
# Check if we are in BIOS boot mode.
# There is no resource to fetch boot device order for BIOS boot mode
if not self._is_boot_mode_uefi():
return None
try:
boot_device = (sushy_system.bios_settings.boot_settings.
get_persistent_boot_device())
return PERSISTENT_BOOT_MAP.get(boot_device)
except sushy.exceptions.SushyError as e:
msg = (self._("The Redfish controller is unable to get "
"persistent boot device.' Error %(error)s") %
{'error': str(e)})
LOG.debug(msg)
raise exception.IloError(msg)

View File

@ -12,17 +12,30 @@
# License for the specific language governing permissions and limitations
# under the License.
import sushy
from sushy.resources import base
from proliantutils import exception
from proliantutils import log
from proliantutils.redfish.resources.system import mappings
from proliantutils.redfish import utils
LOG = log.get_logger(__name__)
BOOT_SOURCE_TARGET_TO_PARTIAL_STRING_MAP = {
sushy.BOOT_SOURCE_TARGET_CD: ('HPE Virtual CD-ROM',),
sushy.BOOT_SOURCE_TARGET_PXE: ('NIC', 'PXE'),
sushy.BOOT_SOURCE_TARGET_UEFI_TARGET: ('ISCSI',),
sushy.BOOT_SOURCE_TARGET_HDD: ('Logical Drive', 'HDD', 'Storage', 'LogVol')
}
class BIOSSettings(base.ResourceBase):
boot_mode = base.MappedField(["Attributes", "BootMode"],
mappings.GET_BIOS_BOOT_MODE_MAP)
_pending_settings = None
_boot_settings = None
@property
def pending_settings(self):
@ -33,14 +46,70 @@ class BIOSSettings(base.ResourceBase):
"""
if self._pending_settings is None:
self._pending_settings = BIOSPendingSettings(
self._conn, utils.get_subresource_path_by(
self._conn,
utils.get_subresource_path_by(
self, ["@Redfish.Settings", "SettingsObject"]),
redfish_version=self.redfish_version)
return self._pending_settings
@property
def boot_settings(self):
"""Property to provide reference to bios boot instance
It is calculated once when the first time it is queried. On refresh,
this property gets reset.
"""
if self._boot_settings is None:
self._boot_settings = BIOSBootSettings(
self._conn,
utils.get_subresource_path_by(
self, ["Oem", "Hpe", "Links", "Boot"]),
redfish_version=self.redfish_version)
return self._boot_settings
class BIOSPendingSettings(base.ResourceBase):
boot_mode = base.MappedField(["Attributes", "BootMode"],
mappings.GET_BIOS_BOOT_MODE_MAP)
class BIOSBootSettings(base.ResourceBase):
boot_sources = base.Field("BootSources", adapter=list)
persistent_boot_config_order = base.Field("PersistentBootConfigOrder",
adapter=list)
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.
"""
boot_string = None
if not self.persistent_boot_config_order or not self.boot_sources:
msg = ('Boot sources or persistent boot config order not found')
LOG.debug(msg)
raise exception.IloError(msg)
preferred_boot_device = self.persistent_boot_config_order[0]
for boot_source in self.boot_sources:
if ((boot_source.get("StructuredBootString") is not None) and (
preferred_boot_device ==
boot_source.get("StructuredBootString"))):
boot_string = boot_source["BootString"]
break
else:
msg = (('Persistent boot device failed, as no matched boot '
'sources found for device: %(persistent_boot_device)s')
% {'persistent_boot_device': preferred_boot_device})
LOG.debug(msg)
raise exception.IloError(msg)
for key, value in BOOT_SOURCE_TARGET_TO_PARTIAL_STRING_MAP.items():
for val in value:
if val in boot_string:
return key
return sushy.BOOT_SOURCE_TARGET_NONE

View File

@ -0,0 +1,292 @@
{
"Default": {
"@Redfish.Settings":
{
"@odata.type": "#Settings.v1_0_0.Settings",
"ETag": "",
"Messages":
[
{
"MessageId": "Base.1.0.Success"
}
],
"SettingsObject":
{
"@odata.id": "/redfish/v1/systems/1/bios/boot/settings/"
},
"Time": ""
},
"@odata.context": "/redfish/v1/$metadata#HpeServerBootSettings.HpeServerBootSettings",
"@odata.etag": "W/\"86E6D5239B54171717C211D20C60F195\"",
"@odata.id": "/redfish/v1/systems/1/bios/boot/",
"@odata.type": "#HpeServerBootSettings.v2_0_0.HpeServerBootSettings",
"BootSources":
[
{
"BootOptionNumber": "0014",
"BootString": "Embedded Storage : HPE Smart Array S100i SR Gen10 - LogVol (Lun:1 VolId:1) 931.48 GiB, RAID 0",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)",
"StructuredBootString": "HD.EmbSWRAID.3.1",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)/Scsi(0x0,0x1)"
},
{
"BootOptionNumber": "0013",
"BootString": "Embedded Storage : HPE Smart Array S100i SR Gen10 - LogVol (Lun:0 VolId:0) 1117.78 GiB, RAID 0",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)",
"StructuredBootString": "HD.EmbSWRAID.1.2",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)/Scsi(0x0,0x0)"
},
{
"BootOptionNumber": "0009",
"BootString": "Generic USB Boot",
"CorrelatableID": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)",
"StructuredBootString": "Generic.USB.1.1",
"UEFIDevicePath": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)"
},
{
"BootOptionNumber": "000D",
"BootString": "Embedded LOM 1 Port 1 : HPE Ethernet 1Gb 4-port 331i Adapter - NIC (PXE IPv4)",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)",
"StructuredBootString": "NIC.LOM.1.1.IPv4",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)/MAC(30E17155B124,0x0)/IPv4(0.0.0.0)"
},
{
"BootOptionNumber": "000E",
"BootString": "Embedded LOM 1 Port 1 : HPE Ethernet 1Gb 4-port 331i Adapter - NIC (PXE IPv6)",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)",
"StructuredBootString": "NIC.LOM.1.1.IPv6",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)/MAC(30E17155B124,0x0)/IPv6(0000:0000:0000:0000:0000:0000:0000:0000)"
},
{
"BootOptionNumber": "000B",
"BootString": "Embedded LOM 1 Port 1 : HPE Ethernet 1Gb 4-port 331i Adapter - NIC (HTTP(S) IPv4)",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)",
"StructuredBootString": "NIC.LOM.1.1.Httpv4",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)/MAC(30E17155B124,0x0)/IPv4(0.0.0.0)/Uri()"
},
{
"BootOptionNumber": "000C",
"BootString": "Embedded LOM 1 Port 1 : HPE Ethernet 1Gb 4-port 331i Adapter - NIC (HTTP(S) IPv6)",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)",
"StructuredBootString": "NIC.LOM.1.1.Httpv6",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x0)/Pci(0x0,0x0)/MAC(30E17155B124,0x0)/IPv6(0000:0000:0000:0000:0000:0000:0000:0000)/Uri()"
},
{
"BootOptionNumber": "000A",
"BootString": "Internal SD Card 1 : Generic USB3.0-CRW",
"CorrelatableID": "PciRoot(0x0)/Pci(0x14,0x0)/USB(0x13,0x0)",
"StructuredBootString": "HD.SD.1.2",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x14,0x0)/USB(0x13,0x0)"
},
{
"BootOptionNumber": "0001",
"BootString": "Embedded UEFI Shell",
"CorrelatableID": "Fv(CDBB7B35-6833-4ED6-9AB2-57D2ACDDF6F0)/FvFile(C57AD6B7-0515-40A8-9D21-551652854E37)",
"StructuredBootString": "Shell.Emb.1.2",
"UEFIDevicePath": "Fv(CDBB7B35-6833-4ED6-9AB2-57D2ACDDF6F0)/FvFile(C57AD6B7-0515-40A8-9D21-551652854E37)"
},
{
"BootOptionNumber": "0011",
"BootString": "iLO Virtual USB 3 : HPE Virtual CD-ROM",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x4)/USB(0x1,0x0)",
"StructuredBootString": "CD.Virtual.3.1",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x4)/USB(0x1,0x0)"
},
{
"BootOptionNumber": "0010",
"BootString": "Red Hat Enterprise Linux",
"CorrelatableID": "HD(1,GPT,6FB3037E-EB9E-4FEC-BE72-8DA4A2D225D9,0x800,0x64000)/\\EFI\\redhat\\shim.efi",
"StructuredBootString": "Unknown.Unknown.200.1",
"UEFIDevicePath": "HD(1,GPT,6FB3037E-EB9E-4FEC-BE72-8DA4A2D225D9,0x800,0x64000)/\\EFI\\redhat\\shim.efi"
},
{
"BootOptionNumber": "0012",
"BootString": "iLO Virtual USB 4 : HPE Virtual USB Key",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x4)/USB(0x2,0x0)",
"StructuredBootString": "FD.Virtual.4.1",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x4)/USB(0x2,0x0)"
}
],
"DefaultBootOrder":
[
"Floppy",
"Cd",
"Usb",
"EmbeddedStorage",
"PcieSlotStorage",
"EmbeddedFlexLOM",
"PcieSlotNic",
"UefiShell"
],
"DesiredBootDevices":
[
{
"CorrelatableID": "",
"Lun": "",
"Wwn": "",
"iScsiTargetName": ""
},
{
"CorrelatableID": "",
"Lun": "",
"Wwn": "",
"iScsiTargetName": ""
},
{
"CorrelatableID": "",
"Lun": "",
"Wwn": "",
"iScsiTargetName": ""
},
{
"CorrelatableID": "",
"Lun": "",
"Wwn": "",
"iScsiTargetName": ""
},
{
"CorrelatableID": "",
"Lun": "",
"Wwn": "",
"iScsiTargetName": ""
}
],
"Id": "boot",
"Name": "Boot Order Current Settings",
"Oem":
{
"Hpe":
{
"@odata.type": "#HpeBiosExt.v2_0_0.HpeBiosExt",
"Links":
{
"BaseConfigs":
{
"@odata.id": "/redfish/v1/systems/1/bios/boot/baseconfigs/"
}
},
"SettingsObject":
{
"UnmodifiedETag": "W/\"CF56F5DDD086DDDDDD700DE91FAC4D22\""
}
}
},
"PersistentBootConfigOrder":
[
"HD.EmbSWRAID.3.1",
"HD.EmbSWRAID.1.2",
"Generic.USB.1.1",
"NIC.LOM.1.1.IPv4",
"NIC.LOM.1.1.IPv6",
"NIC.LOM.1.1.Httpv4",
"NIC.LOM.1.1.Httpv6",
"HD.SD.1.2",
"Shell.Emb.1.2",
"CD.Virtual.3.1",
"Unknown.Unknown.200.1",
"FD.Virtual.4.1"
]
},
"BIOS_boot_without_boot": {
"@Redfish.Settings":
{
"@odata.type": "#Settings.v1_0_0.Settings",
"ETag": "",
"Messages":
[
{
"MessageId": "Base.1.0.Success"
}
],
"SettingsObject":
{
"@odata.id": "/redfish/v1/systems/1/bios/boot/settings/"
},
"Time": ""
},
"@odata.context": "/redfish/v1/$metadata#HpeServerBootSettings.HpeServerBootSettings",
"@odata.etag": "W/\"86E6D5239B54171717C211D20C60F195\"",
"@odata.id": "/redfish/v1/systems/1/bios/boot/",
"@odata.type": "#HpeServerBootSettings.v2_0_0.HpeServerBootSettings",
"BootSources":
[
{
"BootOptionNumber": "0014",
"BootString": "Embedded Storage : HPE Smart Array S100i SR Gen10 - LogVol (Lun:1 VolId:1) 931.48 GiB, RAID 0",
"CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x7)/Scsi(0x0,0x1)"
}
],
"PersistentBootConfigOrder":
[
"HD.EmbSWRAID.3.1"
],
"Id": "boot",
"Name": "Boot Order Current Settings"
},
"BIOS_boot_without_boot_sources": {
"@Redfish.Settings":
{
"@odata.type": "#Settings.v1_0_0.Settings",
"ETag": "",
"Messages":
[
{
"MessageId": "Base.1.0.Success"
}
],
"SettingsObject":
{
"@odata.id": "/redfish/v1/systems/1/bios/boot/settings/"
},
"Time": ""
},
"@odata.context": "/redfish/v1/$metadata#HpeServerBootSettings.HpeServerBootSettings",
"@odata.etag": "W/\"86E6D5239B54171717C211D20C60F195\"",
"@odata.id": "/redfish/v1/systems/1/bios/boot/",
"@odata.type": "#HpeServerBootSettings.v2_0_0.HpeServerBootSettings",
"BootSources": [],
"PersistentBootConfigOrder": [],
"Id": "boot",
"Name": "Boot Order Current Settings"
},
"BIOS_persistent_boot_device_none": {
"@Redfish.Settings":
{
"@odata.type": "#Settings.v1_0_0.Settings",
"ETag": "",
"Messages":
[
{
"MessageId": "Base.1.0.Success"
}
],
"SettingsObject":
{
"@odata.id": "/redfish/v1/systems/1/bios/boot/settings/"
},
"Time": ""
},
"@odata.context": "/redfish/v1/$metadata#HpeServerBootSettings.HpeServerBootSettings",
"@odata.etag": "W/\"86E6D5239B54171717C211D20C60F195\"",
"@odata.id": "/redfish/v1/systems/1/bios/boot/",
"@odata.type": "#HpeServerBootSettings.v2_0_0.HpeServerBootSettings",
"BootSources": [
{
"BootOptionNumber": "0010",
"BootString": "Red Hat Enterprise Linux",
"CorrelatableID": "PciRoot(0x0)/Pci(0x17,0x0)",
"StructuredBootString": "HD.EmbSATA.4.3",
"UEFIDevicePath": "PciRoot(0x0)/Pci(0x17,0x0)/Sata(0x3,0x0,0x0)/HD(1,GPT,4029CE09-5C2D-464D-9C2D-EC6E607F06A1,0x800,0x100000)/\\EFI\\redhat\\shim.efi"
}
],
"PersistentBootConfigOrder": [
"HD.EmbSATA.4.3"
],
"Id": "boot",
"Name": "Boot Order Current Settings"
}
}

View File

@ -287,5 +287,54 @@
"TotalSystemMemoryGiB": 8
}
},
"System_op_for_cdrom_persistent_boot": {
"@odata.context": "/redfish/v1/$metadata#Systems/Members/$entity",
"@odata.etag": "W/\"0E79655D\"",
"@odata.id": "/redfish/v1/Systems/1/",
"@odata.type": "#ComputerSystem.v1_2_0.ComputerSystem",
"Actions": {
"#ComputerSystem.Reset": {
"ResetType@Redfish.AllowableValues": [
"On",
"ForceOff",
"ForceRestart",
"Nmi",
"PushPowerButton"
],
"target": "/redfish/v1/Systems/1/Actions/ComputerSystem.Reset/"
}
},
"HostName": "",
"Id": "1",
"IndicatorLED": "Off",
"Manufacturer": "HPE",
"Name": "Computer System",
"PowerState": "On",
"Boot": {
"BootSourceOverrideEnabled": "Continuous",
"BootSourceOverrideMode": "UEFI",
"BootSourceOverrideTarget": "Cd",
"BootSourceOverrideTarget@Redfish.AllowableValues": [
"None",
"Cd",
"Hdd",
"Usb",
"SDCard",
"Utilities",
"Diags",
"BiosSetup",
"Pxe",
"UefiShell",
"UefiHttp",
"UefiTarget"
],
"UefiTargetBootSourceOverride": "None"
},
"SerialNumber": " ",
"SKU": " ",
"SystemType": "Physical",
"UUID": "00000000-0000-0000-0000-000000000000"
}
}

View File

@ -16,8 +16,10 @@
import json
import mock
import sushy
import testtools
from proliantutils import exception
from proliantutils.redfish.resources.system import bios
from proliantutils.redfish.resources.system import constants as sys_cons
@ -58,6 +60,24 @@ class BIOSSettingsTestCase(testtools.TestCase):
self.bios_inst.pending_settings)
self.conn.get.return_value.json.assert_not_called()
def test_boot_settings(self):
self.assertIsNone(self.bios_inst._boot_settings)
self.conn.get.return_value.json.reset_mock()
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
self.conn.get.return_value.json.return_value = (
json.loads(f.read())['Default'])
actual_settings = self.bios_inst.boot_settings
self.assertIsInstance(actual_settings,
bios.BIOSBootSettings)
self.conn.get.return_value.json.assert_called_once_with()
# reset mock
self.conn.get.return_value.json.reset_mock()
self.assertIs(actual_settings,
self.bios_inst.boot_settings)
self.conn.get.return_value.json.assert_not_called()
class BIOSPendingSettingsTestCase(testtools.TestCase):
@ -76,3 +96,74 @@ class BIOSPendingSettingsTestCase(testtools.TestCase):
def test_attributes(self):
self.assertEqual(sys_cons.BIOS_BOOT_MODE_UEFI,
self.bios_settings_inst.boot_mode)
class BIOSBootSettingsTestCase(testtools.TestCase):
def setUp(self):
super(BIOSBootSettingsTestCase, self).setUp()
self.conn = mock.MagicMock()
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
self.conn.get.return_value.json.return_value = (
json.loads(f.read())['Default'])
self.bios_boot_inst = bios.BIOSBootSettings(
self.conn, '/redfish/v1/Systems/1/bios/boot',
redfish_version='1.0.2')
def test__attributes(self):
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
boot_json = (json.loads(f.read())['Default'])
self.assertEqual(boot_json['BootSources'],
self.bios_boot_inst.boot_sources)
self.assertEqual(boot_json['PersistentBootConfigOrder'],
self.bios_boot_inst.persistent_boot_config_order)
def test_get_persistent_boot_device(self):
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
boot_json = (json.loads(f.read())['Default'])
self.bios_boot_inst.persistent_boot_config_order = (
boot_json['PersistentBootConfigOrder'])
self.bios_boot_inst.boot_sources = boot_json['BootSources']
result = self.bios_boot_inst.get_persistent_boot_device()
self.assertEqual(result, sushy.BOOT_SOURCE_TARGET_HDD)
def test_get_persistent_boot_device_without_boot(self):
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
boot_json = (json.loads(f.read())['BIOS_boot_without_boot'])
self.bios_boot_inst.boot_sources = boot_json['BootSources']
self.bios_boot_inst.persistent_boot_config_order = (
boot_json['PersistentBootConfigOrder'])
self.assertRaisesRegex(
exception.IloError,
'Persistent boot device failed, as no matched boot sources '
'found for device:',
self.bios_boot_inst.get_persistent_boot_device)
def test_get_persistent_boot_device_none(self):
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
boot_json = (
json.loads(f.read())['BIOS_persistent_boot_device_none'])
self.bios_boot_inst.boot_sources = boot_json['BootSources']
self.bios_boot_inst.persistent_boot_config_order = (
boot_json['PersistentBootConfigOrder'])
result = self.bios_boot_inst.get_persistent_boot_device()
self.assertEqual(result, sushy.BOOT_SOURCE_TARGET_NONE)
def test_get_persistent_boot_device_boot_sources_is_none(self):
with open('proliantutils/tests/redfish/'
'json_samples/bios_boot.json', 'r') as f:
boot_json = (
json.loads(f.read())['BIOS_boot_without_boot_sources'])
self.bios_boot_inst.boot_sources = boot_json['BootSources']
self.bios_boot_inst.persistent_boot_config_order = (
boot_json['PersistentBootConfigOrder'])
self.assertRaisesRegex(
exception.IloError,
'Boot sources or persistent boot config order not found',
self.bios_boot_inst.get_persistent_boot_device)

View File

@ -438,3 +438,69 @@ class RedfishOperationsTestCase(testtools.TestCase):
exception.IloError,
'The Redfish controller failed to update firmware',
self.rf_client.update_firmware, 'fw_file_url', 'cpld')
@mock.patch.object(redfish.RedfishOperations, 'get_current_boot_mode')
def test__is_boot_mode_uefi_uefi(self, get_current_boot_mode_mock):
get_current_boot_mode_mock.return_value = (
redfish.BOOT_MODE_MAP.get(sys_cons.BIOS_BOOT_MODE_UEFI))
result = self.rf_client._is_boot_mode_uefi()
self.assertTrue(result)
@mock.patch.object(redfish.RedfishOperations, 'get_current_boot_mode')
def test__is_boot_mode_uefi_bios(self, get_current_boot_mode_mock):
get_current_boot_mode_mock.return_value = (
redfish.BOOT_MODE_MAP.get(sys_cons.BIOS_BOOT_MODE_LEGACY_BIOS))
result = self.rf_client._is_boot_mode_uefi()
self.assertFalse(result)
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_uefi_cdrom(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
(get_sushy_system_mock.return_value.
bios_settings.boot_settings.
get_persistent_boot_device.return_value) = (sushy.
BOOT_SOURCE_TARGET_CD)
_uefi_boot_mode_mock.return_value = True
result = self.rf_client.get_persistent_boot_device()
self.assertEqual(
result,
redfish.DEVICE_REDFISH_TO_COMMON.get(sushy.BOOT_SOURCE_TARGET_CD))
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_bios(self, get_sushy_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = False
result = self.rf_client.get_persistent_boot_device()
self.assertEqual(result, None)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_cdrom_continuous(self,
get_system_mock):
with open('proliantutils/tests/redfish/'
'json_samples/system.json', 'r') as f:
system_json = json.loads(f.read())
self.conn = mock.Mock()
self.conn.get.return_value.json.return_value = system_json[
'System_op_for_cdrom_persistent_boot']
self.sys_inst = system.System(self.conn,
'/redfish/v1/Systems/437XR1138R2',
redfish_version='1.0.2')
get_system_mock.return_value = self.sys_inst
ret = self.rf_client.get_persistent_boot_device()
self.assertEqual(ret, 'CDROM')
@mock.patch.object(redfish.RedfishOperations, '_is_boot_mode_uefi')
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_persistent_boot_device_exp(self, get_system_mock,
_uefi_boot_mode_mock):
_uefi_boot_mode_mock.return_value = True
boot_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value.bios_settings).boot_settings = (
boot_mock)
self.assertRaisesRegex(
exception.IloError,
'The Redfish controller is unable to get persistent boot device.',
self.rf_client.get_persistent_boot_device)