From aa78a20f666c0d6d50597b5f4f4a88dbdb62eced Mon Sep 17 00:00:00 2001 From: Feilong Wang Date: Tue, 26 Sep 2017 16:25:27 +1300 Subject: [PATCH] Fix divide zero error when no object storage cost Change-Id: I6018678aac7367c5fbe4d169509feff1f262d05d --- distil_ui/api/distil_v2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/distil_ui/api/distil_v2.py b/distil_ui/api/distil_v2.py index bb5c65b..961abad 100644 --- a/distil_ui/api/distil_v2.py +++ b/distil_ui/api/distil_v2.py @@ -155,7 +155,9 @@ def _wash_details(current_details): # NOTE(flwang): Currently, the breakdown will accumulate all the object # storage cost, so we need to deduce the duplicated part. object_cost = current_details["breakdown"].get(OBJECTSTORAGE_CATEGORY, 0) - dup_object_cost = (region_count - 1) * (object_cost / region_count) + + dup_object_cost = (0 if region_count == 0 else + (region_count - 1) * (object_cost / region_count)) current_details["total_cost"] = (current_details["total_cost"] - dup_object_cost) return current_details