From 19be723a662a930bf067eb6fb6755629f147b017 Mon Sep 17 00:00:00 2001 From: Shivanand Tendulker Date: Mon, 13 Jul 2015 23:11:54 -0700 Subject: [PATCH] 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 --- proliantutils/ilo/client.py | 14 +- proliantutils/ilo/common.py | 7 + proliantutils/ilo/ribcl.py | 20 +- proliantutils/ilo/ris.py | 172 +++ proliantutils/tests/ilo/ris_sample_outputs.py | 1290 +++++++++++++++++ proliantutils/tests/ilo/test_client.py | 53 +- proliantutils/tests/ilo/test_ribcl.py | 8 +- proliantutils/tests/ilo/test_ris.py | 258 ++++ 8 files changed, 1792 insertions(+), 30 deletions(-) diff --git a/proliantutils/ilo/client.py b/proliantutils/ilo/client.py index 4b5ed18..e641f4b 100644 --- a/proliantutils/ilo/client.py +++ b/proliantutils/ilo/client.py @@ -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) diff --git a/proliantutils/ilo/common.py b/proliantutils/ilo/common.py index f2bae79..648d9e8 100644 --- a/proliantutils/ilo/common.py +++ b/proliantutils/ilo/common.py @@ -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) diff --git a/proliantutils/ilo/ribcl.py b/proliantutils/ilo/ribcl.py index 989169f..3bfa8e1 100644 --- a/proliantutils/ilo/ribcl.py +++ b/proliantutils/ilo/ribcl.py @@ -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" diff --git a/proliantutils/ilo/ris.py b/proliantutils/ilo/ris.py index 3be4e54..e5d7857 100755 --- a/proliantutils/ilo/ris.py +++ b/proliantutils/ilo/ris.py @@ -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) diff --git a/proliantutils/tests/ilo/ris_sample_outputs.py b/proliantutils/tests/ilo/ris_sample_outputs.py index 9d9afb2..3a83170 100755 --- a/proliantutils/tests/ilo/ris_sample_outputs.py +++ b/proliantutils/tests/ilo/ris_sample_outputs.py @@ -1780,3 +1780,1293 @@ RESP_VM_STATUS_CDROM_MISSING = """ "Name": "VirtualMedia" } """ + +RESP_BODY_FOR_SYSTEM_WITH_CDROM = """ +{ + "AssetTag": "", + "AvailableActions": [ + { + "Action": "Reset", + "Capabilities": [ + { + "AllowableValues": [ + "On", + "ForceOff", + "ForceRestart", + "Nmi", + "PushPowerButton" + ], + "PropertyName": "ResetType" + } + ] + } + ], + "Bios": { + "Current": { + "VersionString": "I36 v1.40 (01/28/2015)" + } + }, + "Boot": { + "BootSourceOverrideEnabled": "Once", + "BootSourceOverrideSupported": [ + "None", + "Cd", + "Hdd", + "Usb", + "Utilities", + "Diags", + "BiosSetup", + "Pxe", + "UefiShell", + "UefiTarget" + ], + "BootSourceOverrideTarget": "Cd", + "UefiTargetBootSourceOverride": "None", + "UefiTargetBootSourceOverrideSupported": [ + "HD.Emb.1.2", + "Generic.USB.1.1", + "NIC.FlexLOM.1.1.IPv4", + "NIC.FlexLOM.1.1.IPv6", + "CD.Virtual.2.1" + ] + }, + "Description": "Computer System View", + "HostCorrelation": { + "HostMACAddress": [ + "6c:c2:17:39:fe:80", + "6c:c2:17:39:fe:88" + ], + "HostName": "", + "IPAddress": [ + "", + "" + ] + }, + "IndicatorLED": "Off", + "Manufacturer": "HP", + "Memory": { + "TotalSystemMemoryGB": 16 + }, + "Model": "ProLiant BL460c Gen9", + "Name": "Computer System", + "Oem": { + "Hp": { + "AvailableActions": [ + { + "Action": "PowerButton", + "Capabilities": [ + { + "AllowableValues": [ + "Press", + "PressAndHold" + ], + "PropertyName": "PushType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + }, + { + "Action": "SystemReset", + "Capabilities": [ + { + "AllowableValues": [ + "ColdBoot" + ], + "PropertyName": "ResetType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + } + ], + "Battery": [], + "Bios": { + "Backup": { + "Date": "v1.40 (01/28/2015)", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "Current": { + "Date": "01/28/2015", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "UefiClass": 2 + }, + "DeviceDiscoveryComplete": { + "AMSDeviceDiscovery": "NoAMS", + "SmartArrayDiscovery": "Initial", + "vAuxDeviceDiscovery": "DataIncomplete", + "vMainDeviceDiscovery": "ServerOff" + }, + "PostState": "PowerOff", + "PowerAllocationLimit": 500, + "PowerAutoOn": "PowerOn", + "PowerOnDelay": "Minimum", + "PowerRegulatorMode": "Dynamic", + "PowerRegulatorModesSupported": [ + "OSControl", + "Dynamic", + "Max", + "Min" + ], + "ServerSignature": 0, + "Type": "HpComputerSystemExt.0.10.1", + "VirtualProfile": "Inactive", + "VirtualUUID": null, + "links": { + "BIOS": { + "href": "/rest/v1/systems/1/bios" + }, + "MEMORY": { + "href": "/rest/v1/Systems/1/Memory" + }, + "PCIDevices": { + "href": "/rest/v1/Systems/1/PCIDevices" + }, + "PCISlots": { + "href": "/rest/v1/Systems/1/PCISlots" + }, + "SecureBoot": { + "href": "/rest/v1/Systems/1/SecureBoot" + } + } + } + }, + "Power": "Off", + "Processors": { + "Count": 1, + "ProcessorFamily": "Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz", + "Status": { + "HealthRollUp": "OK" + } + }, + "SKU": "727021-B21", + "SerialNumber": "SGH449WNL3", + "Status": { + "Health": "OK", + "State": "Disabled" + }, + "SystemType": "Physical", + "Type": "ComputerSystem.0.9.6", + "UUID": "30373237-3132-4753-4834-3439574E4C33", + "links": { + "Chassis": [ + { + "href": "/rest/v1/Chassis/1" + } + ], + "Logs": { + "href": "/rest/v1/Systems/1/Logs" + }, + "ManagedBy": [ + { + "href": "/rest/v1/Managers/1" + } + ], + "self": { + "href": "/rest/v1/Systems/1" + } + } +} +""" + +RESP_BODY_WITH_UEFI_SHELL = """ +{ + "AssetTag": "", + "AvailableActions": [ + { + "Action": "Reset", + "Capabilities": [ + { + "AllowableValues": [ + "On", + "ForceOff", + "ForceRestart", + "Nmi", + "PushPowerButton" + ], + "PropertyName": "ResetType" + } + ] + } + ], + "Bios": { + "Current": { + "VersionString": "I36 v1.40 (01/28/2015)" + } + }, + "Boot": { + "BootSourceOverrideEnabled": "Once", + "BootSourceOverrideSupported": [ + "None", + "Cd", + "Hdd", + "Usb", + "Utilities", + "Diags", + "BiosSetup", + "Pxe", + "UefiShell", + "UefiTarget" + ], + "BootSourceOverrideTarget": "UefiShell", + "UefiTargetBootSourceOverride": "None", + "UefiTargetBootSourceOverrideSupported": [ + "HD.Emb.1.2", + "Generic.USB.1.1", + "NIC.FlexLOM.1.1.IPv4", + "NIC.FlexLOM.1.1.IPv6", + "CD.Virtual.2.1" + ] + }, + "Description": "Computer System View", + "HostCorrelation": { + "HostMACAddress": [ + "6c:c2:17:39:fe:80", + "6c:c2:17:39:fe:88" + ], + "HostName": "", + "IPAddress": [ + "", + "" + ] + }, + "IndicatorLED": "Off", + "Manufacturer": "HP", + "Memory": { + "TotalSystemMemoryGB": 16 + }, + "Model": "ProLiant BL460c Gen9", + "Name": "Computer System", + "Oem": { + "Hp": { + "AvailableActions": [ + { + "Action": "PowerButton", + "Capabilities": [ + { + "AllowableValues": [ + "Press", + "PressAndHold" + ], + "PropertyName": "PushType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + }, + { + "Action": "SystemReset", + "Capabilities": [ + { + "AllowableValues": [ + "ColdBoot" + ], + "PropertyName": "ResetType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + } + ], + "Battery": [], + "Bios": { + "Backup": { + "Date": "v1.40 (01/28/2015)", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "Current": { + "Date": "01/28/2015", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "UefiClass": 2 + }, + "DeviceDiscoveryComplete": { + "AMSDeviceDiscovery": "NoAMS", + "SmartArrayDiscovery": "Initial", + "vAuxDeviceDiscovery": "DataIncomplete", + "vMainDeviceDiscovery": "ServerOff" + }, + "PostState": "PowerOff", + "PowerAllocationLimit": 500, + "PowerAutoOn": "PowerOn", + "PowerOnDelay": "Minimum", + "PowerRegulatorMode": "Dynamic", + "PowerRegulatorModesSupported": [ + "OSControl", + "Dynamic", + "Max", + "Min" + ], + "ServerSignature": 0, + "Type": "HpComputerSystemExt.0.10.1", + "VirtualProfile": "Inactive", + "VirtualUUID": null, + "links": { + "BIOS": { + "href": "/rest/v1/systems/1/bios" + }, + "MEMORY": { + "href": "/rest/v1/Systems/1/Memory" + }, + "PCIDevices": { + "href": "/rest/v1/Systems/1/PCIDevices" + }, + "PCISlots": { + "href": "/rest/v1/Systems/1/PCISlots" + }, + "SecureBoot": { + "href": "/rest/v1/Systems/1/SecureBoot" + } + } + } + }, + "Power": "Off", + "Processors": { + "Count": 1, + "ProcessorFamily": "Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz", + "Status": { + "HealthRollUp": "OK" + } + }, + "SKU": "727021-B21", + "SerialNumber": "SGH449WNL3", + "Status": { + "Health": "OK", + "State": "Disabled" + }, + "SystemType": "Physical", + "Type": "ComputerSystem.0.9.6", + "UUID": "30373237-3132-4753-4834-3439574E4C33", + "links": { + "Chassis": [ + { + "href": "/rest/v1/Chassis/1" + } + ], + "Logs": { + "href": "/rest/v1/Systems/1/Logs" + }, + "ManagedBy": [ + { + "href": "/rest/v1/Managers/1" + } + ], + "self": { + "href": "/rest/v1/Systems/1" + } + } +} +""" + + +RESP_BODY_FOR_SYSTEM_WITHOUT_BOOT = """ +{ + "AssetTag": "", + "AvailableActions": [ + { + "Action": "Reset", + "Capabilities": [ + { + "AllowableValues": [ + "On", + "ForceOff", + "ForceRestart", + "Nmi", + "PushPowerButton" + ], + "PropertyName": "ResetType" + } + ] + } + ], + "Bios": { + "Current": { + "VersionString": "I36 v1.40 (01/28/2015)" + } + }, + "Description": "Computer System View", + "HostCorrelation": { + "HostMACAddress": [ + "6c:c2:17:39:fe:80", + "6c:c2:17:39:fe:88" + ], + "HostName": "", + "IPAddress": [ + "", + "" + ] + }, + "IndicatorLED": "Off", + "Manufacturer": "HP", + "Memory": { + "TotalSystemMemoryGB": 16 + }, + "Model": "ProLiant BL460c Gen9", + "Name": "Computer System", + "Oem": { + "Hp": { + "AvailableActions": [ + { + "Action": "PowerButton", + "Capabilities": [ + { + "AllowableValues": [ + "Press", + "PressAndHold" + ], + "PropertyName": "PushType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + }, + { + "Action": "SystemReset", + "Capabilities": [ + { + "AllowableValues": [ + "ColdBoot" + ], + "PropertyName": "ResetType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + } + ], + "Battery": [], + "Bios": { + "Backup": { + "Date": "v1.40 (01/28/2015)", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "Current": { + "Date": "01/28/2015", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "UefiClass": 2 + }, + "DeviceDiscoveryComplete": { + "AMSDeviceDiscovery": "NoAMS", + "SmartArrayDiscovery": "Initial", + "vAuxDeviceDiscovery": "DataIncomplete", + "vMainDeviceDiscovery": "ServerOff" + }, + "PostState": "PowerOff", + "PowerAllocationLimit": 500, + "PowerAutoOn": "PowerOn", + "PowerOnDelay": "Minimum", + "PowerRegulatorMode": "Dynamic", + "PowerRegulatorModesSupported": [ + "OSControl", + "Dynamic", + "Max", + "Min" + ], + "ServerSignature": 0, + "Type": "HpComputerSystemExt.0.10.1", + "VirtualProfile": "Inactive", + "VirtualUUID": null, + "links": { + "BIOS": { + "href": "/rest/v1/systems/1/bios" + }, + "MEMORY": { + "href": "/rest/v1/Systems/1/Memory" + }, + "PCIDevices": { + "href": "/rest/v1/Systems/1/PCIDevices" + }, + "PCISlots": { + "href": "/rest/v1/Systems/1/PCISlots" + }, + "SecureBoot": { + "href": "/rest/v1/Systems/1/SecureBoot" + } + } + } + }, + "Power": "Off", + "Processors": { + "Count": 1, + "ProcessorFamily": "Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz", + "Status": { + "HealthRollUp": "OK" + } + }, + "SKU": "727021-B21", + "SerialNumber": "SGH449WNL3", + "Status": { + "Health": "OK", + "State": "Disabled" + }, + "SystemType": "Physical", + "Type": "ComputerSystem.0.9.6", + "UUID": "30373237-3132-4753-4834-3439574E4C33", + "links": { + "Chassis": [ + { + "href": "/rest/v1/Chassis/1" + } + ], + "Logs": { + "href": "/rest/v1/Systems/1/Logs" + }, + "ManagedBy": [ + { + "href": "/rest/v1/Managers/1" + } + ], + "self": { + "href": "/rest/v1/Systems/1" + } + } +} +""" + +SYSTEM_WITH_CDROM_CONT = """ +{ + "AssetTag": "", + "AvailableActions": [ + { + "Action": "Reset", + "Capabilities": [ + { + "AllowableValues": [ + "On", + "ForceOff", + "ForceRestart", + "Nmi", + "PushPowerButton" + ], + "PropertyName": "ResetType" + } + ] + } + ], + "Bios": { + "Current": { + "VersionString": "I36 v1.40 (01/28/2015)" + } + }, + "Boot": { + "BootSourceOverrideEnabled": "Continuous", + "BootSourceOverrideSupported": [ + "None", + "Cd", + "Hdd", + "Usb", + "Utilities", + "Diags", + "BiosSetup", + "Pxe", + "UefiShell", + "UefiTarget" + ], + "BootSourceOverrideTarget": "Cd", + "UefiTargetBootSourceOverride": "None", + "UefiTargetBootSourceOverrideSupported": [ + "HD.Emb.1.2", + "Generic.USB.1.1", + "NIC.FlexLOM.1.1.IPv4", + "NIC.FlexLOM.1.1.IPv6", + "CD.Virtual.2.1" + ] + }, + "Description": "Computer System View", + "HostCorrelation": { + "HostMACAddress": [ + "6c:c2:17:39:fe:80", + "6c:c2:17:39:fe:88" + ], + "HostName": "", + "IPAddress": [ + "", + "" + ] + }, + "IndicatorLED": "Off", + "Manufacturer": "HP", + "Memory": { + "TotalSystemMemoryGB": 16 + }, + "Model": "ProLiant BL460c Gen9", + "Name": "Computer System", + "Oem": { + "Hp": { + "AvailableActions": [ + { + "Action": "PowerButton", + "Capabilities": [ + { + "AllowableValues": [ + "Press", + "PressAndHold" + ], + "PropertyName": "PushType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + }, + { + "Action": "SystemReset", + "Capabilities": [ + { + "AllowableValues": [ + "ColdBoot" + ], + "PropertyName": "ResetType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + } + ], + "Battery": [], + "Bios": { + "Backup": { + "Date": "v1.40 (01/28/2015)", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "Current": { + "Date": "01/28/2015", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "UefiClass": 2 + }, + "DeviceDiscoveryComplete": { + "AMSDeviceDiscovery": "NoAMS", + "SmartArrayDiscovery": "Initial", + "vAuxDeviceDiscovery": "DataIncomplete", + "vMainDeviceDiscovery": "ServerOff" + }, + "PostState": "PowerOff", + "PowerAllocationLimit": 500, + "PowerAutoOn": "PowerOn", + "PowerOnDelay": "Minimum", + "PowerRegulatorMode": "Dynamic", + "PowerRegulatorModesSupported": [ + "OSControl", + "Dynamic", + "Max", + "Min" + ], + "ServerSignature": 0, + "Type": "HpComputerSystemExt.0.10.1", + "VirtualProfile": "Inactive", + "VirtualUUID": null, + "links": { + "BIOS": { + "href": "/rest/v1/systems/1/bios" + }, + "MEMORY": { + "href": "/rest/v1/Systems/1/Memory" + }, + "PCIDevices": { + "href": "/rest/v1/Systems/1/PCIDevices" + }, + "PCISlots": { + "href": "/rest/v1/Systems/1/PCISlots" + }, + "SecureBoot": { + "href": "/rest/v1/Systems/1/SecureBoot" + } + } + } + }, + "Power": "Off", + "Processors": { + "Count": 1, + "ProcessorFamily": "Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz", + "Status": { + "HealthRollUp": "OK" + } + }, + "SKU": "727021-B21", + "SerialNumber": "SGH449WNL3", + "Status": { + "Health": "OK", + "State": "Disabled" + }, + "SystemType": "Physical", + "Type": "ComputerSystem.0.9.6", + "UUID": "30373237-3132-4753-4834-3439574E4C33", + "links": { + "Chassis": [ + { + "href": "/rest/v1/Chassis/1" + } + ], + "Logs": { + "href": "/rest/v1/Systems/1/Logs" + }, + "ManagedBy": [ + { + "href": "/rest/v1/Managers/1" + } + ], + "self": { + "href": "/rest/v1/Systems/1" + } + } +} +""" + +SYSTEM_WITH_UEFISHELL_CONT = """ +{ + "AssetTag": "", + "AvailableActions": [ + { + "Action": "Reset", + "Capabilities": [ + { + "AllowableValues": [ + "On", + "ForceOff", + "ForceRestart", + "Nmi", + "PushPowerButton" + ], + "PropertyName": "ResetType" + } + ] + } + ], + "Bios": { + "Current": { + "VersionString": "I36 v1.40 (01/28/2015)" + } + }, + "Boot": { + "BootSourceOverrideEnabled": "Continuous", + "BootSourceOverrideSupported": [ + "None", + "Cd", + "Hdd", + "Usb", + "Utilities", + "Diags", + "BiosSetup", + "Pxe", + "UefiShell", + "UefiTarget" + ], + "BootSourceOverrideTarget": "UefiShell", + "UefiTargetBootSourceOverride": "None", + "UefiTargetBootSourceOverrideSupported": [ + "HD.Emb.1.2", + "Generic.USB.1.1", + "NIC.FlexLOM.1.1.IPv4", + "NIC.FlexLOM.1.1.IPv6", + "CD.Virtual.2.1" + ] + }, + "Description": "Computer System View", + "HostCorrelation": { + "HostMACAddress": [ + "6c:c2:17:39:fe:80", + "6c:c2:17:39:fe:88" + ], + "HostName": "", + "IPAddress": [ + "", + "" + ] + }, + "IndicatorLED": "Off", + "Manufacturer": "HP", + "Memory": { + "TotalSystemMemoryGB": 16 + }, + "Model": "ProLiant BL460c Gen9", + "Name": "Computer System", + "Oem": { + "Hp": { + "AvailableActions": [ + { + "Action": "PowerButton", + "Capabilities": [ + { + "AllowableValues": [ + "Press", + "PressAndHold" + ], + "PropertyName": "PushType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + }, + { + "Action": "SystemReset", + "Capabilities": [ + { + "AllowableValues": [ + "ColdBoot" + ], + "PropertyName": "ResetType" + }, + { + "AllowableValues": [ + "/Oem/Hp" + ], + "PropertyName": "Target" + } + ] + } + ], + "Battery": [], + "Bios": { + "Backup": { + "Date": "v1.40 (01/28/2015)", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "Current": { + "Date": "01/28/2015", + "Family": "I36", + "VersionString": "I36 v1.40 (01/28/2015)" + }, + "UefiClass": 2 + }, + "DeviceDiscoveryComplete": { + "AMSDeviceDiscovery": "NoAMS", + "SmartArrayDiscovery": "Initial", + "vAuxDeviceDiscovery": "DataIncomplete", + "vMainDeviceDiscovery": "ServerOff" + }, + "PostState": "PowerOff", + "PowerAllocationLimit": 500, + "PowerAutoOn": "PowerOn", + "PowerOnDelay": "Minimum", + "PowerRegulatorMode": "Dynamic", + "PowerRegulatorModesSupported": [ + "OSControl", + "Dynamic", + "Max", + "Min" + ], + "ServerSignature": 0, + "Type": "HpComputerSystemExt.0.10.1", + "VirtualProfile": "Inactive", + "VirtualUUID": null, + "links": { + "BIOS": { + "href": "/rest/v1/systems/1/bios" + }, + "MEMORY": { + "href": "/rest/v1/Systems/1/Memory" + }, + "PCIDevices": { + "href": "/rest/v1/Systems/1/PCIDevices" + }, + "PCISlots": { + "href": "/rest/v1/Systems/1/PCISlots" + }, + "SecureBoot": { + "href": "/rest/v1/Systems/1/SecureBoot" + } + } + } + }, + "Power": "Off", + "Processors": { + "Count": 1, + "ProcessorFamily": "Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz", + "Status": { + "HealthRollUp": "OK" + } + }, + "SKU": "727021-B21", + "SerialNumber": "SGH449WNL3", + "Status": { + "Health": "OK", + "State": "Disabled" + }, + "SystemType": "Physical", + "Type": "ComputerSystem.0.9.6", + "UUID": "30373237-3132-4753-4834-3439574E4C33", + "links": { + "Chassis": [ + { + "href": "/rest/v1/Chassis/1" + } + ], + "Logs": { + "href": "/rest/v1/Systems/1/Logs" + }, + "ManagedBy": [ + { + "href": "/rest/v1/Managers/1" + } + ], + "self": { + "href": "/rest/v1/Systems/1" + } + } +} +""" + +UEFI_BOOT_DEVICE_ORDER_PXE = ['NIC.LOM.1.1.IPv4', + 'NIC.LOM.1.1.IPv6', + 'HD.Slot.1.2', + 'Generic.USB.1.1', + 'CD.Virtual.2.1', + 'FD.Virtual.1.1'] + +UEFI_BOOT_DEVICE_ORDER_HDD = ['HD.Slot.1.2', + 'NIC.LOM.1.1.IPv4', + 'NIC.LOM.1.1.IPv6', + 'Generic.USB.1.1', + 'CD.Virtual.2.1', + 'FD.Virtual.1.1'] + +UEFI_BOOT_DEVICE_ORDER_CD = ['CD.Virtual.2.1', + 'NIC.LOM.1.1.IPv4', + 'NIC.LOM.1.1.IPv6', + 'Generic.USB.1.1', + 'HD.Slot.1.2', + 'FD.Virtual.1.1'] + +UEFI_BOOT_DEVICE_ORDER_ERR = ['FAKE.Virtual.2.1', + 'CD.Virtual.2.1', + 'NIC.LOM.1.1.IPv4', + 'NIC.LOM.1.1.IPv6', + 'Generic.USB.1.1', + 'HD.Slot.1.2', + 'FD.Virtual.1.1'] + +UEFI_BOOT_SOURCES_ERR = ''' +[ + { + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC \ + (3863BB43683C,0x0)/IPv4(0.0.0.0)", + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port \ + 331i Adapter - NIC (PXE IPv4) ", + "StructuredBootString": "NIC.LOM.1.1.IPv4", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)" + }, + { + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC\ + (3863BB43683C,0x0)/IPv6(0000:0000:0000:0000:\ + 0000:0000:0000:0000)", + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port \ + 331i Adapter - NIC (PXE IPv6) ", + "StructuredBootString": "NIC.LOM.1.1.IPv6", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)" + }, + { + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)/Scsi\ + (0x0,0x0)", + "StructuredBootString": "HD.Slot.1.2", + "CorrelatableID": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)" + }, + { + "UEFIDevicePath": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)", + "BootString": "Generic USB Boot", + "StructuredBootString": "Generic.USB.1.1", + "CorrelatableID": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)" + }, + { + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)\ + /USB(0x0,0x0)", + "BootString": "iLO Virtual USB 2 : HP iLO Virtual USB CD/DVD ROM", + "StructuredBootString": "CD.Virtual.2.1", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)/USB\ + (0x0,0x0)" + }, + { + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x2)/Pci(0x0,0x4)/USB\ + (0x1,0x0)", + "BootString": "iLO Virtual USB 1 : HP iLO Virtual USB Key", + "StructuredBootString": "FD.Virtual.1.1", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x2)/Pci(0x0,0x4)/USB(0x1,\ + 0x0)" + } + ] +''' + +UEFI_PERS_BOOT_DEVICES = ["HD.Slot.1.1", + "HD.Slot.1.2", + "NIC.LOM.1.1.IPv4", + "NIC.LOM.1.1.IPv6", + "Generic.USB.1.1", + "CD.Virtual.2.1" + ] + +BOOT_PERS_DEV_ORDER_MISSING = """ + +{ + "AttributeRegistry": "HpBiosAttributeRegistryP89.1.1.00", + "BootSources": [ + { + "BootString": "Slot 1 : Smart Array P840 Controller - 279.37 GiB,\ + RAID 0 Logical Drive(Target:0, Lun:0)", + "CorrelatableID": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)", + "StructuredBootString": "HD.Slot.1.1", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)/Scsi\ + (0x0,0x0)" + }, + { + "BootString": "Slot 1 : Smart Array P840 Controller - 279.37 GiB,\ + RAID 0 Logical Drive(Target:0, Lun:1)", + "CorrelatableID": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)", + "StructuredBootString": "HD.Slot.1.2", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)/Scsi\ + (0x0,0x1)" + }, + { + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port\ + 331i Adapter - NIC (PXE IPv4) ", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)", + "StructuredBootString": "NIC.LOM.1.1.IPv4", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC\ + (C4346BB7EF30,0x0)/IPv4(0.0.0.0)" + }, + { + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port\ + 331i Adapter - NIC (PXE IPv6) ", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)", + "StructuredBootString": "NIC.LOM.1.1.IPv6", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC\ + (C4346BB7EF30,0x0)/IPv6(0000:0000:0000:0000:0000:0000:0000:0000)" + }, + { + "BootString": "Generic USB Boot", + "CorrelatableID": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)", + "StructuredBootString": "Generic.USB.1.1", + "UEFIDevicePath": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)" + }, + { + "BootString": "iLO Virtual USB 2 : HP iLO Virtual USB CD/DVD ROM", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)/USB\ + (0x0,0x0)", + "StructuredBootString": "CD.Virtual.2.1", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)/USB\ + (0x0,0x0)" + } + ], + "DefaultBootOrder": [ + "Floppy", + "Cd", + "Usb", + "EmbeddedStorage", + "PcieSlotStorage", + "EmbeddedFlexLOM", + "PcieSlotNic", + "UefiShell" + ], + "Description": "This is the Server Boot Order Current Settings", + "DesiredBootDevices": [ + { + "CorrelatableID": "", + "Lun": "", + "Wwn": "", + "iScsiTargetName": "" + }, + { + "CorrelatableID": "", + "Lun": "", + "Wwn": "", + "iScsiTargetName": "" + } + ], + "Modified": "2015-05-26T23:38:24+00:00", + "Name": "Boot Order Current Settings", + "SettingsResult": { + "ETag": "0DEA61A1609C51EED0628E3B0BC633DD", + "Messages": [ + { + "MessageArgs": [ + "PersistentBootConfigOrder[0" + ], + "MessageID": "Base.1.0:PropertyValueNotInList" + }, + { + "MessageArgs": [], + "MessageID": "Base.1.0:Success" + } + ], + "Time": "2015-05-14T02:38:40+00:00" + }, + "Type": "HpServerBootSettings.1.2.0", + "links": { + "BaseConfigs": { + "href": "/rest/v1/systems/1/bios/Boot/BaseConfigs" + }, + "Settings": { + "href": "/rest/v1/systems/1/bios/Boot/Settings" + }, + "self": { + "href": "/rest/v1/systems/1/bios/Boot" + } + } +} + +""" + +UEFI_BootSources = ''' +[ + { + "BootString": "Slot 1 : Smart Array P840 Controller - 279.37 GiB,\ + RAID 0 Logical Drive(Target:0, Lun:0)", + "CorrelatableID": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)", + "StructuredBootString": "HD.Slot.1.1", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)/Scsi\ + (0x0,0x0)" + }, + { + "BootString": "Slot 1 : Smart Array P840 Controller - 279.37 GiB,\ + RAID 0 Logical Drive(Target:0, Lun:1)", + "CorrelatableID": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)", + "StructuredBootString": "HD.Slot.1.2", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x2,0x0)/Pci(0x0,0x0)/Scsi\ + (0x0,0x1)" + }, + { + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port\ + 331i Adapter - NIC (PXE IPv4) ", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)", + "StructuredBootString": "NIC.LOM.1.1.IPv4", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC\ + (C4346BB7EF30,0x0)/IPv4(0.0.0.0)" + }, + { + "BootString": "Embedded LOM 1 Port 1 : HP Ethernet 1Gb 4-port\ + 331i Adapter - NIC (PXE IPv6) ", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)", + "StructuredBootString": "NIC.LOM.1.1.IPv6", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1C,0x4)/Pci(0x0,0x0)/MAC\ + (C4346BB7EF30,0x0)/IPv6(0000:0000:0000:0000:0000:0000:0000:0000)" + }, + { + "BootString": "Generic USB Boot", + "CorrelatableID": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)", + "StructuredBootString": "Generic.USB.1.1", + "UEFIDevicePath": "UsbClass(0xFFFF,0xFFFF,0xFF,0xFF,0xFF)" + }, + { + "BootString": "iLO Virtual USB 2 : HP iLO Virtual USB CD/DVD ROM", + "CorrelatableID": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)/USB\ + (0x0,0x0)", + "StructuredBootString": "CD.Virtual.2.1", + "UEFIDevicePath": "PciRoot(0x0)/Pci(0x1D,0x0)/USB(0x0,0x0)/USB\ + (0x0,0x0)" + } +] +''' + +UEFI_BOOTSOURCES_MISSING = """ +{ + "AttributeRegistry": "HpBiosAttributeRegistryP89.1.1.00", + "DefaultBootOrder": [ + "Floppy", + "Cd", + "Usb", + "EmbeddedStorage", + "PcieSlotStorage", + "EmbeddedFlexLOM", + "PcieSlotNic", + "UefiShell" + ], + "Description": "This is the Server Boot Order Current Settings", + "DesiredBootDevices": [ + { + "CorrelatableID": "", + "Lun": "", + "Wwn": "", + "iScsiTargetName": "" + }, + { + "CorrelatableID": "", + "Lun": "", + "Wwn": "", + "iScsiTargetName": "" + } + ], + "Modified": "2015-05-26T23:38:24+00:00", + "Name": "Boot Order Current Settings", + "PersistentBootConfigOrder": [ + "HD.Slot.1.1", + "HD.Slot.1.2", + "NIC.LOM.1.1.IPv4", + "NIC.LOM.1.1.IPv6", + "Generic.USB.1.1", + "CD.Virtual.2.1" + ], + "SettingsResult": { + "ETag": "0DEA61A1609C51EED0628E3B0BC633DD", + "Messages": [ + { + "MessageArgs": [ + "PersistentBootConfigOrder[0" + ], + "MessageID": "Base.1.0:PropertyValueNotInList" + }, + { + "MessageArgs": [], + "MessageID": "Base.1.0:Success" + } + ], + "Time": "2015-05-14T02:38:40+00:00" + }, + "Type": "HpServerBootSettings.1.2.0", + "links": { + "BaseConfigs": { + "href": "/rest/v1/systems/1/bios/Boot/BaseConfigs" + }, + "Settings": { + "href": "/rest/v1/systems/1/bios/Boot/Settings" + }, + "self": { + "href": "/rest/v1/systems/1/bios/Boot" + } + } +} +""" diff --git a/proliantutils/tests/ilo/test_client.py b/proliantutils/tests/ilo/test_client.py index 89aa7a8..8c7c758 100644 --- a/proliantutils/tests/ilo/test_client.py +++ b/proliantutils/tests/ilo/test_client.py @@ -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() diff --git a/proliantutils/tests/ilo/test_ribcl.py b/proliantutils/tests/ilo/test_ribcl.py index a1f153d..337424e 100644 --- a/proliantutils/tests/ilo/test_ribcl.py +++ b/proliantutils/tests/ilo/test_ribcl.py @@ -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, diff --git a/proliantutils/tests/ilo/test_ris.py b/proliantutils/tests/ilo/test_ris.py index 946af30..95369ee 100755 --- a/proliantutils/tests/ilo/test_ris.py +++ b/proliantutils/tests/ilo/test_ris.py @@ -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)