-
-from unittest import case
import json
import logging
self.mgr_daemons[mgr_id].restart()
def get_mgr_map(self):
- status = json.loads(
- self.mon_manager.raw_cluster_cmd("status", "--format=json-pretty"))
-
- return status["mgrmap"]
+ return json.loads(
+ self.mon_manager.raw_cluster_cmd("mgr", "dump", "--format=json-pretty"))
def get_active_id(self):
return self.get_mgr_map()["active_name"]
module, key
), val)
- def set_module_localized_conf(self, module, mgr_id, key, val):
- self.mon_manager.raw_cluster_cmd("config", "set", "mgr",
- "mgr/{0}/{1}/{2}".format(
- module, mgr_id, key
- ), val)
+ def set_module_localized_conf(self, module, mgr_id, key, val, force):
+ cmd = ["config", "set", "mgr",
+ "/".join(["mgr", module, mgr_id, key]),
+ val]
+ if force:
+ cmd.append("--force")
+ self.mon_manager.raw_cluster_cmd(*cmd)
class MgrTestCase(CephTestCase):
assert cls.mgr_cluster is not None
if len(cls.mgr_cluster.mgr_ids) < cls.MGRS_REQUIRED:
- raise case.SkipTest("Only have {0} manager daemons, "
- "{1} are required".format(
- len(cls.mgr_cluster.mgr_ids), cls.MGRS_REQUIRED))
+ cls.skipTest(
+ "Only have {0} manager daemons, {1} are required".format(
+ len(cls.mgr_cluster.mgr_ids), cls.MGRS_REQUIRED))
cls.setup_mgrs()
+ @classmethod
+ def _unload_module(cls, module_name):
+ def is_disabled():
+ enabled_modules = json.loads(cls.mgr_cluster.mon_manager.raw_cluster_cmd(
+ 'mgr', 'module', 'ls'))['enabled_modules']
+ return module_name not in enabled_modules
+
+ if is_disabled():
+ return
+
+ log.info("Unloading Mgr module %s ...", module_name)
+ cls.mgr_cluster.mon_manager.raw_cluster_cmd('mgr', 'module', 'disable', module_name)
+ cls.wait_until_true(is_disabled, timeout=30)
+
@classmethod
def _load_module(cls, module_name):
loaded = json.loads(cls.mgr_cluster.mon_manager.raw_cluster_cmd(
- "mgr", "module", "ls"))['enabled_modules']
+ "mgr", "module", "ls"))['enabled_modules']
if module_name in loaded:
# The enable command is idempotent, but our wait for a restart
# isn't, so let's return now if it's already loaded
# check if the the module is configured as an always on module
mgr_daemons = json.loads(cls.mgr_cluster.mon_manager.raw_cluster_cmd(
- "mgr", "metadata"))
+ "mgr", "metadata"))
for daemon in mgr_daemons:
if daemon["name"] == initial_mgr_map["active_name"]:
if module_name in always_on:
return
+ log.info("Loading Mgr module %s ...", module_name)
initial_gid = initial_mgr_map['active_gid']
- cls.mgr_cluster.mon_manager.raw_cluster_cmd("mgr", "module", "enable",
- module_name, "--force")
+ cls.mgr_cluster.mon_manager.raw_cluster_cmd(
+ "mgr", "module", "enable", module_name, "--force")
# Wait for the module to load
def has_restarted():
done = mgr_map['active_gid'] != initial_gid and mgr_map['available']
if done:
log.info("Restarted after module load (new active {0}/{1})".format(
- mgr_map['active_name'] , mgr_map['active_gid']))
+ mgr_map['active_name'], mgr_map['active_gid']))
return done
cls.wait_until_true(has_restarted, timeout=30)
))
cls.mgr_cluster.set_module_localized_conf(module_name, mgr_id,
config_name,
- str(assign_port))
+ str(assign_port),
+ force=True)
assign_port += 1
for mgr_id in cls.mgr_cluster.mgr_ids: