From 28d487379fbef9225488811f4c49765a66266dde Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 31 Jan 2018 17:30:59 +0800 Subject: [PATCH] pybind/mgr/balancer: load weight-set from ms 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 --- src/pybind/mgr/balancer/module.py | 57 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/pybind/mgr/balancer/module.py b/src/pybind/mgr/balancer/module.py index 0253de92454..3233688e8e8 100644 --- a/src/pybind/mgr/balancer/module.py +++ b/src/pybind/mgr/balancer/module.py @@ -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 = {} -- 2.39.5