]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr/balancer: load weight-set from ms
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 31 Jan 2018 09:30:59 +0000 (17:30 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 31 Jan 2018 09:38:34 +0000 (17:38 +0800)
See https://github.com/ceph/ceph/pull/20178, so we won't
try to call 'ceph osd crush weight-set create-compat' multiple times.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/pybind/mgr/balancer/module.py

index 0253de924549061d3c24a2b6836d17032cb2739e..3233688e8e863008ad554672e3fc5c2795926739 100644 (file)
@@ -657,7 +657,7 @@ class Module(MgrModule):
                             if b < 1.0 and b > 0.0 ]
 
         # get current compat weight-set weights
-        orig_ws = self.get_compat_weight_set_weights()
+        orig_ws = self.get_compat_weight_set_weights(ms)
         if orig_ws is None:
             return False
         orig_ws = { a: b for a, b in orig_ws.iteritems() if a >= 0 }
@@ -802,32 +802,35 @@ class Module(MgrModule):
                           pe.score)
             return False
 
-    def get_compat_weight_set_weights(self):
-        # enable compat weight-set
-        self.log.debug('ceph osd crush weight-set create-compat')
-        result = CommandResult('')
-        self.send_command(result, 'mon', '', json.dumps({
-            'prefix': 'osd crush weight-set create-compat',
-            'format': 'json',
-        }), '')
-        r, outb, outs = result.wait()
-        if r != 0:
-            self.log.error('Error creating compat weight-set')
-            return
-
-        result = CommandResult('')
-        self.send_command(result, 'mon', '', json.dumps({
-            'prefix': 'osd crush dump',
-            'format': 'json',
-        }), '')
-        r, outb, outs = result.wait()
-        if r != 0:
-            self.log.error('Error dumping crush map')
-            return
-        try:
-            crushmap = json.loads(outb)
-        except:
-            raise RuntimeError('unable to parse crush map')
+    def get_compat_weight_set_weights(self, ms):
+        if '-1' not in ms.crush_dump.get('choose_args', {}):
+            # enable compat weight-set first
+            self.log.debug('ceph osd crush weight-set create-compat')
+            result = CommandResult('')
+            self.send_command(result, 'mon', '', json.dumps({
+                'prefix': 'osd crush weight-set create-compat',
+                'format': 'json',
+            }), '')
+            r, outb, outs = result.wait()
+            if r != 0:
+                self.log.error('Error creating compat weight-set')
+                return
+
+            result = CommandResult('')
+            self.send_command(result, 'mon', '', json.dumps({
+                'prefix': 'osd crush dump',
+                'format': 'json',
+            }), '')
+            r, outb, outs = result.wait()
+            if r != 0:
+                self.log.error('Error dumping crush map')
+                return
+            try:
+                crushmap = json.loads(outb)
+            except:
+                raise RuntimeError('unable to parse crush map')
+        else:
+            crushmap = ms.crush_dump
 
         raw = crushmap.get('choose_args',{}).get('-1', [])
         weight_set = {}