From: xie xingguo Date: Wed, 7 Mar 2018 05:56:17 +0000 (+0800) Subject: pybind/mgr/balancer: sanity check against empty roots X-Git-Tag: v13.0.2~27^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F20788%2Fhead;p=ceph.git pybind/mgr/balancer: sanity check against empty roots To avoid crashes as below: ``` File "/usr/lib/ceph/mgr/balancer/module.py", line 181, in calc_stats score += target[k] * (math.erf(((adjusted - avg)/avg) / math.sqrt(2.0))) ZeroDivisionError: float division by zero ``` Signed-off-by: xie xingguo --- diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 88f175608b5..7e4a3b5c6ef 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -141,6 +141,15 @@ class Eval: num = max(len(target), 1) r = {} for t in ('pgs', 'objects', 'bytes'): + if total[t] == 0: + r[t] = { + 'avg': 0, + 'stddev': 0, + 'sum_weight': 0, + 'score': 0, + } + continue + avg = float(total[t]) / float(num) dev = 0.0