]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/balancer: sanity check against empty roots
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>
Sat, 10 Mar 2018 03:44:25 +0000 (11:44 +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>
(cherry picked from commit 1e3498ad9116d696a72ceb65d9f882b2c1970cd5)

src/pybind/mgr/balancer/module.py

index 0fbf798abf355205e5aba8a57cdae1a05d0d3072..1135bc4224722ddc9e7229cdb2ded431419ce90b 100644 (file)
@@ -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