Skip to content
Permalink
Browse files

cmk: rename __init__.py to version.py to make cmk a namespace

This allows us to shadow shipped plugins by corresponding files
in the local hierarchy.

Change-Id: I34814b57804b4ff69c3a7fc511d3e7c588319534
  • Loading branch information
mo-ki committed Mar 2, 2020
1 parent 5f84c12 commit f5201a91b63f5721d0af55ddecc1bd0551553d25
Showing with 435 additions and 380 deletions.
  1. +1 −1 Makefile
  2. +2 −3 cmk/.f12
  3. +9 −68 cmk/__init__.py
  4. +3 −3 cmk/base/checking.py
  5. +6 −6 cmk/base/config.py
  6. +2 −1 cmk/base/core_config.py
  7. +2 −2 cmk/base/decorator.py
  8. +2 −2 cmk/base/default_config/notify.py
  9. +4 −4 cmk/base/events.py
  10. +0 −1 cmk/base/inventory.py
  11. +2 −2 cmk/base/modes/check_mk.py
  12. +0 −1 cmk/ec/actions.py
  13. +4 −4 cmk/ec/main.py
  14. +2 −2 cmk/ec/settings.py
  15. +2 −1 cmk/gui/availability.py
  16. +1 −2 cmk/gui/background_job.py
  17. +0 −1 cmk/gui/bi.py
  18. +5 −5 cmk/gui/config.py
  19. +2 −1 cmk/gui/crash_reporting.py
  20. +2 −2 cmk/gui/cron.py
  21. +3 −2 cmk/gui/dashboard.py
  22. +4 −3 cmk/gui/htmllib.py
  23. +5 −3 cmk/gui/login.py
  24. +2 −1 cmk/gui/metrics.py
  25. +2 −1 cmk/gui/mkeventd.py
  26. +4 −4 cmk/gui/modules.py
  27. +1 −2 cmk/gui/node_visualization.py
  28. +2 −2 cmk/gui/plugins/metrics/timeseries.py
  29. +5 −5 cmk/gui/plugins/openapi/endpoints/version.py
  30. +3 −3 cmk/gui/plugins/userdb/ldap_connector.py
  31. +5 −3 cmk/gui/plugins/views/availability.py
  32. +3 −3 cmk/gui/plugins/views/builtin.py
  33. +6 −4 cmk/gui/plugins/visuals/filters.py
  34. +5 −5 cmk/gui/plugins/wato/bi.py
  35. +2 −2 cmk/gui/plugins/wato/builtin_modules.py
  36. +2 −2 cmk/gui/plugins/wato/check_mk_configuration.py
  37. +3 −2 cmk/gui/plugins/wato/notifications.py
  38. +2 −1 cmk/gui/plugins/wato/omd_configuration.py
  39. +4 −4 cmk/gui/plugins/webapi/webapi.py
  40. +7 −7 cmk/gui/sidebar.py
  41. +1 −1 cmk/gui/sites.py
  42. +2 −1 cmk/gui/userdb.py
  43. +4 −3 cmk/gui/views.py
  44. +4 −4 cmk/gui/visuals.py
  45. +4 −4 cmk/gui/wato/__init__.py
  46. +8 −7 cmk/gui/wato/mkeventd.py
  47. +7 −5 cmk/gui/wato/pages/automation.py
  48. +3 −2 cmk/gui/wato/pages/global_settings.py
  49. +4 −2 cmk/gui/wato/pages/ldap.py
  50. +0 −1 cmk/gui/wato/pages/notifications.py
  51. +1 −3 cmk/gui/wato/pages/object_parameters.py
  52. +1 −1 cmk/gui/wato/pages/rulesets.py
  53. +5 −6 cmk/gui/wato/pages/services.py
  54. +6 −3 cmk/gui/wato/pages/sites.py
  55. +2 −1 cmk/gui/wato/pages/timeperiods.py
  56. +9 −9 cmk/gui/wato/pages/users.py
  57. +4 −4 cmk/gui/watolib/__init__.py
  58. +3 −2 cmk/gui/watolib/activate_changes.py
  59. +3 −3 cmk/gui/watolib/automation_commands.py
  60. +3 −3 cmk/gui/watolib/automations.py
  61. +3 −2 cmk/gui/watolib/config_domains.py
  62. +5 −4 cmk/gui/watolib/groups.py
  63. +13 −8 cmk/gui/watolib/hosts_and_folders.py
  64. +2 −2 cmk/gui/watolib/sites.py
  65. +2 −2 cmk/gui/watolib/utils.py
  66. +2 −2 cmk/gui/webapi.py
  67. +2 −1 cmk/gui/werks.py
  68. +2 −2 cmk/gui/wsgi/routing.py
  69. +2 −2 cmk/special_agents/agent_bi.py
  70. +3 −3 cmk/utils/crash_reporting.py
  71. +10 −9 cmk/utils/packaging.py
  72. +74 −0 cmk/utils/version.py
  73. +2 −1 doc/treasures/wato_hook_cleanup_folders.py
  74. +2 −2 inventory/omd_status
  75. +0 −1 omd/packages/check_mk/check_mk.make
  76. +8 −8 tests-py3/integration/cmk/gui/test_webapi.py
  77. +5 −4 tests-py3/integration/cmk/test_omd_version.py
  78. +3 −3 tests-py3/unit/cmk/base/test_config.py
  79. +2 −2 tests-py3/unit/cmk/base/test_unit_automations.py
  80. +2 −2 tests-py3/unit/cmk/ec/test_rule_matching.py
  81. +2 −2 tests-py3/unit/conftest.py
  82. +6 −5 tests/testlib/__init__.py
  83. +1 −1 tests/testlib/site.py
  84. +3 −3 tests/unit/cmk/gui/plugins/sidebar/test_snapins.py
  85. +3 −3 tests/unit/cmk/gui/plugins/views/test_icons.py
  86. +3 −3 tests/unit/cmk/gui/plugins/visuals/test_filters.py
  87. +4 −2 tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py
  88. +3 −3 tests/unit/cmk/gui/plugins/wato/utils/test_sample_config.py
  89. +2 −2 tests/unit/cmk/gui/test_background_job.py
  90. +2 −2 tests/unit/cmk/gui/test_cron.py
  91. +3 −3 tests/unit/cmk/gui/test_dashboard.py
  92. +3 −3 tests/unit/cmk/gui/test_gui_config.py
  93. +2 −2 tests/unit/cmk/gui/test_pages.py
  94. +3 −1 tests/unit/cmk/gui/test_views.py
  95. +2 −2 tests/unit/cmk/gui/test_visuals.py
  96. +2 −2 tests/unit/cmk/gui/test_webapi_unit.py
  97. +2 −2 tests/unit/cmk/gui/watolib/test_analyze_configuration.py
  98. +5 −3 tests/unit/cmk/gui/watolib/test_rulespecs.py
  99. +6 −4 tests/unit/cmk/gui/watolib/test_watolib.py
  100. +5 −4 tests/unit/cmk/gui/wsgi/test_wsgi_router.py
  101. +26 −26 tests/unit/cmk/test_base.py
  102. +2 −2 tests/unit/cmk/utils/rulesets/test_tuple_rulesets.py
  103. +1 −1 tests/unit/cmk/utils/test_man_pages.py
  104. +3 −1 tests/unit/cmk/utils/test_werks.py
  105. +2 −2 tests/unit/conftest.py
@@ -280,7 +280,7 @@ setversion:
sed -ri 's/^(VERSION[[:space:]]*:?= *).*/\1'"$(NEW_VERSION)/" defines.make ; \
sed -i 's/^AC_INIT.*/AC_INIT([MK Livestatus], ['"$(NEW_VERSION)"'], [mk@mathias-kettner.de])/' configure.ac ; \
sed -i 's/^VERSION=".*/VERSION="$(NEW_VERSION)"/' bin/mkbackup ; \
sed -i 's/^__version__ = ".*"$$/__version__ = "$(NEW_VERSION)"/' cmk/__init__.py bin/mkbench bin/livedump; \
sed -i 's/^__version__ = ".*"$$/__version__ = "$(NEW_VERSION)"/' cmk/utils/version.py bin/mkbench bin/livedump; \
sed -i 's/^VERSION=.*/VERSION='"$(NEW_VERSION)"'/' scripts/setup.sh ; \
$(MAKE) -C agents NEW_VERSION=$(NEW_VERSION) setversion
$(MAKE) -C docker NEW_VERSION=$(NEW_VERSION) setversion
@@ -58,7 +58,6 @@
)

PYTHON3_PATHS=(
__init__.py
gui
utils
ec
@@ -103,8 +102,8 @@
done

# Restore site version after .f12
sudo sed -i "s|^__version__.*$|__version__ = \"$CMK_VERSION\"|g" $ROOT/lib/python/cmk/__init__.py
sudo sed -i "s|^__version__.*$|__version__ = \"$CMK_VERSION\"|g" $ROOT/lib/python3/cmk/__init__.py
sudo sed -i "s|^__version__.*$|__version__ = \"$CMK_VERSION\"|g" $ROOT/lib/python/cmk/utils/version.py
sudo sed -i "s|^__version__.*$|__version__ = \"$CMK_VERSION\"|g" $ROOT/lib/python3/cmk/utils/version.py

# Also deploy all other directories of same type
if [ ${ALL_EDITIONS:-1} != 0 ]; then
@@ -3,72 +3,13 @@
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
"""Check_MK's library for code used by different components of Check_MK.

This library is currently handled as internal module of Check_MK and
does not offer stable APIs. The code may change at any time."""

__version__ = "1.7.0i1"

import os
import sys
from typing import Text # pylint: disable=unused-import
import six

import cmk.utils.paths
from cmk.utils.encoding import ensure_unicode
from cmk.utils.exceptions import MKGeneralException
from cmk.utils.i18n import _

# Explicitly check for Python 3 (which is understood by mypy)
if sys.version_info[0] >= 3:
from pathlib import Path # pylint: disable=import-error
else:
from pathlib2 import Path


def omd_version():
# type: () -> Text
version_link = Path(cmk.utils.paths.omd_root).joinpath("version")
return ensure_unicode(version_link.resolve().name)


def omd_site():
# type: () -> str
try:
return os.environ["OMD_SITE"]
except KeyError:
raise MKGeneralException(
_("OMD_SITE environment variable not set. You can "
"only execute this in an OMD site."))


def edition_short():
# type: () -> Text
"""Can currently either return \"cre\" or \"cee\"."""
parts = omd_version().split(".")
if parts[-1] == "demo":
return six.text_type(parts[-2])

return six.text_type(parts[-1])


def is_enterprise_edition():
# type: () -> bool
return edition_short() == "cee"


def is_raw_edition():
# type: () -> bool
return edition_short() == "cre"


def is_managed_edition():
# type: () -> bool
return edition_short() == "cme"


def is_demo():
# type: () -> bool
parts = omd_version().split(".")
return parts[-1] == "demo"
#
# This file (cmk.__init__.py) is only kept to make
# our dev tools (pylint & co) happy.
# It will not be deployed, as cmk is supposed to be a
# namespace that can be shadowed/extended using the local/
# hierarchy.
#
# This file must not contain any code.
#
@@ -18,7 +18,7 @@

import six

import cmk
import cmk.utils.version as cmk_version
import cmk.utils.defines as defines
import cmk.utils.tty as tty
from cmk.utils.exceptions import MKGeneralException, MKTimeout
@@ -45,7 +45,7 @@
)
from cmk.utils.type_defs import HostName, HostAddress, ServiceName # pylint: disable=unused-import

if not cmk.is_raw_edition():
if not cmk_version.is_raw_edition():
import cmk.base.cee.keepalive as keepalive # pylint: disable=no-name-in-module
import cmk.base.cee.inline_snmp as inline_snmp # pylint: disable=no-name-in-module
else:
@@ -82,7 +82,7 @@
def do_check(hostname, ipaddress, only_check_plugin_names=None):
# type: (HostName, Optional[HostAddress], Optional[List[CheckPluginName]]) -> Tuple[int, List[ServiceDetails], List[ServiceAdditionalDetails], List[Text]]
cpu_tracking.start("busy")
console.verbose("Check_MK version %s\n", six.ensure_str(cmk.__version__))
console.verbose("Check_MK version %s\n", six.ensure_str(cmk_version.__version__))

config_cache = config.get_config_cache()
host_config = config_cache.get_host_config(hostname)
@@ -32,7 +32,7 @@

import six

import cmk
import cmk.utils.version as cmk_version
import cmk.utils.debug
import cmk.utils.paths
from cmk.utils.regex import regex
@@ -2567,7 +2567,7 @@ def agent_target_version(self):
if spec == "ignore":
return None
if spec == "site":
return cmk.__version__
return cmk_version.__version__
if isinstance(spec, str):
# Compatibility to old value specification format (a single version string)
return spec
@@ -3111,7 +3111,7 @@ def get_host_config(self, hostname):
if host_config:
return host_config

config_class = HostConfig if cmk.is_raw_edition() else CEEHostConfig
config_class = HostConfig if cmk_version.is_raw_edition() else CEEHostConfig
host_config = self._host_configs[hostname] = config_class(self, hostname)
return host_config

@@ -3191,7 +3191,7 @@ def _tag_list_to_tag_groups(self, tag_to_group_map, tag_list):
'agent': 'cmk-agent',
'criticality': 'prod',
'snmp_ds': 'no-snmp',
'site': cmk.omd_site(),
'site': cmk_version.omd_site(),
'address_family': 'ip-v4-only',
} # type: Tags

@@ -3235,7 +3235,7 @@ def tags_of_host(self, hostname):
'agent': 'cmk-agent',
'criticality': 'prod',
'snmp_ds': 'no-snmp',
'site': cmk.omd_site(),
'site': cmk_version.omd_site(),
'address_family': 'ip-v4-only',
}

@@ -3643,7 +3643,7 @@ def get_config_cache():
# type: () -> ConfigCache
config_cache = _config_cache.get_dict("config_cache")
if not config_cache:
cache_class = ConfigCache if cmk.is_raw_edition() else CEEConfigCache
cache_class = ConfigCache if cmk_version.is_raw_edition() else CEEConfigCache
config_cache["cache"] = cache_class()
return config_cache["cache"]

@@ -13,6 +13,7 @@
)
import six

import cmk.utils.version as cmk_version
import cmk.utils.debug
import cmk.utils.paths
import cmk.utils.tty as tty
@@ -468,7 +469,7 @@ def get_host_attributes(hostname, config_cache):
if actions:
attrs["_ACTIONS"] = ",".join(actions)

if cmk.is_managed_edition():
if cmk_version.is_managed_edition():
attrs["_CUSTOMER"] = config.current_customer # type: ignore[attr-defined]

return attrs
@@ -7,7 +7,7 @@
from typing import cast, Any, Callable # pylint: disable=unused-import
import six

import cmk
import cmk.utils.version as cmk_version
import cmk.utils.debug
import cmk.utils.defines as defines
from cmk.utils.exceptions import MKGeneralException, MKTimeout
@@ -19,7 +19,7 @@
from cmk.base.check_utils import CheckPluginName # pylint: disable=unused-import
from cmk.utils.type_defs import HostName, ServiceName # pylint: disable=unused-import

if not cmk.is_raw_edition():
if not cmk_version.is_raw_edition():
import cmk.base.cee.keepalive as keepalive # pylint: disable=no-name-in-module
else:
keepalive = None # type: ignore[assignment]
@@ -6,7 +6,7 @@

from typing import Any as _Any, Dict as _Dict, List as _List # pylint: disable=unused-import

import cmk as _cmk
import cmk.utils.version as cmk_version

# Log level of notifications
# 0, 1, 2 -> deprecated (transformed to 20, 20, and 10)
@@ -33,7 +33,7 @@
# "both" - Asynchronous local delivery plus remote forwarding
# False - legacy: sync delivery (and notification_spool_to)
# True - legacy: async delivery (and notification_spool_to)
if _cmk.is_raw_edition():
if cmk_version.is_raw_edition():
notification_spooling = "off"
else:
notification_spooling = "local"
@@ -26,7 +26,7 @@
import six

import livestatus
import cmk
import cmk.utils.version as cmk_version
from cmk.utils.regex import regex
import cmk.utils.debug
import cmk.utils.daemon
@@ -101,7 +101,7 @@ def event_keepalive(event_function,
try:
new_data = b""
new_data = os.read(0, 32768)
except IOError as e:
except IOError:
new_data = b""
except Exception as e:
if cmk.utils.debug.enabled():
@@ -305,7 +305,7 @@ def complete_raw_context(raw_context, with_dump):

raw_context.setdefault("MONITORING_HOST", socket.gethostname())
raw_context.setdefault("OMD_ROOT", cmk.utils.paths.omd_root)
raw_context.setdefault("OMD_SITE", cmk.omd_site())
raw_context.setdefault("OMD_SITE", cmk_version.omd_site())

# The Check_MK Micro Core sends the MICROTIME and no other time stamps. We add
# a few Nagios-like variants in order to be compatible
@@ -469,7 +469,7 @@ def event_match_site(rule, context):
required_site_ids = rule["match_site"]

# Fallback to local site ID in case there is none in the context
site_id = context.get("OMD_SITE", cmk.omd_site())
site_id = context.get("OMD_SITE", cmk_version.omd_site())

if site_id not in required_site_ids:
return "The site '%s' is not in the required sites list: %s" % \
@@ -11,7 +11,6 @@
import os
from typing import Set, Tuple, Optional, List, Dict, Text # pylint: disable=unused-import

import cmk
import cmk.utils.misc
import cmk.utils.paths
import cmk.utils.store as store
@@ -10,7 +10,7 @@

import six

import cmk
import cmk.utils.version as cmk_version
import cmk.utils.tty as tty
import cmk.utils.paths
import cmk.utils.log as log
@@ -1686,7 +1686,7 @@ def mode_version():
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
""", cmk.__version__, six.ensure_str(cmk.edition_short().upper()))
""", cmk_version.__version__, six.ensure_str(cmk_version.edition_short().upper()))


modes.register(
@@ -9,7 +9,6 @@
from logging import Logger # pylint: disable=unused-import
from typing import Any, Dict, Set # pylint: disable=unused-import

import cmk
import cmk.utils.debug
import cmk.utils.defines
from cmk.utils.log import VERBOSE
@@ -30,7 +30,7 @@
from types import FrameType # pylint: disable=unused-import
from typing import Any, AnyStr, Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union # pylint: disable=unused-import

import cmk
import cmk.utils.version as cmk_version
import cmk.utils.daemon
import cmk.utils.defines
import cmk.utils.log as log
@@ -2330,7 +2330,7 @@ def event_rule_determine_match_priority(self, rule, event, match_priority):
return True

def event_rule_matches_site(self, rule, event):
return "match_site" not in rule or cmk.omd_site() in rule["match_site"]
return "match_site" not in rule or cmk_version.omd_site() in rule["match_site"]

def event_rule_matches_host(self, rule, event):
if match(rule.get("match_host"), event["host"], complete=True) is False:
@@ -3914,7 +3914,7 @@ def main():
# type: () -> None
os.unsetenv("LANG")
logger = getLogger("cmk.mkeventd")
settings = create_settings(cmk.__version__, Path(cmk.utils.paths.omd_root),
settings = create_settings(cmk_version.__version__, Path(cmk.utils.paths.omd_root),
Path(cmk.utils.paths.default_config_dir), sys.argv)

pid_path = None
@@ -3927,7 +3927,7 @@ def main():
log.open_log(str(settings.paths.log_file.value))

logger.info("-" * 65)
logger.info("mkeventd version %s starting", cmk.__version__)
logger.info("mkeventd version %s starting", cmk_version.__version__)

slave_status = default_slave_status_master()
config = load_configuration(settings, logger, slave_status)
@@ -231,8 +231,8 @@ def settings(version, omd_root, default_config_dir, argv):


if __name__ == "__main__":
import cmk
import cmk.utils.version as cmk_version
import cmk.utils.paths
print(
settings(str(cmk.__version__), Path(cmk.utils.paths.omd_root),
settings(str(cmk_version.__version__), Path(cmk.utils.paths.omd_root),
Path(cmk.utils.paths.default_config_dir), sys.argv))
@@ -8,6 +8,7 @@
import time
import os

import cmk.utils.version as cmk_version
import cmk.utils.defines as defines
import cmk.utils.paths
import cmk.utils.store as store
@@ -131,7 +132,7 @@ def get_av_display_options(what):
("service_groups", _("By Service group")),
]

if not cmk.is_raw_edition():
if not cmk_version.is_raw_edition():
ruleset_search_url = html.makeuri_contextless(
[
("filled_in", "search"),
@@ -27,15 +27,14 @@

import six

from cmk.gui.i18n import _
import cmk
import cmk.utils.log
from cmk.utils.log import VERBOSE
import cmk.utils.daemon as daemon
import cmk.utils.store as store
from cmk.utils.exceptions import MKGeneralException, MKTerminate

import cmk.gui.log
from cmk.gui.i18n import _

JobId = str
JobParameters = Dict[str, Any]

0 comments on commit f5201a9

Please sign in to comment.
You can’t perform that action at this time.