From 1febf0c179682bc01e56a19e007103f65e92f0b1 Mon Sep 17 00:00:00 2001 From: "mccasland, trevor (tm2086)" Date: Fri, 13 Jul 2018 14:55:50 -0500 Subject: [PATCH] fix get_numeric_data The change[1] introduced a failure for the grouped-runs page, there is a case where if no data is provided to get_numeric_data it will error with[2] This change aims to fix that error by returning get_numeric_data early if no data is provided. [1] https://review.openstack.org/#/c/547866/ [2] http://paste.openstack.org/show/725854/ Change-Id: I02e9f40f4dcd44aefb47f5c8c96d9a318e034189 --- openstack_health/run_aggregator.py | 2 ++ openstack_health/tests/test_run_aggregator.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/openstack_health/run_aggregator.py b/openstack_health/run_aggregator.py index d6c56184..47eaba47 100644 --- a/openstack_health/run_aggregator.py +++ b/openstack_health/run_aggregator.py @@ -30,6 +30,8 @@ def format_output_numeric_dicts(df): def get_numeric_data(run_times_time_series, sample_rate): + if not run_times_time_series: + return {} temp_dict = {} sample_rate = base.resample_matrix[sample_rate] for run_at, run in run_times_time_series.items(): diff --git a/openstack_health/tests/test_run_aggregator.py b/openstack_health/tests/test_run_aggregator.py index 71d070a2..27eb616b 100644 --- a/openstack_health/tests/test_run_aggregator.py +++ b/openstack_health/tests/test_run_aggregator.py @@ -58,6 +58,11 @@ class TestRunAggregatorGetNumericData(base.TestCase): } } + def test_get_numeric_data_no_runs(self): + expected = {} + actual = run_aggregator.get_numeric_data({}, 'day') + self.assertEqual(expected, actual) + def test_get_numeric_data(self): self.maxDiff = None expected = {