From: hsiang41 Date: Sun, 20 Jan 2019 13:22:24 +0000 (+0800) Subject: mgr/diskprediction_cloud: fix divide by zero when total_size is 0 X-Git-Tag: v14.1.0~323^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F26045%2Fhead;p=ceph.git 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 --- 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}