Skip to content

Commit 7752bd0

Browse files
authored
Merge pull request ceph#63785 from guits/wip-71575-tentacle
tentacle: mgr/dashboard: fix KeyError exception in HardwareService.get_summary()
2 parents a8ae312 + f80d395 commit 7752bd0

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/pybind/mgr/dashboard/services/hardware.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,41 @@ def get_summary(categories: Optional[List[str]] = None,
2323
}
2424
}
2525

26+
def count_ok(data: dict) -> int:
27+
return sum(
28+
component.get("status", {}).get("health") == "OK"
29+
for node in data.values()
30+
for system in node.values()
31+
for component in system.values()
32+
)
33+
34+
def count_total(data: dict) -> int:
35+
return sum(
36+
len(component)
37+
for system in data.values()
38+
for component in system.values()
39+
)
40+
2641
categories = HardwareService.validate_categories(categories)
2742

2843
orch_hardware_instance = OrchClient.instance().hardware
2944
for category in categories:
3045
data = orch_hardware_instance.common(category, hostname)
3146
category_total = {
32-
'total': sum(len(items) for items in data.values()),
33-
'ok': sum(item['status']['health'] == 'OK' for items in data.values()
34-
for item in items.values()),
47+
'total': count_total(data),
48+
'ok': count_ok(data),
3549
'error': 0
3650
}
3751

38-
for host, items in data.items():
52+
for host, systems in data.items():
3953
output['host'].setdefault(host, {'flawed': False})
4054
if not output['host'][host]['flawed']:
41-
output['host'][host]['flawed'] = any(
42-
item['status']['health'] != 'OK' for item in items.values())
55+
for system in systems.values():
56+
if any(dimm['status']['health'] != 'OK' for dimm in system.values()):
57+
output['host'][host]['flawed'] = True
58+
break
4359

44-
category_total['error'] = category_total['total'] - category_total['ok']
60+
category_total['error'] = max(0, category_total['total'] - category_total['ok'])
4561
output['total']['category'].setdefault(category, {})
4662
output['total']['category'][category] = category_total
4763

0 commit comments

Comments
 (0)