From 8d88081a5ec08936ac42fa3f0745189536aa8b6f Mon Sep 17 00:00:00 2001 From: Moritz Kiemer Date: Tue, 7 Jan 2025 14:44:51 +0100 Subject: [PATCH] 17515 FIX Improper warning about MKPs during upgrade SUP-21652 Change-Id: I2bc1c3708f05699dbc503351420a5461f188f70e --- .werks/17515.md | 16 ++++++++++++++ .../pre_actions/agent_based_plugins.py | 19 ++++++++++++---- .../plugins/pre_actions/ui_extensions.py | 19 ++++++++++++---- .../plugins/pre_actions/utils.py | 22 ++++++++++++++++++- 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 .werks/17515.md diff --git a/.werks/17515.md b/.werks/17515.md new file mode 100644 index 00000000000..08880039f15 --- /dev/null +++ b/.werks/17515.md @@ -0,0 +1,16 @@ +[//]: # (werk v2) +# Improper warning about MKPs during upgrade + +key | value +---------- | --- +date | 2025-01-07T14:38:20+00:00 +version | 2.3.0p25 +class | fix +edition | cre +component | checks +level | 1 +compatible | yes + +The upgrade process will issue warnings in case MKPs are enabled that will stop working after the upgrade. +On the other hand, MKPs that are marked inapplicable for that version will be disabled anyway. +With this change we no longer issue warnings for those MKPs, as there is no user action required. diff --git a/cmk/update_config/plugins/pre_actions/agent_based_plugins.py b/cmk/update_config/plugins/pre_actions/agent_based_plugins.py index 7ddc346b7ed..f1c18684b48 100644 --- a/cmk/update_config/plugins/pre_actions/agent_based_plugins.py +++ b/cmk/update_config/plugins/pre_actions/agent_based_plugins.py @@ -20,6 +20,7 @@ error_message_incomp_local_file, get_installer_and_package_map, get_path_config, + is_applicable_mkp, PACKAGE_STORE, ) from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction @@ -43,7 +44,8 @@ def _disable_failure_and_reload_plugins( return False package_store = PACKAGE_STORE installer, package_map = get_installer_and_package_map(path_config) - disabled_packages: set[PackageID] = set() + dealt_with_packages: set[PackageID] = set() + for module_name, error in load_plugins_with_exceptions("cmk.base.plugins.agent_based"): path = Path(traceback.extract_tb(error.__traceback__)[-1].filename) manifest = package_map.get(path.resolve()) @@ -54,8 +56,17 @@ def _disable_failure_and_reload_plugins( continue raise MKUserError(None, "incompatible local file") - if manifest.id in disabled_packages: - continue # already dealt with + if manifest.id in dealt_with_packages: + continue + + if not is_applicable_mkp(manifest): + dealt_with_packages.add(manifest.id) + logger.info( + "[%s %s]: Ignoring problems (MKP will be disabled on target version)", + manifest.name, + manifest.version, + ) + continue if disable_incomp_mkp( logger, @@ -68,7 +79,7 @@ def _disable_failure_and_reload_plugins( path_config, path, ): - disabled_packages.add(manifest.id) + dealt_with_packages.add(manifest.id) return True raise MKUserError(None, "incompatible local file") diff --git a/cmk/update_config/plugins/pre_actions/ui_extensions.py b/cmk/update_config/plugins/pre_actions/ui_extensions.py index 64a9522c4cd..002ba31a019 100644 --- a/cmk/update_config/plugins/pre_actions/ui_extensions.py +++ b/cmk/update_config/plugins/pre_actions/ui_extensions.py @@ -23,6 +23,7 @@ get_installer_and_package_map, get_path_config, GUI_PLUGINS_PREACTION_SORT_INDEX, + is_applicable_mkp, PACKAGE_STORE, ) from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction @@ -47,7 +48,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: return package_store = PACKAGE_STORE installer, package_map = get_installer_and_package_map(path_config) - disabled_packages: set[PackageID] = set() + dealt_with_packages: set[PackageID] = set() + for path, _gui_part, module_name, error in get_failed_plugins(): manifest = _get_package_manifest(package_map, str(path)) # unpackaged files @@ -57,8 +59,17 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: continue raise MKUserError(None, "incompatible local file") - if manifest.id in disabled_packages: - continue # already dealt with + if manifest.id in dealt_with_packages: + continue + + if not is_applicable_mkp(manifest): + dealt_with_packages.add(manifest.id) + logger.info( + "[%s %s]: Ignoring problems (MKP will be disabled on target version)", + manifest.name, + manifest.version, + ) + continue if disable_incomp_mkp( logger, @@ -71,7 +82,7 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None: path_config, path, ): - disabled_packages.add(manifest.id) + dealt_with_packages.add(manifest.id) remove_failed_plugin(path) continue diff --git a/cmk/update_config/plugins/pre_actions/utils.py b/cmk/update_config/plugins/pre_actions/utils.py index 1c1eb7f2ed6..f5692a77059 100644 --- a/cmk/update_config/plugins/pre_actions/utils.py +++ b/cmk/update_config/plugins/pre_actions/utils.py @@ -11,7 +11,7 @@ from termios import tcflush, TCIFLUSH from typing import Final -from cmk.utils import paths +from cmk.utils import paths, version from cmk.utils.setup_search_index import request_index_rebuild from cmk.utils.visuals import invalidate_visuals_cache @@ -187,3 +187,23 @@ def get_installer_and_package_map( for file in files } return installer, installed_files_package_map + + +def is_applicable_mkp(manifest: Manifest) -> bool: + """Try to find out if this MKP is applicable to the version we upgrade to. + Assume yes if we can't find out. + """ + target_version = version.Version.from_str(version.__version__) + try: + lower_bound_ok = target_version >= version.Version.from_str(manifest.version_min_required) + except ValueError: + lower_bound_ok = True + + try: + upper_bound_ok = manifest.version_usable_until is None or ( + version.Version.from_str(manifest.version_usable_until) > target_version + ) + except ValueError: + upper_bound_ok = True + + return lower_bound_ok and upper_bound_ok