From 1e3498ad9116d696a72ceb65d9f882b2c1970cd5 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 7 Mar 2018 13:56:17 +0800 Subject: [PATCH] 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 --- src/pybind/mgr/balancer/module.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.39.5