mirror of
https://github.com/krkn-chaos/krkn.git
synced 2026-08-25 09:27:36 +00:00
handle None values in node summary for text report (#1541)
Signed-off-by: Teju Gangisetty <tgangise@redhat.com>
This commit is contained in:
@@ -316,12 +316,12 @@ def build_chaos_report(chaos_output: dict) -> str:
|
||||
lines.append(f" {'Type':<8} {'Count':<6} {'Instance':<14} {'Arch':<7} {'Kubelet':<10} OS")
|
||||
for ni in node_infos:
|
||||
lines.append(
|
||||
f" {ni.get('nodes_type', 'N/A'):<8} "
|
||||
f"{ni.get('count', 'N/A'):<6} "
|
||||
f"{ni.get('instance_type', 'N/A'):<14} "
|
||||
f"{ni.get('architecture', 'N/A'):<7} "
|
||||
f"{ni.get('kubelet_version', 'N/A'):<10} "
|
||||
f"{ni.get('os_version', 'N/A')}"
|
||||
f" {ni.get('nodes_type') or 'N/A':<8} "
|
||||
f"{'N/A' if ni.get('count') is None else ni.get('count'):<6} "
|
||||
f"{ni.get('instance_type') or 'N/A':<14} "
|
||||
f"{ni.get('architecture') or 'N/A':<7} "
|
||||
f"{ni.get('kubelet_version') or 'N/A':<10} "
|
||||
f"{ni.get('os_version') or 'N/A'}"
|
||||
)
|
||||
|
||||
# --- Targets ---
|
||||
|
||||
@@ -596,6 +596,24 @@ class TestBuildChaosReportClusterOverview(unittest.TestCase):
|
||||
self.assertIn("worker", report)
|
||||
self.assertIn("m6i.xlarge", report)
|
||||
|
||||
def test_node_summary_with_none_values(self):
|
||||
"""Test that None node metadata fields render as N/A without crashing."""
|
||||
output = _minimal_chaos_output()
|
||||
output["telemetry"]["node_summary_infos"] = [{
|
||||
"nodes_type": None,
|
||||
"count": 3,
|
||||
"instance_type": None,
|
||||
"architecture": "amd64",
|
||||
"kubelet_version": "v1.28.0",
|
||||
"os_version": "Linux",
|
||||
}]
|
||||
report = build_chaos_report(output)
|
||||
self.assertIn("CLUSTER OVERVIEW", report)
|
||||
overview_start = report.index("CLUSTER OVERVIEW")
|
||||
overview_section = report[overview_start:overview_start + 200]
|
||||
self.assertIn("N/A", overview_section)
|
||||
self.assertNotIn("None", overview_section)
|
||||
|
||||
def test_no_overview_when_empty(self):
|
||||
output = _minimal_chaos_output()
|
||||
output["telemetry"]["node_summary_infos"] = []
|
||||
|
||||
Reference in New Issue
Block a user