Skip to content

Commit

Permalink
mkp-tool: reduce paths on path config
Browse files Browse the repository at this point in the history
Change-Id: I444b4faaa9616df136d6d9e71c241125ce098b01
  • Loading branch information
mo-ki committed Dec 13, 2023
1 parent 23be2f2 commit d2d9abd
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 149 deletions.
11 changes: 7 additions & 4 deletions bin/mkp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ from cmk.mkp_tool import (
make_post_package_change_actions,
PackageOperationCallbacks,
PackagePart,
PackageStore,
PathConfig,
reload_apache,
)
Expand All @@ -43,16 +44,18 @@ _PATH_CONFIG = PathConfig(
mib_dir=cmk.utils.paths.local_mib_dir,
mkp_rule_pack_dir=ec.mkp_rule_pack_dir(),
notifications_dir=cmk.utils.paths.local_notifications_dir,
packages_enabled_dir=cmk.utils.paths.local_enabled_packages_dir,
packages_local_dir=cmk.utils.paths.local_optional_packages_dir,
packages_shipped_dir=cmk.utils.paths.optional_packages_dir,
pnp_templates_dir=cmk.utils.paths.local_pnp_templates_dir,
tmp_dir=cmk.utils.paths.tmp_dir,
manifests_dir=cmk.utils.paths.tmp_dir,
web_dir=cmk.utils.paths.local_web_dir,
)


_SITE_CONTEXT: Final = cli.SiteContext(
PackageStore(
enabled_dir=cmk.utils.paths.local_enabled_packages_dir,
local_dir=cmk.utils.paths.local_optional_packages_dir,
shipped_dir=cmk.utils.paths.optional_packages_dir,
),
callbacks={
PackagePart.EC_RULE_PACKS: PackageOperationCallbacks(
install=ec.install_packaged_rule_packs,
Expand Down
10 changes: 6 additions & 4 deletions cmk/gui/watolib/activate_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2599,13 +2599,15 @@ def _execute_post_config_sync_actions(site_id: SiteId) -> None:
mib_dir=paths.local_mib_dir,
mkp_rule_pack_dir=ec.mkp_rule_pack_dir(),
notifications_dir=paths.local_notifications_dir,
packages_enabled_dir=paths.local_enabled_packages_dir,
packages_local_dir=paths.local_optional_packages_dir,
packages_shipped_dir=paths.optional_packages_dir,
pnp_templates_dir=paths.local_pnp_templates_dir,
tmp_dir=paths.tmp_dir,
manifests_dir=paths.tmp_dir,
web_dir=paths.local_web_dir,
),
mkp_tool.PackageStore(
enabled_dir=paths.local_enabled_packages_dir,
local_dir=paths.local_optional_packages_dir,
shipped_dir=paths.optional_packages_dir,
),
{
mkp_tool.PackagePart.EC_RULE_PACKS: mkp_tool.PackageOperationCallbacks(
install=ec.install_packaged_rule_packs,
Expand Down
4 changes: 2 additions & 2 deletions cmk/update_config/plugins/pre_actions/agent_based_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
continue_on_incomp_local_file,
disable_incomp_mkp,
get_installer_and_package_map,
get_package_store,
get_path_config,
PACKAGE_STORE,
)
from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction

Expand All @@ -27,7 +27,7 @@ class PreUpdateAgentBasedPlugins(PreUpdateAction):

def __call__(self, conflict_mode: ConflictMode) -> None:
path_config = get_path_config()
package_store = get_package_store(path_config)
package_store = PACKAGE_STORE
installer, package_map = get_installer_and_package_map(path_config)
disabled_packages: set[PackageID] = set()
for module_name, error in load_plugins_with_exceptions("cmk.base.plugins.agent_based"):
Expand Down
4 changes: 2 additions & 2 deletions cmk/update_config/plugins/pre_actions/ui_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
continue_on_incomp_local_file,
disable_incomp_mkp,
get_installer_and_package_map,
get_package_store,
get_path_config,
PACKAGE_STORE,
)
from cmk.update_config.registry import pre_update_action_registry, PreUpdateAction

Expand All @@ -25,7 +25,7 @@ class PreUpdateUIExtensions(PreUpdateAction):
def __call__(self, conflict_mode: ConflictMode) -> None:
main_modules.load_plugins()
path_config = get_path_config()
package_store = get_package_store(path_config)
package_store = PACKAGE_STORE
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():
Expand Down
16 changes: 6 additions & 10 deletions cmk/update_config/plugins/pre_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ def get_path_config() -> PathConfig:
mib_dir=paths.local_mib_dir,
mkp_rule_pack_dir=ec.mkp_rule_pack_dir(),
notifications_dir=paths.local_notifications_dir,
packages_enabled_dir=paths.local_enabled_packages_dir,
packages_local_dir=paths.local_optional_packages_dir,
packages_shipped_dir=paths.optional_packages_dir,
pnp_templates_dir=paths.local_pnp_templates_dir,
tmp_dir=paths.tmp_dir,
manifests_dir=paths.tmp_dir,
web_dir=paths.local_web_dir,
)

Expand All @@ -69,12 +66,11 @@ def get_path_config() -> PathConfig:
}


def get_package_store(path_config: PathConfig) -> PackageStore:
return PackageStore(
shipped_dir=path_config.packages_shipped_dir,
local_dir=path_config.packages_local_dir,
enabled_dir=path_config.packages_enabled_dir,
)
PACKAGE_STORE = PackageStore(
enabled_dir=paths.local_enabled_packages_dir,
local_dir=paths.local_optional_packages_dir,
shipped_dir=paths.optional_packages_dir,
)


class ConflictMode(enum.StrEnum):
Expand Down
10 changes: 2 additions & 8 deletions packages/cmk-mkp-tool/cmk/mkp_tool/_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class PathConfig:
# other paths
installed_packages_dir: Path
local_root: Path
packages_enabled_dir: Path
packages_local_dir: Path
packages_shipped_dir: Path
tmp_dir: Path
manifests_dir: Path

@classmethod
def from_toml(cls, content: str) -> Self:
Expand All @@ -74,10 +71,7 @@ def from_toml(cls, content: str) -> Self:
web_dir=Path(raw["web_dir"]),
installed_packages_dir=Path(raw["installed_packages_dir"]),
local_root=Path(raw["local_root"]),
packages_enabled_dir=Path(raw["packages_enabled_dir"]),
packages_local_dir=Path(raw["packages_local_dir"]),
packages_shipped_dir=Path(raw["packages_shipped_dir"]),
tmp_dir=Path(raw["tmp_dir"]),
manifests_dir=Path(raw["manifests_dir"]),
)

def get_path(self, part: PackagePart) -> Path:
Expand Down
19 changes: 3 additions & 16 deletions packages/cmk-mkp-tool/cmk/mkp_tool/_unsorted.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,14 @@ def create(
installer: Installer,
manifest: Manifest,
path_config: PathConfig,
package_store: PackageStore,
persisting_function: Callable[[str, bytes], object],
*,
version_packaged: str,
) -> None:
if installer.is_installed(manifest.name):
raise PackageError("Package already exists.")

package_store = PackageStore(
shipped_dir=path_config.packages_shipped_dir,
local_dir=path_config.packages_local_dir,
enabled_dir=path_config.packages_enabled_dir,
)

_raise_for_nonexisting_files(manifest, path_config)
_validate_package_files(manifest, installer)
installer.add_installed_manifest(manifest)
Expand All @@ -243,6 +238,7 @@ def edit(
pacname: PackageName,
new_manifest: Manifest,
path_config: PathConfig,
package_store: PackageStore,
persisting_function: Callable[[str, bytes], object],
*,
version_packaged: str,
Expand All @@ -254,11 +250,6 @@ def edit(
if pacname != new_manifest.name:
if installer.is_installed(new_manifest.name):
raise PackageError("Cannot rename package: a package with that name already exists.")
package_store = PackageStore(
shipped_dir=path_config.packages_shipped_dir,
local_dir=path_config.packages_local_dir,
enabled_dir=path_config.packages_enabled_dir,
)

_raise_for_nonexisting_files(new_manifest, path_config)
_validate_package_files(new_manifest, installer)
Expand Down Expand Up @@ -595,16 +586,12 @@ def id_to_mkp(
def update_active_packages(
installer: Installer,
path_config: PathConfig,
package_store: PackageStore,
callbacks: Mapping[PackagePart, PackageOperationCallbacks],
site_version: str,
parse_version: Callable[[str], ComparableVersion],
) -> tuple[Sequence[Manifest], Sequence[Manifest]]:
"""Update which of the enabled packages are actually active (installed)"""
package_store = PackageStore(
shipped_dir=path_config.packages_shipped_dir,
local_dir=path_config.packages_local_dir,
enabled_dir=path_config.packages_enabled_dir,
)
# order matters here (deinstall, then install)!
return (
_deinstall_inapplicable_active_packages(
Expand Down
Loading

0 comments on commit d2d9abd

Please sign in to comment.