Redfish: Adding the ability to get current boot mode

This commit adds new function 'get_current_boot_mode' to get
current boot mode for server.

Change-Id: I85c1376457698bda81120b74f54e08e5236c9974
This commit is contained in:
kesper 2017-05-22 11:22:03 +00:00
parent 10fcea9ebc
commit 09d869326a
7 changed files with 51 additions and 8 deletions

View File

@ -66,6 +66,7 @@ SUPPORTED_REDFISH_METHODS = [
'hold_pwr_btn',
'get_one_time_boot',
'get_pending_boot_mode',
'get_current_boot_mode',
]
LOG = log.get_logger(__name__)

View File

@ -268,7 +268,23 @@ class RedfishOperations(operations.IloOperations):
return BOOT_MODE_MAP.get(
sushy_system.bios_settings.pending_settings.boot_mode)
except sushy.exceptions.SushyError as e:
msg = (self._('The pending BIOS Settings was not found. Error'
msg = (self._('The pending BIOS Settings was not found. Error '
'%(error)s') %
{'error': str(e)})
LOG.debug(msg)
raise exception.IloError(msg)
def get_current_boot_mode(self):
"""Retrieves the current boot mode of the server.
:returns: Current boot mode, LEGACY or UEFI.
:raises: IloError, on an error from iLO.
"""
sushy_system = self._get_sushy_system(PROLIANT_SYSTEM_ID)
try:
return BOOT_MODE_MAP.get(sushy_system.bios_settings.boot_mode)
except sushy.exceptions.SushyError as e:
msg = (self._('The current BIOS Settings was not found. Error '
'%(error)s') %
{'error': str(e)})
LOG.debug(msg)

View File

@ -12,18 +12,21 @@
# License for the specific language governing permissions and limitations
# under the License.
from sushy.resources import base
from proliantutils.redfish.resources.system import mappings
from proliantutils.redfish import utils
from sushy.resources import base
class BIOSSettings(base.ResourceBase):
boot_mode = base.MappedField(["Attributes", "BootMode"],
mappings.GET_BIOS_BOOT_MODE_MAP)
_pending_settings = None
@property
def pending_settings(self):
"""Property to provide reference to bios settings instance
"""Property to provide reference to bios_pending_settings instance
It is calculated once when the first time it is queried. On refresh,
this property gets reset.

View File

@ -84,7 +84,7 @@ class HPESystem(system.System):
@property
def bios_settings(self):
"""Property to provide reference to bios resources instance
"""Property to provide reference to bios_settings instance
It is calculated once when the first time it is queried. On refresh,
this property gets reset.

View File

@ -292,7 +292,7 @@
}
},
"BIOS_settings_default": {
"BIOS_pending_settings_default": {
"@odata.context": "/redfish/v1/$metadata#Bios.Bios",
"@odata.etag": "W/\"7F2D028BA2542B2B2B2AF4CFFD358F35\"",
"@odata.id": "/redfish/v1/systems/1/bios/settings/",

View File

@ -19,6 +19,7 @@ import mock
import testtools
from proliantutils.redfish.resources.system import bios
from proliantutils.redfish.resources.system import constants as sys_cons
class BIOSSettingsTestCase(testtools.TestCase):
@ -35,6 +36,10 @@ class BIOSSettingsTestCase(testtools.TestCase):
self.conn, '/redfish/v1/Systems/1/bios',
redfish_version='1.0.2')
def test_attributes(self):
self.assertEqual(sys_cons.BIOS_BOOT_MODE_UEFI,
self.bios_inst.boot_mode)
def test_pending_settings(self):
self.assertIsNone(self.bios_inst._pending_settings)
@ -42,7 +47,7 @@ class BIOSSettingsTestCase(testtools.TestCase):
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
self.conn.get.return_value.json.return_value = (
json.loads(f.read())['BIOS_settings_default'])
json.loads(f.read())['BIOS_pending_settings_default'])
actual_settings = self.bios_inst.pending_settings
self.assertIsInstance(actual_settings,
bios.BIOSPendingSettings)
@ -62,11 +67,12 @@ class BIOSPendingSettingsTestCase(testtools.TestCase):
with open('proliantutils/tests/redfish/'
'json_samples/bios.json', 'r') as f:
self.conn.get.return_value.json.return_value = (
json.loads(f.read())['BIOS_settings_default'])
json.loads(f.read())['BIOS_pending_settings_default'])
self.bios_settings_inst = bios.BIOSPendingSettings(
self.conn, '/redfish/v1/Systems/1/bios/settings',
redfish_version='1.0.2')
def test_attributes(self):
self.assertEqual('uefi', self.bios_settings_inst.boot_mode)
self.assertEqual(sys_cons.BIOS_BOOT_MODE_UEFI,
self.bios_settings_inst.boot_mode)

View File

@ -194,3 +194,20 @@ class RedfishOperationsTestCase(testtools.TestCase):
exception.IloError,
'The pending BIOS Settings was not found.',
self.rf_client.get_pending_boot_mode)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_boot_mode(self, get_system_mock):
for cons_val in redfish.BOOT_MODE_MAP.keys():
get_system_mock.return_value.bios_settings.boot_mode = cons_val
result = self.rf_client.get_current_boot_mode()
self.assertEqual(redfish.BOOT_MODE_MAP[cons_val], result)
@mock.patch.object(redfish.RedfishOperations, '_get_sushy_system')
def test_get_current_boot_mode_fail(self, get_system_mock):
bios_mock = mock.PropertyMock(
side_effect=sushy.exceptions.SushyError)
type(get_system_mock.return_value).bios_settings = bios_mock
self.assertRaisesRegex(
exception.IloError,
'The current BIOS Settings was not found.',
self.rf_client.get_current_boot_mode)