Fix efficacy indicators in action plans

Currently, Efficacy in action plans list and efficacy indicators in
action plan details are empty.

There are two different problems:

- While EfficacyIndicator expects a dict, global_efficacy is a list
  with one dict inside.
- EfficacyIndicator is using getattr function to initialize the
  attributes while the correct way for dicts is get, which also provides
  None when the attribute does not exist.

This is effectively reverting [1].

[1] https://review.opendev.org/c/openstack/watcher-dashboard/+/587032

Closes-Bug: #2086627

Change-Id: I5a45357ccd69da26443818ae165ba08963004358
This commit is contained in:
Alfredo Moralejo 2024-10-18 12:56:12 +02:00
parent 0451ec9c5f
commit 42d8914dcf
2 changed files with 10 additions and 5 deletions
watcher_dashboard
api
content/action_plans

@ -514,7 +514,7 @@ class EfficacyIndicator(base.APIDictWrapper):
def __init__(self, indicator):
super(EfficacyIndicator, self).__init__(indicator)
self.value = getattr(indicator, 'value', None)
self.name = getattr(indicator, 'name', None)
self.description = getattr(indicator, 'description', None)
self.unit = getattr(indicator, 'unit', None)
self.value = indicator.get('value', None)
self.name = indicator.get('name', None)
self.description = indicator.get('description', None)
self.unit = indicator.get('unit', None)

@ -126,7 +126,12 @@ class UpdateRow(horizon.tables.Row):
def format_global_efficacy(action_plan):
formatted_global_efficacy = None
global_efficacy = watcher.EfficacyIndicator(action_plan.global_efficacy)
# action_plan.global_efficacy is a list with one dict while we need a dict
if len(action_plan.global_efficacy) > 0:
global_efficacy_dict = action_plan.global_efficacy[0]
else:
global_efficacy_dict = {}
global_efficacy = watcher.EfficacyIndicator(global_efficacy_dict)
if global_efficacy.value is not None and global_efficacy.unit:
formatted_global_efficacy = "%(value)s %(unit)s" % dict(
unit=global_efficacy.unit,