From f3836a17dfba142285feb41ba8fbbe0763dd1697 Mon Sep 17 00:00:00 2001 From: hsiang41 Date: Sun, 20 Jan 2019 21:22:24 +0800 Subject: [PATCH] mgr/diskprediction_cloud: fix divide by zero when total_size is 0 Fix devide by zero when total_size is o. Ref ticket: https://tracker.ceph.com/issues/37736 Signed-off-by: Rick Chen --- src/pybind/mgr/diskprediction_cloud/common/clusterdata.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/diskprediction_cloud/common/clusterdata.py b/src/pybind/mgr/diskprediction_cloud/common/clusterdata.py index 41997a36300e..45add6937643 100644 --- a/src/pybind/mgr/diskprediction_cloud/common/clusterdata.py +++ b/src/pybind/mgr/diskprediction_cloud/common/clusterdata.py @@ -261,7 +261,10 @@ class ClusterAPI(object): total_size = round(float(ceph_stats.get('total_bytes', 0)) / GB) avail_size = round(float(ceph_stats.get('total_avail_bytes', 0)) / GB, 2) raw_used_size = round(float(ceph_stats.get('total_used_bytes', 0)) / GB, 2) - raw_used_percent = round(float(raw_used_size) / float(total_size) * 100, 2) + if total_size != 0: + raw_used_percent = round(float(raw_used_size) / float(total_size) * 100, 2) + else: + raw_used_percent = 0 return {'total_size': total_size, 'avail_size': avail_size, 'raw_used_size': raw_used_size, 'used_percent': raw_used_percent} -- 2.47.3