From 7e8845bf25bb079fa7db06fe432759d302a2a61b Mon Sep 17 00:00:00 2001 From: Enzo Candotti Date: Thu, 2 Nov 2023 22:36:32 -0300 Subject: [PATCH] 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 Change-Id: Ia8cdce0b89be30abc632a8161201302cd9a51681 --- .../starlingx_dashboard/api/patch.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py index 2c2b5d0d..cd5c7149 100755 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py @@ -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)