Module: check_mk
Branch: master
Commit: 0e5ca0a1987af67295fbcfa64b162eeb300e5210
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0e5ca0a1987af6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 1 11:55:20 2019 +0100
Fix displaying of background job titles
* Made gui_title a classmethod because it is needed in a context
where no specific job is instantiated and the title is not a
object but a class attribute
* Add a regression test for this issue
* Add a test for ensuring the desired job classes are registered
Change-Id: I2298a284d184d57ecac463c58abea793f0e155f1
---
cmk/gui/gui_background_job.py | 4 ++--
cmk/gui/userdb.py | 6 +++---
cmk/gui/wato/__init__.py | 4 ++--
cmk/gui/wato/pages/host_rename.py | 4 ++--
cmk/gui/wato/pages/parentscan.py | 4 ++--
cmk/gui/wato/pages/services.py | 4 ++--
cmk/gui/watolib/bulk_discovery.py | 6 +++---
tests/unit/cmk/gui/test_background_job.py | 30 ++++++++++++++++++++++++++++--
8 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/cmk/gui/gui_background_job.py b/cmk/gui/gui_background_job.py
index 3d2b0cf..f608b00 100644
--- a/cmk/gui/gui_background_job.py
+++ b/cmk/gui/gui_background_job.py
@@ -542,10 +542,10 @@ class JobRenderer(object):
def show_job_class_infos(cls, job_class_infos, **kwargs):
"""Renders all jobs from the job_class_infos in a single
multi-table"""
html.open_table(css="job_table data")
- for job_class, jobs_info in sorted(job_class_infos.items(), key=lambda x:
x[0].gui_title):
+ for job_class, jobs_info in sorted(job_class_infos.items(), key=lambda x:
x[0].gui_title()):
html.open_tr()
html.open_td(colspan=len(cls.get_headers()))
- html.h3(job_class.gui_title)
+ html.h3(job_class.gui_title())
html.close_td()
html.close_tr()
diff --git a/cmk/gui/userdb.py b/cmk/gui/userdb.py
index 9dc10ac..1099fe9 100644
--- a/cmk/gui/userdb.py
+++ b/cmk/gui/userdb.py
@@ -1393,13 +1393,13 @@ def ajax_sync():
class UserSyncBackgroundJob(gui_background_job.GUIBackgroundJob):
job_prefix = "user_sync"
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("User synchronization")
def __init__(self):
kwargs = {}
- kwargs["title"] = self.gui_title
+ kwargs["title"] = self.gui_title()
kwargs["deletable"] = False
kwargs["stoppable"] = False
diff --git a/cmk/gui/wato/__init__.py b/cmk/gui/wato/__init__.py
index a81b5ad..9ae56e0 100644
--- a/cmk/gui/wato/__init__.py
+++ b/cmk/gui/wato/__init__.py
@@ -694,8 +694,8 @@ cmk.gui.pages.register_page_handler("fetch_agent_output",
lambda: PageFetchAgent
class FetchAgentOutputBackgroundJob(cmk.gui.plugins.wato.utils.WatoBackgroundJob):
job_prefix = "agent-output-"
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("Fetch agent output")
def __init__(self, site_id, host_name, ty):
diff --git a/cmk/gui/wato/pages/host_rename.py b/cmk/gui/wato/pages/host_rename.py
index 2286ccd..68b009d 100644
--- a/cmk/gui/wato/pages/host_rename.py
+++ b/cmk/gui/wato/pages/host_rename.py
@@ -75,8 +75,8 @@ from cmk.gui.plugins.wato import (
class RenameHostsBackgroundJob(WatoBackgroundJob):
job_prefix = "rename-hosts"
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("Host renaming")
def __init__(self, title=None):
diff --git a/cmk/gui/wato/pages/parentscan.py b/cmk/gui/wato/pages/parentscan.py
index 1b57482..8190ba0 100644
--- a/cmk/gui/wato/pages/parentscan.py
+++ b/cmk/gui/wato/pages/parentscan.py
@@ -53,8 +53,8 @@ ParentScanResult = collections.namedtuple("ParentScanResult",
class ParentScanBackgroundJob(WatoBackgroundJob):
job_prefix = "parent_scan"
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("Parent scan")
def __init__(self):
diff --git a/cmk/gui/wato/pages/services.py b/cmk/gui/wato/pages/services.py
index 187f936..bd0efac 100644
--- a/cmk/gui/wato/pages/services.py
+++ b/cmk/gui/wato/pages/services.py
@@ -372,8 +372,8 @@ class ServiceDiscoveryBackgroundJob(WatoBackgroundJob):
housekeeping_max_age_sec = 86400 # 1 day
housekeeping_max_count = 20
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("Service discovery")
def __init__(self, host_name):
diff --git a/cmk/gui/watolib/bulk_discovery.py b/cmk/gui/watolib/bulk_discovery.py
index b9d4003..cf7041d 100644
--- a/cmk/gui/watolib/bulk_discovery.py
+++ b/cmk/gui/watolib/bulk_discovery.py
@@ -127,13 +127,13 @@ def vs_bulk_discovery(render_form=False, include_subfolders=True):
class BulkDiscoveryBackgroundJob(WatoBackgroundJob):
job_prefix = "bulk_discovery"
- @property
- def gui_title(self):
+ @classmethod
+ def gui_title(cls):
return _("Bulk Discovery")
def __init__(self):
kwargs = {}
- kwargs["title"] = _("Bulk discovery")
+ kwargs["title"] = self.gui_title()
kwargs["lock_wato"] = False
kwargs["deletable"] = False
kwargs["stoppable"] = False
diff --git a/tests/unit/cmk/gui/test_background_job.py
b/tests/unit/cmk/gui/test_background_job.py
index 3630500..90c4440 100644
--- a/tests/unit/cmk/gui/test_background_job.py
+++ b/tests/unit/cmk/gui/test_background_job.py
@@ -8,6 +8,8 @@ import testlib # type: ignore
import cmk.utils.paths
import cmk.gui.background_job as background_job
import cmk.gui.gui_background_job as gui_background_job
+# Loads all GUI modules
+import cmk.gui.modules # pylint: disable=unused-import
import cmk.gui.log
@@ -19,6 +21,27 @@ def debug_logging():
cmk.gui.log.set_log_levels({"cmk.web": cmk.gui.log._logging.INFO})
+def test_registered_background_jobs():
+ assert sorted(gui_background_job.job_registry.keys()) == sorted([
+ 'ParentScanBackgroundJob',
+ 'BakeAgentsBackgroundJob',
+ 'DummyBackgroundJob',
+ 'RenameHostsBackgroundJob',
+ 'ReportingBackgroundJob',
+ 'RenameHostBackgroundJob',
+ 'FetchAgentOutputBackgroundJob',
+ 'BulkDiscoveryBackgroundJob',
+ 'UserSyncBackgroundJob',
+ 'ServiceDiscoveryBackgroundJob',
+ ])
+
+
+def test_registered_background_jobs_attributes():
+ for job_class in gui_background_job.job_registry.values():
+ assert isinstance(job_class.job_prefix, str)
+ assert isinstance(job_class.gui_title(), unicode)
+
+
@pytest.fixture(autouse=True)
def job_base_dir(tmpdir, monkeypatch):
var_dir = Path("%s" % tmpdir)
@@ -39,11 +62,14 @@ def job_base_dir(tmpdir, monkeypatch):
@gui_background_job.job_registry.register
class DummyBackgroundJob(gui_background_job.GUIBackgroundJob):
job_prefix = "dummy_job"
- gui_title = u"Dummy Job"
+
+ @classmethod
+ def gui_title(cls):
+ return u"Dummy Job"
def __init__(self):
kwargs = {}
- kwargs["title"] = self.gui_title
+ kwargs["title"] = self.gui_title()
kwargs["deletable"] = False
kwargs["stoppable"] = True
self.finish_hello_event = multiprocessing.Event()