ILO: Support for configuring httpboot through RIS
This commit adds two methods 'get_http_boot_url' and 'set_http_boot_url' in proliantutils for configuring HTTPBoot support through RIS. The test cases for these methods are also added. Change-Id: I49310dfa65850739a605cde04834157947731608
This commit is contained in:
@@ -55,6 +55,16 @@ class IloCommandNotSupportedError(IloError):
|
||||
super(IloError, self).__init__(message)
|
||||
|
||||
|
||||
class IloCommandNotSupportedInBiosError(IloCommandNotSupportedError):
|
||||
"""Command not supported on the bios boot mode.
|
||||
|
||||
This exception is raised when iLO client library fails to
|
||||
communicate properly with the iLO
|
||||
"""
|
||||
def __init__(self, message, errorcode=None):
|
||||
super(IloCommandNotSupportedInBiosError, self).__init__(message)
|
||||
|
||||
|
||||
class IloLoginFailError(IloError):
|
||||
"""iLO Login Failed.
|
||||
|
||||
|
||||
@@ -37,6 +37,26 @@ class IloOperations:
|
||||
"""Request the power state of the server."""
|
||||
raise exception.IloCommandNotSupportedError(ERRMSG)
|
||||
|
||||
def get_http_boot_url(self):
|
||||
"""Request the http boot url.
|
||||
|
||||
:returns: URL for http boot.
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
raise exception.IloCommandNotSupportedError(ERRMSG)
|
||||
|
||||
def set_http_boot_url(self, url):
|
||||
"""Set the url to the UefiShellStartupUrl.
|
||||
|
||||
:param url: URL for http boot.
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
raise exception.IloCommandNotSupportedError(ERRMSG)
|
||||
|
||||
def get_one_time_boot(self):
|
||||
"""Retrieves the current setting for the one time boot."""
|
||||
raise exception.IloCommandNotSupportedError(ERRMSG)
|
||||
|
||||
@@ -453,6 +453,51 @@ class RISOperations(operations.IloOperations):
|
||||
data = self._get_host_details()
|
||||
return data['Power'].upper()
|
||||
|
||||
def _validate_uefi_boot_mode(self):
|
||||
"""Checks if the system is in uefi boot mode.
|
||||
|
||||
:return: 'True' if the boot mode is uefi else 'False'
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedError, if the command is not supported
|
||||
on the server.
|
||||
"""
|
||||
|
||||
boot_mode = self.get_current_boot_mode()
|
||||
if boot_mode == 'UEFI':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_http_boot_url(self):
|
||||
"""Request the http boot url from system in uefi boot mode.
|
||||
|
||||
:returns: URL for http boot
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedInBiosError, if the system is
|
||||
in the bios boot mode.
|
||||
"""
|
||||
|
||||
if(self._validate_uefi_boot_mode() is True):
|
||||
return self._get_bios_setting('UefiShellStartupUrl')
|
||||
else:
|
||||
msg = 'get_http_boot_url is not supported in the BIOS boot mode'
|
||||
raise exception.IloCommandNotSupportedInBiosError(msg)
|
||||
|
||||
def set_http_boot_url(self, url):
|
||||
"""Set url to the UefiShellStartupUrl to the system in uefi boot mode.
|
||||
|
||||
:param url: URL for http boot
|
||||
:raises: IloError, on an error from iLO.
|
||||
:raises: IloCommandNotSupportedInBiosError, if the system is
|
||||
in the bios boot mode.
|
||||
"""
|
||||
|
||||
if(self._validate_uefi_boot_mode() is True):
|
||||
self._change_bios_setting({'UefiShellStartupUrl': url})
|
||||
else:
|
||||
msg = 'set_http_boot_url is not supported in the BIOS boot mode'
|
||||
raise exception.IloCommandNotSupportedInBiosError(msg)
|
||||
|
||||
def get_current_boot_mode(self):
|
||||
"""Retrieves the current boot mode of the server.
|
||||
|
||||
|
||||
@@ -15,3 +15,7 @@
|
||||
|
||||
# Flake doesn't allow files without anything. Remove on first commit.
|
||||
MODULE = "RIS"
|
||||
|
||||
HTTP_BOOT_URL = {
|
||||
"UefiShellStartupUrl": "http://10.10.1.30:8081/startup.nsh"
|
||||
}
|
||||
|
||||
@@ -98,6 +98,19 @@ class IloRibclTestCase(unittest.TestCase):
|
||||
result = self.ilo.get_host_power_status()
|
||||
self.assertIn('ON', result)
|
||||
|
||||
def test_get_http_boot_url(self):
|
||||
self.assertRaises(
|
||||
exception.IloCommandNotSupportedError,
|
||||
self.ilo.get_http_boot_url
|
||||
)
|
||||
|
||||
def test_set_http_boot_url(self):
|
||||
self.assertRaises(
|
||||
exception.IloCommandNotSupportedError,
|
||||
self.ilo.set_http_boot_url,
|
||||
'http://10.10.1.30:8081/startup.nsh'
|
||||
)
|
||||
|
||||
@mock.patch.object(ribcl.RIBCLOperations, '_request_ilo')
|
||||
def test_reset_server(self, request_ilo_mock):
|
||||
request_ilo_mock.return_value = constants.RESET_SERVER_XML
|
||||
|
||||
@@ -14,3 +14,66 @@
|
||||
# under the License.
|
||||
|
||||
"""Test class for RIS Module."""
|
||||
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import ris_sample_outputs as ris_constants
|
||||
|
||||
from proliantutils import exception
|
||||
from proliantutils.ilo import ris
|
||||
|
||||
|
||||
class IloRisTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(IloRisTestCase, self).setUp()
|
||||
self.ilo = ris.RISOperations("x.x.x.x", "Administrator", "admin", None)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_get_bios_setting')
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
def test_get_http_boot_url_uefi(self, _validate_uefi_boot_mode_mock,
|
||||
get_bios_settings_mock):
|
||||
get_bios_settings_mock.return_value = ris_constants.HTTP_BOOT_URL
|
||||
_validate_uefi_boot_mode_mock.return_value = True
|
||||
result = self.ilo.get_http_boot_url()
|
||||
_validate_uefi_boot_mode_mock.assert_called_once_with()
|
||||
self.assertEqual(
|
||||
'http://10.10.1.30:8081/startup.nsh', result['UefiShellStartupUrl']
|
||||
)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_change_bios_setting')
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
def test_set_http_boot_url_uefi(self, _validate_uefi_boot_mode_mock,
|
||||
change_bios_setting_mock):
|
||||
_validate_uefi_boot_mode_mock.return_value = True
|
||||
self.ilo.set_http_boot_url('http://10.10.1.30:8081/startup.nsh')
|
||||
_validate_uefi_boot_mode_mock.assert_called_once_with()
|
||||
change_bios_setting_mock.assert_called_once_with({
|
||||
"UefiShellStartupUrl": "http://10.10.1.30:8081/startup.nsh"
|
||||
})
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
def test_get_http_boot_url_bios(self, _validate_uefi_boot_mode_mock):
|
||||
_validate_uefi_boot_mode_mock.return_value = False
|
||||
self.assertRaises(exception.IloCommandNotSupportedInBiosError,
|
||||
self.ilo.get_http_boot_url)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, '_validate_uefi_boot_mode')
|
||||
def test_set_http_boot_url_bios(self, _validate_uefi_boot_mode_mock):
|
||||
_validate_uefi_boot_mode_mock.return_value = False
|
||||
self.assertRaises(exception.IloCommandNotSupportedInBiosError,
|
||||
self.ilo.set_http_boot_url,
|
||||
'http://10.10.1.30:8081/startup.nsh')
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'get_current_boot_mode')
|
||||
def test__validate_uefi_boot_mode_uefi(self, get_current_boot_mode_mock):
|
||||
get_current_boot_mode_mock.return_value = 'UEFI'
|
||||
result = self.ilo._validate_uefi_boot_mode()
|
||||
self.assertTrue(result)
|
||||
|
||||
@mock.patch.object(ris.RISOperations, 'get_current_boot_mode')
|
||||
def test__validate_uefi_boot_mode_bios(self, get_current_boot_mode_mock):
|
||||
get_current_boot_mode_mock.return_value = 'LEGACY'
|
||||
result = self.ilo._validate_uefi_boot_mode()
|
||||
self.assertFalse(result)
|
||||
|
||||
Reference in New Issue
Block a user