Simplify UEFI logic and change the UefiHttp flow
In trying to test the Redfish UEFI Http interface logic, it was observed that we were not getting the values out of the emulator we expected. So this change simplifies the logic which wasn't quite working for us. We also realized the code was trying to set the boot interface before actually creating it. Doh! It seems, also I might have had some other issues in the original patch which we couldn't detect without fully getting everything working, so some additional refactoring exists with this patch. Change-Id: Ibfe5a560a25251965e8bad87012f64e89d9640be
This commit is contained in:
parent
b5edaadd8d
commit
feb88a5c46
|
@ -389,6 +389,7 @@ def system_resource(identity):
|
|||
total_cpus=try_get(app.systems.get_total_cpus),
|
||||
boot_source_target=app.systems.get_boot_device(identity),
|
||||
boot_source_mode=try_get(app.systems.get_boot_mode),
|
||||
uefi_mode=(try_get(app.systems.get_boot_mode) == 'UEFI'),
|
||||
managers=app.managers.get_managers_for_system(identity),
|
||||
chassis=app.chassis.chassis[:1],
|
||||
indicator_led=app.indicators.get_indicator_state(
|
||||
|
@ -405,6 +406,38 @@ def system_resource(identity):
|
|||
|
||||
if boot:
|
||||
target = boot.get('BootSourceOverrideTarget')
|
||||
mode = boot.get('BootSourceOverrideMode')
|
||||
http_uri = boot.get('HttpBootUri')
|
||||
|
||||
if http_uri and target == 'UefiHttp':
|
||||
|
||||
try:
|
||||
# Download the image
|
||||
image_path = app.vmedia.insert_image(
|
||||
identity, 'Cd', http_uri)
|
||||
except Exception as e:
|
||||
app.logger.error('Unable to insert image for HttpBootUri '
|
||||
'request processing. Error: %s', e)
|
||||
return 'Failed to download and attach HttpBootUri.', 400
|
||||
try:
|
||||
# Mount it as an ISO
|
||||
app.systems.set_boot_image(
|
||||
identity,
|
||||
'Cd', boot_image=image_path,
|
||||
write_protected=True)
|
||||
# Set it for our emulator's API surface to return it
|
||||
# if queried.
|
||||
except Exception as e:
|
||||
app.logger.error('Unable to attach HttpBootUri for boot '
|
||||
'operation. Error: %s', e)
|
||||
return (('Failed to set the supplied media as the next '
|
||||
'bootdevice.'), 400)
|
||||
try:
|
||||
app.systems.set_http_boot_uri(http_uri)
|
||||
except Exception as e:
|
||||
app.logger.error('Unable to record HttpBootUri for boot '
|
||||
'operation. Error: %s', e)
|
||||
return 'Failed to save HttpBootUri field value.', 400
|
||||
|
||||
if target == 'UefiHttp':
|
||||
# Reset to Cd, in our case, since we can't force override
|
||||
|
@ -422,34 +455,12 @@ def system_resource(identity):
|
|||
app.logger.info('Set boot device to "%s" for system "%s"',
|
||||
target, identity)
|
||||
|
||||
mode = boot.get('BootSourceOverrideMode')
|
||||
|
||||
if mode:
|
||||
app.systems.set_boot_mode(identity, mode)
|
||||
|
||||
app.logger.info('Set boot mode to "%s" for system "%s"',
|
||||
mode, identity)
|
||||
|
||||
http_uri = boot.get('HttpBootUri')
|
||||
|
||||
if http_uri:
|
||||
|
||||
try:
|
||||
# Download the image
|
||||
image_path = flask.current_app.vmedia.insert_image(
|
||||
identity, 'Cd', http_uri)
|
||||
# Mount it as an ISO
|
||||
flask.current_app.systems.set_boot_image(
|
||||
'Cd', boot_image=image_path,
|
||||
write_protected=True)
|
||||
# Set it for our emulator's API surface to return it
|
||||
# if queried.
|
||||
flask.current_app.systems.set_http_boot_uri(http_uri)
|
||||
except Exception as e:
|
||||
app.logger.error('Unable to load HttpBootUri for boot '
|
||||
'operation. Error: %s', e)
|
||||
return '', 400
|
||||
|
||||
if not target and not mode and not http_uri:
|
||||
return ('Missing the BootSourceOverrideTarget and/or '
|
||||
'BootSourceOverrideMode and/or HttpBootUri '
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"Pxe",
|
||||
"Cd",
|
||||
{%- if boot_source_mode %}
|
||||
{%- if 'uefi' in boot_source_mode.lower() %}
|
||||
{%- if uefi_mode %}
|
||||
"Hdd",
|
||||
"UefiHttp"
|
||||
],
|
||||
|
|
|
@ -292,7 +292,10 @@ class SystemsTestCase(EmulatorTestCase):
|
|||
set_http_boot_uri = systems_mock.return_value.set_http_boot_uri
|
||||
set_boot_device.assert_called_once_with('xxxx-yyyy-zzzz', 'Cd')
|
||||
set_boot_image.assert_called_once_with(
|
||||
'Cd', boot_image='/path/to/file.iso', write_protected=True)
|
||||
'xxxx-yyyy-zzzz',
|
||||
'Cd',
|
||||
boot_image='/path/to/file.iso',
|
||||
write_protected=True)
|
||||
set_boot_mode.assert_called_once_with('xxxx-yyyy-zzzz', 'UEFI')
|
||||
set_http_boot_uri.assert_called_once_with('http://test.url/boot.iso')
|
||||
|
||||
|
|
Loading…
Reference in New Issue