Skip to content

Commit

Permalink
pass package manifests around
Browse files Browse the repository at this point in the history
We'll need the version info in the next commit.

Change-Id: I878b933b206bd620e32fb9bea50654a3d6af02ee
  • Loading branch information
mo-ki committed Jan 10, 2025
1 parent 33c7cb6 commit 476e963
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
16 changes: 9 additions & 7 deletions cmk/update_config/plugins/pre_actions/agent_based_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cmk.gui.exceptions import MKUserError
from cmk.gui.utils.urls import werk_reference_url, WerkReference

from cmk.mkp_tool import PackageID
from cmk.mkp_tool import Manifest
from cmk.update_config.plugins.pre_actions.utils import (
AGENT_BASED_PLUGINS_PREACTION_SORT_INDEX,
ConflictMode,
Expand Down Expand Up @@ -42,11 +42,11 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
return
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]] = {}
grouped_files: dict[Manifest, 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)
if (manifest := package_map.get(path.resolve())) is not None:
grouped_files.setdefault(manifest, []).append(path)
else:
inactive_files_not_in_package.append(path)

Expand All @@ -59,12 +59,14 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
if _continue_per_users_choice(conflict_mode).is_abort():
raise MKUserError(None, "decommissioned file(s)")

for package_id, paths in grouped_files.items():
for manifest, 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}."
f"The above file(s) are part of the extension package {manifest.name} {manifest.version}."
)
if disable_incomp_mkp(conflict_mode, package_id, installer, PACKAGE_STORE, path_config):
if disable_incomp_mkp(
conflict_mode, manifest.id, installer, PACKAGE_STORE, path_config
):
continue
raise MKUserError(None, "incompatible extension package")

Expand Down
18 changes: 10 additions & 8 deletions cmk/update_config/plugins/pre_actions/ui_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from cmk.gui.graphing import parse_perfometer, perfometer_info
from cmk.gui.utils import get_failed_plugins, remove_failed_plugin

from cmk.mkp_tool import PackageID
from cmk.mkp_tool import Manifest, PackageID
from cmk.update_config.plugins.pre_actions.utils import (
ConflictMode,
continue_per_users_choice,
Expand All @@ -31,7 +31,7 @@
from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction


def _get_package_id(package_map: Mapping[Path, PackageID], rel_path: str) -> PackageID | None:
def _get_package_manifest(package_map: Mapping[Path, Manifest], rel_path: str) -> Manifest | None:
# What a knightmare, somebody please help.
for path, package in package_map.items():
if str(path).endswith(rel_path):
Expand All @@ -51,20 +51,22 @@ def __call__(self, logger: Logger, conflict_mode: ConflictMode) -> None:
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():
package_id = _get_package_id(package_map, str(path))
manifest = _get_package_manifest(package_map, str(path))
# unpackaged files
if package_id is None:
if manifest is None:
logger.error(error_message_incomp_local_file(path, error))
if _continue_on_incomp_local_file(conflict_mode).is_not_abort():
continue
raise MKUserError(None, "incompatible local file")

if package_id in disabled_packages:
if manifest.id in disabled_packages:
continue # already dealt with

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)
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)
remove_failed_plugin(path)
continue

Expand Down
6 changes: 3 additions & 3 deletions cmk/update_config/plugins/pre_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import enum
import sys
from collections.abc import Callable, Sequence
from collections.abc import Callable, Mapping, Sequence
from pathlib import Path
from termios import tcflush, TCIFLUSH
from typing import Final
Expand Down Expand Up @@ -189,10 +189,10 @@ def _disable_per_users_choice(prompt_text: str) -> Resume:

def get_installer_and_package_map(
path_config: PathConfig,
) -> tuple[Installer, dict[Path, PackageID]]:
) -> tuple[Installer, Mapping[Path, Manifest]]:
installer = Installer(paths.installed_packages_dir)
installed_files_package_map = {
Path(path_config.get_path(part)).resolve() / file: manifest.id
Path(path_config.get_path(part)).resolve() / file: manifest
for manifest in installer.get_installed_manifests()
for part, files in manifest.files.items()
for file in files
Expand Down

0 comments on commit 476e963

Please sign in to comment.