From 99ece544e54b5030581c5ec0939c649fa2c163f6 Mon Sep 17 00:00:00 2001 From: fperez Date: Wed, 23 Aug 2023 15:28:57 -0300 Subject: [PATCH] Fix for Horizon inventory in subclouds upgrade When dealing with a subcloud where Centos and SystemController have already been upgraded to Debian, Horizon encounters difficulties loading Host Inventory and Software Management pages. This issue arises due to variations in host attributes between different versions. To address this, any expected but missing attributes will be assigned default values before loading the page. Additionally, adding a fix for issues with sphinx version for this package Test Plan: - Select the target subcloud with the previous version. Navigate to Platform -> Host Inventory and confirm the successful loading of the Host table. - Select the target subcloud. Navigate to Platform -> Host Inventory and confirm the ability to load the Edit Host modal and Host details. - Select the target subcloud. Navigate to Platform -> Software Management and confirm the successful loading of patch details for this host. closes-bug: 2032838 Signed-off-by: fperez Change-Id: I671fcca81c14a787d4c55f823d1dae793fe2df35 --- doc/requirements.txt | 2 +- .../starlingx_dashboard/api/patch.py | 12 +++++++-- .../starlingx_dashboard/api/sysinv.py | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index f9f7a73d..3734ee1c 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,4 @@ -sphinx>=2.0.0,!=2.1.0 # BSD +sphinx>=2.0.0,!=2.1.0,<7.2.0 # BSD openstackdocstheme>=2.2.1 # Apache-2.0 # Release Notes documentation diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py index 30c71fe6..2c2b5d0d 100755 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/patch.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2014 Wind River Systems, Inc. +# Copyright (c) 2014-2023 Wind River Systems, Inc. # import logging @@ -208,6 +208,7 @@ def get_patch(request, patch_id): def get_hosts(request): hosts = [] + default_value = None try: info = _patching_client(request).get_hosts() except Exception: @@ -217,7 +218,14 @@ def get_hosts(request): for h in info['data']: host = Host() for a in host._attrs: - setattr(host, a, h[a]) + # if host received doesn't have this attribute, + # add it with a default value + if hasattr(h, a): + setattr(host, a, h[a]) + else: + setattr(host, a, default_value) + LOG.debug("Attribute not found. Adding default:" + "%s", a) hosts.append(host) return hosts diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py index c1dd705b..7d5aa298 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py @@ -1167,14 +1167,39 @@ def host_get(request, host_id): host = cgtsclient(request).ihost.get(host_id) if not host: raise ValueError('No match found for host_id "%s".' % host_id) + + # if host received doesn't have this attribute, + # add it with a default value + set_host_defaults(host) + return Host(host) def host_list(request): hosts = cgtsclient(request).ihost.list() + + # if host received doesn't have this attribute, + # add it with a default value + for host_data in hosts: + set_host_defaults(host_data) + return [Host(n) for n in hosts] +def set_host_defaults(host): + default_value = None + attrs_list = Host._attrs + + host_dict = host._info + for attr in attrs_list: + if attr not in host_dict: + LOG.debug("Attribute not found. Adding default value: %s: %s", + attr, default_value) + host._add_details({attr: default_value}) + + return + + class DNS(base.APIResourceWrapper): """..."""