Skip to content

Commit

Permalink
cmk-update-config: offer disabling MKPs
Browse files Browse the repository at this point in the history
Previously, users were only warned about files decommissioned by Werk
17201. For files contained in an extension package, we can offer
disabling the MKP, just like we do in the `UI extensions` plugin.

Users are still advised about unpackaged files with the continue option
(as they were before).

CMK-19767

Change-Id: Ie7f560ca21abbe0144ca5c04bddd12ef624d85c4
  • Loading branch information
SoloJacobs committed Jan 8, 2025
1 parent 73a0899 commit 28214b7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
42 changes: 31 additions & 11 deletions cmk/update_config/plugins/pre_actions/agent_based_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
AGENT_BASED_PLUGINS_PREACTION_SORT_INDEX,
ConflictMode,
continue_per_users_choice,
disable_incomp_mkp,
get_installer_and_package_map,
get_path_config,
PACKAGE_STORE,
)
from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction

Expand All @@ -37,20 +39,34 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
# In this case we have no mkp plugins available so bail out early
if path_config is None:
return
_installer, package_map = get_installer_and_package_map(path_config)
inactive_files = self._get_files()
if inactive_files:
for path in inactive_files:
package_id = package_map.get(path.resolve())
logger.error(_error_message_obsolete_file(path, package_id))
installer, package_map = get_installer_and_package_map(path_config)
# group the local_agent_based_plugins_dir files by package
grouped_files: dict[PackageID, list[Path]] = {}
inactive_files_not_in_package = []
for path in self._get_files():
if (package_id := package_map.get(path.resolve())) is not None:
grouped_files.setdefault(package_id, []).append(path)
else:
inactive_files_not_in_package.append(path)

if inactive_files_not_in_package:
_log_error_message_obsolete_files(logger, inactive_files_not_in_package)
logger.error(
"The file(s) residing in `local/lib/check_mk/plugins/agent_based` will no longer be loaded in Checkmk 2.4. "
"The above file(s) are not associated with any MKP and can thus not be removed automatically. "
"You must manually remove them in order to suppress future warnings."
)
logger.error("See: %s\n", werk_reference_url(WerkReference.DECOMMISSION_V1_API))
if not _continue_per_users_choice(conflict_mode):
raise MKUserError(None, "decommissioned file(s)")

for package_id, paths in grouped_files.items():
_log_error_message_obsolete_files(logger, paths)
logger.error(
f"The above file(s) are part of the extension package {package_id.name} {package_id.version}."
)
if disable_incomp_mkp(conflict_mode, package_id, installer, PACKAGE_STORE, path_config):
continue
raise MKUserError(None, "incompatible extension package")


def _continue_per_users_choice(conflict_mode: ConflictMode) -> bool:
return continue_per_users_choice(
Expand All @@ -60,9 +76,13 @@ def _continue_per_users_choice(conflict_mode: ConflictMode) -> bool:
)


def _error_message_obsolete_file(path: Path, package_id: PackageID | None) -> str:
hint = "" if package_id is None else f"of package {package_id.name} [{package_id.version}] "
return f"Obsolete file: '{path}' {hint}"
def _log_error_message_obsolete_files(logger: Logger, paths: Sequence[Path]) -> None:
for path in paths:
logger.error(f"Obsolete file: '{path}'")
logger.error(
"The file(s) residing in `local/lib/check_mk/plugins/agent_based` will no longer be loaded in Checkmk 2.4. "
)
logger.error("See: %s", werk_reference_url(WerkReference.DECOMMISSION_V1_API))


pre_update_action_registry.register(
Expand Down
14 changes: 3 additions & 11 deletions cmk/update_config/plugins/pre_actions/ui_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
continue_on_incomp_local_file,
disable_incomp_mkp,
error_message_incomp_local_file,
error_message_incomp_package,
get_installer_and_package_map,
get_path_config,
GUI_PLUGINS_PREACTION_SORT_INDEX,
Expand Down Expand Up @@ -61,17 +62,8 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
if package_id in disabled_packages:
continue # already dealt with

if disable_incomp_mkp(
logger,
conflict_mode,
module_name,
error,
package_id,
installer,
package_store,
path_config,
path,
):
logger.error(error_message_incomp_package(path, package_id, error))
if disable_incomp_mkp(conflict_mode, package_id, installer, package_store, path_config):
disabled_packages.add(package_id)
remove_failed_plugin(path)
continue
Expand Down
6 changes: 0 additions & 6 deletions cmk/update_config/plugins/pre_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import enum
import sys
from collections.abc import Callable, Sequence
from logging import Logger
from pathlib import Path
from termios import tcflush, TCIFLUSH
from typing import Final
Expand Down Expand Up @@ -96,17 +95,12 @@ class ConflictMode(enum.StrEnum):


def disable_incomp_mkp(
logger: Logger,
conflict_mode: ConflictMode,
module_name: str,
error: BaseException,
package_id: PackageID,
installer: Installer,
package_store: PackageStore,
path_config: PathConfig,
path: Path,
) -> bool:
logger.error(error_message_incomp_package(path, package_id, error))
if conflict_mode in (ConflictMode.INSTALL, ConflictMode.KEEP_OLD) or (
conflict_mode is ConflictMode.ASK
and _request_user_input_on_incompatible_file().lower() in USER_INPUT_DISABLE
Expand Down

0 comments on commit 28214b7

Please sign in to comment.