Merge "Add balancer module support for 'upmap'"
This commit is contained in:
commit
1e148346b7
|
@ -314,3 +314,9 @@ options:
|
|||
The charm does not segregate access to pools from different models properly,
|
||||
this means that the correct charm settings can result with client model B
|
||||
having access to the data from model A.
|
||||
balancer-mode:
|
||||
type: string
|
||||
default:
|
||||
description: |
|
||||
The balancer mode used by the Ceph manager. Can only be set for Luminous or
|
||||
later versions, and only when the balancer module is enabled.
|
||||
|
|
|
@ -102,6 +102,7 @@ from utils import (
|
|||
mgr_disable_module,
|
||||
mgr_enable_module,
|
||||
is_mgr_module_enabled,
|
||||
set_balancer_mode,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.charmsupport import nrpe
|
||||
|
@ -245,6 +246,7 @@ def config_changed():
|
|||
assert_charm_supports_ipv6()
|
||||
|
||||
check_for_upgrade()
|
||||
set_balancer_mode(config('balancer-mode'))
|
||||
|
||||
log('Monitor hosts are ' + repr(get_mon_hosts()))
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ from charmhelpers.fetch import (
|
|||
from charmhelpers.core.host import (
|
||||
lsb_release,
|
||||
CompareHostReleases,
|
||||
cmp_pkgrevno,
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
|
@ -109,6 +110,23 @@ def mgr_disable_module(module):
|
|||
return False
|
||||
|
||||
|
||||
def set_balancer_mode(mode):
|
||||
'''Set the balancer mode used by the Ceph manager.'''
|
||||
if not mode:
|
||||
return
|
||||
elif cmp_pkgrevno('ceph-common', '12.0.0') < 0:
|
||||
log('Luminous or later is required to set the balancer mode')
|
||||
return
|
||||
elif not is_mgr_module_enabled('balancer'):
|
||||
log("Balancer module is disabled")
|
||||
return
|
||||
|
||||
try:
|
||||
subprocess.check_call(['ceph', 'balancer', 'mode', mode], shell=True)
|
||||
except subprocess.CalledProcessError:
|
||||
log('Failed to set balancer mode:', level='ERROR')
|
||||
|
||||
|
||||
@cached
|
||||
def get_unit_hostname():
|
||||
return socket.gethostname()
|
||||
|
|
|
@ -409,6 +409,7 @@ class CephHooksTestCase(test_utils.CharmTestCase):
|
|||
notify_client):
|
||||
relations_of_type.return_value = False
|
||||
self.test_config.set('pg-autotune', 'false')
|
||||
self.test_config.set('balancer-mode', '')
|
||||
ceph_hooks.config_changed()
|
||||
mgr_enable_module.assert_not_called()
|
||||
|
||||
|
@ -438,6 +439,7 @@ class CephHooksTestCase(test_utils.CharmTestCase):
|
|||
relations_of_type.return_value = False
|
||||
cmp_pkgrevno.return_value = 1
|
||||
self.test_config.set('pg-autotune', 'true')
|
||||
self.test_config.set('balancer-mode', '')
|
||||
ceph_hooks.config_changed()
|
||||
mgr_enable_module.assert_called_once_with('pg_autoscaler')
|
||||
monitor_key_set.assert_called_once_with('admin', 'autotune', 'true')
|
||||
|
@ -466,6 +468,7 @@ class CephHooksTestCase(test_utils.CharmTestCase):
|
|||
relations_of_type.return_value = False
|
||||
cmp_pkgrevno.return_value = 1
|
||||
self.test_config.set('pg-autotune', 'auto')
|
||||
self.test_config.set('balancer-mode', '')
|
||||
ceph_hooks.config_changed()
|
||||
mgr_enable_module.assert_not_called()
|
||||
|
||||
|
@ -928,6 +931,7 @@ class BootstrapSourceTestCase(test_utils.CharmTestCase):
|
|||
self.relations_of_type.return_value = []
|
||||
self.is_relation_made.return_value = True
|
||||
self.test_config.set_changed('no-bootstrap', True)
|
||||
self.test_config.set('balancer-mode', '')
|
||||
ceph_hooks.config_changed()
|
||||
bootstrap_source_rel_changed.assert_called_once()
|
||||
|
||||
|
|
|
@ -354,3 +354,37 @@ class CephUtilsTestCase(test_utils.CharmTestCase):
|
|||
|
||||
with self.assertRaises(utils.OsdPostUpgradeError):
|
||||
utils._is_required_osd_release(release)
|
||||
|
||||
@mock.patch.object(utils.subprocess, 'check_call')
|
||||
@mock.patch.object(utils, 'is_mgr_module_enabled')
|
||||
@mock.patch.object(utils, 'cmp_pkgrevno')
|
||||
def test_balancer_mode(self,
|
||||
cmp_pkgrevno,
|
||||
is_mgr_module_enabled,
|
||||
check_call):
|
||||
cmp_pkgrevno.return_value = 0
|
||||
is_mgr_module_enabled.return_value = True
|
||||
utils.set_balancer_mode('upmap')
|
||||
check_call.assert_called_with(['ceph', 'balancer', 'mode',
|
||||
'upmap'], shell=True)
|
||||
|
||||
@mock.patch.object(utils.subprocess, 'check_call')
|
||||
@mock.patch.object(utils, 'cmp_pkgrevno')
|
||||
def test_balancer_mode_before_luminous(self,
|
||||
cmp_pkgrevno,
|
||||
check_call):
|
||||
cmp_pkgrevno.return_value = -1
|
||||
utils.set_balancer_mode('upmap')
|
||||
check_call.assert_not_called()
|
||||
|
||||
@mock.patch.object(utils.subprocess, 'check_call')
|
||||
@mock.patch.object(utils, 'is_mgr_module_enabled')
|
||||
@mock.patch.object(utils, 'cmp_pkgrevno')
|
||||
def test_balancer_mode_no_balancer(self,
|
||||
cmp_pkgrevno,
|
||||
is_mgr_module_enabled,
|
||||
check_call):
|
||||
cmp_pkgrevno.return_value = 0
|
||||
is_mgr_module_enabled.return_value = False
|
||||
utils.set_balancer_mode('upmap')
|
||||
check_call.assert_not_called()
|
||||
|
|
Loading…
Reference in New Issue