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 476e963 commit 2ab201e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 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.5.0b1
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.
9 changes: 9 additions & 0 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 @@
disable_incomp_mkp,
get_installer_and_package_map,
get_path_config,
is_applicable_mkp,
PACKAGE_STORE,
Resume,
)
Expand Down Expand Up @@ -60,6 +61,14 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
raise MKUserError(None, "decommissioned file(s)")

for manifest, paths in grouped_files.items():
if not is_applicable_mkp(manifest):
logger.info(
"[%s %s]: Ignoring problems (MKP will be disabled on target version)",
manifest.name,
manifest.version,
)
continue

_log_error_message_obsolete_files(logger, paths)
logger.error(
f"The above file(s) are part of the extension package {manifest.name} {manifest.version}."
Expand Down
21 changes: 16 additions & 5 deletions cmk/update_config/plugins/pre_actions/ui_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_installer_and_package_map,
get_path_config,
GUI_PLUGINS_PREACTION_SORT_INDEX,
is_applicable_mkp,
PACKAGE_STORE,
Resume,
)
Expand All @@ -49,8 +50,9 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
if path_config is None:
return
installer, package_map = get_installer_and_package_map(path_config)
disabled_packages: set[PackageID] = set()
for path, _gui_part, module_name, error in get_failed_plugins():
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
if manifest is None:
Expand All @@ -59,14 +61,23 @@ 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

logger.error(error_message_incomp_package(path, manifest.id, error))
if disable_incomp_mkp(
conflict_mode, manifest.id, installer, PACKAGE_STORE, path_config
):
disabled_packages.add(manifest.id)
dealt_with_packages.add(manifest.id)
remove_failed_plugin(path)
continue

Expand Down
22 changes: 22 additions & 0 deletions cmk/update_config/plugins/pre_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from termios import tcflush, TCIFLUSH
from typing import Final

from cmk.ccc import version

from cmk.utils import paths
from cmk.utils.setup_search_index import request_index_rebuild
from cmk.utils.visuals import invalidate_visuals_cache
Expand Down Expand Up @@ -198,3 +200,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 2ab201e

Please sign in to comment.