diff --git a/proliantutils/ilo/ris.py b/proliantutils/ilo/ris.py index 86eaea3..9391c6d 100755 --- a/proliantutils/ilo/ris.py +++ b/proliantutils/ilo/ris.py @@ -959,6 +959,10 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations): except Exception: return None + def _is_sriov_enabled(self): + """Return sriov enabled or not""" + return (self._get_bios_setting('Sriov') == 'Enabled') + def get_server_capabilities(self): """Gets server properties which can be used for scheduling @@ -989,6 +993,8 @@ class RISOperations(rest.RestConnectorBase, operations.IloOperations): # If an error is raised dont populate the capability # secure_boot pass + if self._is_sriov_enabled(): + capabilities['sriov_enabled'] = 'true' return capabilities def activate_license(self, key): diff --git a/proliantutils/redfish/redfish.py b/proliantutils/redfish/redfish.py index 0ae1d0b..063fd0b 100644 --- a/proliantutils/redfish/redfish.py +++ b/proliantutils/redfish/redfish.py @@ -597,16 +597,25 @@ class RedfishOperations(operations.IloOperations): def get_server_capabilities(self): """Returns the server capabilities - :raises: IloError if any Sushy error is encountered. + raises: IloError on an error from iLO. """ capabilities = {} + sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID) try: count = len(sushy_system.pci_devices.gpu_devices) capabilities.update({'pci_gpu_devices': count}) + + capabilities.update( + {key: 'true' + for (key, value) in (( + 'sriov_enabled', + sushy_system.bios_settings.sriov == sys_cons.SRIOV_ENABLED + ),)}) + except sushy.exceptions.SushyError as e: msg = (self._("The Redfish controller is unable to get " - "resource or its members. Error" + "resource or its members. Error " "%(error)s)") % {'error': str(e)}) LOG.debug(msg) raise exception.IloError(msg) diff --git a/proliantutils/redfish/resources/system/bios.py b/proliantutils/redfish/resources/system/bios.py index 5dac062..0447d50 100644 --- a/proliantutils/redfish/resources/system/bios.py +++ b/proliantutils/redfish/resources/system/bios.py @@ -36,6 +36,9 @@ class BIOSSettings(base.ResourceBase): boot_mode = base.MappedField(["Attributes", "BootMode"], mappings.GET_BIOS_BOOT_MODE_MAP) + + sriov = base.MappedField(['Attributes', 'Sriov'], mappings.SRIOV_MAP) + _pending_settings = None _boot_settings = None _base_configs = None diff --git a/proliantutils/redfish/resources/system/constants.py b/proliantutils/redfish/resources/system/constants.py index 1a2ff12..6f5b82e 100644 --- a/proliantutils/redfish/resources/system/constants.py +++ b/proliantutils/redfish/resources/system/constants.py @@ -30,3 +30,8 @@ BOOT_SOURCE_TARGET_CD = 'Cd' BOOT_SOURCE_TARGET_PXE = 'Pxe' BOOT_SOURCE_TARGET_UEFI_TARGET = 'UefiTarget' BOOT_SOURCE_TARGET_HDD = 'Hdd' + +# BIOS Sriov constants + +SRIOV_ENABLED = 'sriov enabled' +SRIOV_DISABLED = 'sriov disabled' diff --git a/proliantutils/redfish/resources/system/mappings.py b/proliantutils/redfish/resources/system/mappings.py index e23a8aa..a935c62 100644 --- a/proliantutils/redfish/resources/system/mappings.py +++ b/proliantutils/redfish/resources/system/mappings.py @@ -34,3 +34,10 @@ GET_BIOS_BOOT_MODE_MAP = { GET_BIOS_BOOT_MODE_MAP_REV = ( utils.revert_dictionary(GET_BIOS_BOOT_MODE_MAP)) + +# BIOS Sriov mappings + +SRIOV_MAP = { + 'Enabled': constants.SRIOV_ENABLED, + 'Disabled': constants.SRIOV_DISABLED +} diff --git a/proliantutils/tests/ilo/test_ris.py b/proliantutils/tests/ilo/test_ris.py index a969183..abb0dcf 100755 --- a/proliantutils/tests/ilo/test_ris.py +++ b/proliantutils/tests/ilo/test_ris.py @@ -375,6 +375,7 @@ class IloRisTestCase(testtools.TestCase): validate_mock.assert_called_once_with(ris_outputs.GET_HEADERS, settings_uri) + @mock.patch.object(ris.RISOperations, '_get_bios_setting') @mock.patch.object(ris.RISOperations, '_get_nvdimm_n_status') @mock.patch.object(ris.RISOperations, '_get_cpu_virtualization') @@ -386,7 +387,8 @@ class IloRisTestCase(testtools.TestCase): @mock.patch.object(ris.RISOperations, '_get_host_details') def test_get_server_capabilities(self, get_details_mock, ilo_firm_mock, secure_mock, gpu_mock, tpm_mock, - cpu_vt_mock, nvdimm_n_mock): + cpu_vt_mock, nvdimm_n_mock, + bios_sriov_mock): host_details = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP) get_details_mock.return_value = host_details ilo_firm_mock.return_value = {'ilo_firmware_version': 'iLO 4 v2.20'} @@ -395,6 +397,7 @@ class IloRisTestCase(testtools.TestCase): secure_mock.return_value = False nvdimm_n_mock.return_value = True tpm_mock.return_value = True + bios_sriov_mock.return_value = 'Disabled' expected_caps = {'secure_boot': 'true', 'ilo_firmware_version': 'iLO 4 v2.20', 'rom_firmware_version': u'I36 v1.40 (01/28/2015)', @@ -406,6 +409,7 @@ class IloRisTestCase(testtools.TestCase): capabilities = self.client.get_server_capabilities() self.assertEqual(expected_caps, capabilities) + @mock.patch.object(ris.RISOperations, '_get_bios_setting') @mock.patch.object(ris.RISOperations, '_get_nvdimm_n_status') @mock.patch.object(ris.RISOperations, '_get_cpu_virtualization') @@ -419,7 +423,8 @@ class IloRisTestCase(testtools.TestCase): get_details_mock, ilo_firm_mock, secure_mock, gpu_mock, tpm_mock, - cpu_vt_mock, nvdimm_n_mock): + cpu_vt_mock, nvdimm_n_mock, + bios_sriov_mock): host_details = json.loads(ris_outputs.RESPONSE_BODY_FOR_REST_OP) get_details_mock.return_value = host_details ilo_firm_mock.return_value = {'ilo_firmware_version': 'iLO 4 v2.20'} @@ -428,13 +433,15 @@ class IloRisTestCase(testtools.TestCase): nvdimm_n_mock.return_value = True tpm_mock.return_value = False cpu_vt_mock.return_value = True + bios_sriov_mock.return_value = 'Enabled' expected_caps = {'secure_boot': 'true', 'ilo_firmware_version': 'iLO 4 v2.20', 'rom_firmware_version': u'I36 v1.40 (01/28/2015)', 'server_model': u'ProLiant BL460c Gen9', 'pci_gpu_devices': 2, 'cpu_vt': 'true', - 'nvdimm_n': 'true'} + 'nvdimm_n': 'true', + 'sriov_enabled': 'true'} capabilities = self.client.get_server_capabilities() self.assertEqual(expected_caps, capabilities) diff --git a/proliantutils/tests/redfish/resources/system/test_bios.py b/proliantutils/tests/redfish/resources/system/test_bios.py index 48558e5..f70ff38 100644 --- a/proliantutils/tests/redfish/resources/system/test_bios.py +++ b/proliantutils/tests/redfish/resources/system/test_bios.py @@ -41,6 +41,8 @@ class BIOSSettingsTestCase(testtools.TestCase): def test_attributes(self): self.assertEqual(sys_cons.BIOS_BOOT_MODE_UEFI, self.bios_inst.boot_mode) + self.assertEqual(sys_cons.SRIOV_ENABLED, + self.bios_inst.sriov) def test_pending_settings(self): self.assertIsNone(self.bios_inst._pending_settings) diff --git a/proliantutils/tests/redfish/test_redfish.py b/proliantutils/tests/redfish/test_redfish.py index 419aa44..1d1222c 100644 --- a/proliantutils/tests/redfish/test_redfish.py +++ b/proliantutils/tests/redfish/test_redfish.py @@ -28,6 +28,7 @@ from proliantutils.redfish.resources.manager import manager from proliantutils.redfish.resources.manager import virtual_media from proliantutils.redfish.resources.system import bios from proliantutils.redfish.resources.system import constants as sys_cons +from proliantutils.redfish.resources.system import pci_device from proliantutils.redfish.resources.system import system as pro_sys from sushy.resources.system import system @@ -655,11 +656,12 @@ class RedfishOperationsTestCase(testtools.TestCase): 'pci_device.json') with open(path, 'r') as f: val.append(json.loads(f.read())) - gpu_mock = mock.PropertyMock(return_value=val) type(get_system_mock.return_value.pci_devices).gpu_devices = ( - gpu_mock) + [mock.MagicMock(spec=pci_device.PCIDevice)]) + type(get_system_mock.return_value.bios_settings).sriov = ( + sys_cons.SRIOV_ENABLED) actual = self.rf_client.get_server_capabilities() - expected = {'pci_gpu_devices': 1} + expected = {'pci_gpu_devices': 1, 'sriov_enabled': 'true'} self.assertEqual(expected, actual) @mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')