Merge pull request #31969 from sebastian-philipp/mgr-fix-mocking

pybind/mgr: Make it easier to create a Module instance without the mgr

Reviewed-by: Ricardo Dias <rdias@suse.com>
Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sebastian Wagner 2019-12-03 15:26:23 +01:00 committed by GitHub
commit 88636f8bf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -414,7 +414,7 @@ class CPlusPlusHandler(logging.Handler):
class FileHandler(logging.FileHandler):
def __init__(self, module_inst):
path = module_inst._ceph_get_option("log_file")
path = module_inst.get_ceph_option("log_file")
idx = path.rfind(".log")
if idx != -1:
self.path = "{}.{}.log".format(path[:idx], module_inst.module_name)
@ -535,7 +535,7 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule, MgrModuleLoggingMixin):
super(MgrStandbyModule, self).__init__(capsule)
self.module_name = module_name
mgr_level = self._ceph_get_option("debug_mgr")
mgr_level = self.get_ceph_option("debug_mgr")
log_level = self.get_module_option("log_level")
self._configure_logging(mgr_level, log_level, False)
@ -641,7 +641,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
self.module_name = module_name
super(MgrModule, self).__init__(py_modules_ptr, this_ptr)
mgr_level = self._ceph_get_option("debug_mgr")
mgr_level = self.get_ceph_option("debug_mgr")
log_level = self.get_module_option("log_level")
self._configure_logging(mgr_level, log_level,
self.get_module_option("log_to_file", False))
@ -733,7 +733,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
def _config_notify(self):
# check logging options for changes
mgr_level = self._ceph_get_option("debug_mgr")
mgr_level = self.get_ceph_option("debug_mgr")
module_level = self.get_module_option("log_level")
log_to_file = self.get_module_option("log_to_file", False)

View File

@ -23,13 +23,17 @@ def get_store_prefix(self, prefix):
if k.startswith(prefix)
}
def get_ceph_option(_, key):
return __file__
@pytest.yield_fixture()
def ssh_module():
with mock.patch("ssh.module.SSHOrchestrator.get_ceph_option", lambda _, key: __file__),\
with mock.patch("ssh.module.SSHOrchestrator.get_ceph_option", get_ceph_option),\
mock.patch("ssh.module.SSHOrchestrator._configure_logging", lambda *args: None),\
mock.patch("ssh.module.SSHOrchestrator.set_store", set_store),\
mock.patch("ssh.module.SSHOrchestrator.get_store", get_store),\
mock.patch("ssh.module.SSHOrchestrator.get_store_prefix", get_store_prefix):
SSHOrchestrator._register_commands('')
m = SSHOrchestrator.__new__ (SSHOrchestrator)
m._store = {
'ssh_config': '',