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: v12.2.5~81^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c4336b51b05a968736824d7d0976eb438e21c6ac;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 (cherry picked from commit 1e3498ad9116d696a72ceb65d9f882b2c1970cd5) --- diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 0fbf798abf3..1135bc42247 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -143,6 +143,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