Skip to content

Commit

Permalink
17515 FIX Improper warning about MKPs during upgrade
Browse files Browse the repository at this point in the history
SUP-21652

Change-Id: I2bc1c3708f05699dbc503351420a5461f188f70e
  • Loading branch information
mo-ki committed Jan 10, 2025
1 parent 38d7612 commit 8d88081
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .werks/17515.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 15 additions & 4 deletions cmk/update_config/plugins/pre_actions/agent_based_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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,
Expand All @@ -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")
Expand Down
19 changes: 15 additions & 4 deletions cmk/update_config/plugins/pre_actions/ui_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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

Expand Down
22 changes: 21 additions & 1 deletion cmk/update_config/plugins/pre_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 8d88081

Please sign in to comment.