Fix Horizon crash on a patch installation

When a patch installation is triggered on a locked host via Horizon,
it crashes redirecting to an error screen. The normal behaviour seen
using the CLI is just an error message saying that the host is unknown
because of being locked.

Horizon should show this error message instead of crashing. The root
cause is an issue during raising the ValueError expection, because
of an 'AttributeError' exception raised on the 'split_message'
function.

This commit fixes this problem by replacing the ValueError exception
with the Horizon error message function.

Closes-Bug: 2040495

Test Plan:
PASS: Build the starlingx-dashboard package, install it on a
system and verify the changes are applied correctly.
PASS: Execute test scenarios to receive errors in various
requests impacted by this function. Verify that the error message
is correctly displayed and logged.

Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
Change-Id: Ia8cdce0b89be30abc632a8161201302cd9a51681
This commit is contained in:
Enzo Candotti 2023-11-02 22:36:32 -03:00
parent 8121f7d24d
commit 7e8845bf25
1 changed files with 12 additions and 8 deletions

View File

@ -20,6 +20,8 @@ from six.moves.urllib.parse import urlparse
import requests
from horizon import messages
from openstack_dashboard.api import base
from requests_toolbelt import MultipartEncoder
@ -236,10 +238,12 @@ def get_host(request, hostname):
None)
def get_message(data):
def get_message(request, data):
LOG.info("RESPONSE: %s", data)
if not data or ('error' in data and data["error"] != ""):
raise ValueError(data["error"] or "Invalid patch file")
error_msg = data["error"] or "Invalid patch file"
messages.error(request, error_msg)
LOG.error(error_msg)
if 'warning' in data and data["warning"] != "":
return data["warning"]
if 'info' in data and data["info"] != "":
@ -250,29 +254,29 @@ def get_message(data):
def upload_patch(request, patchfile, name):
_file = {'file': (name, patchfile,)}
resp = _patching_client(request).upload(_file)
return get_message(resp)
return get_message(request, resp)
def patch_apply_req(request, patch_id):
resp = _patching_client(request).apply(patch_id)
return get_message(resp)
return get_message(request, resp)
def patch_remove_req(request, patch_id):
resp = _patching_client(request).remove(patch_id)
return get_message(resp)
return get_message(request, resp)
def patch_delete_req(request, patch_id):
resp = _patching_client(request).delete(patch_id)
return get_message(resp)
return get_message(request, resp)
def host_install(request, hostname):
resp = _patching_client(request).host_install(hostname)
return get_message(resp)
return get_message(request, resp)
def host_install_async(request, hostname):
resp = _patching_client(request).host_install_async(hostname)
return get_message(resp)
return get_message(request, resp)