]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/balancer: sanity check against empty roots 20788/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 7 Mar 2018 05:56:17 +0000 (13:56 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 8 Mar 2018 01:05:58 +0000 (09:05 +0800)
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 <xie.xingguo@zte.com.cn>
src/pybind/mgr/balancer/module.py

index 88f175608b5028edc9b7af1de9a2dd28b7f184da..7e4a3b5c6ef1629f90cb18299c07b9520b8a1025 100644 (file)
@@ -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