diff --git a/pleskdistup/common/src/leapp_configs.py b/pleskdistup/common/src/leapp_configs.py index 195fff8..4d9f1c6 100644 --- a/pleskdistup/common/src/leapp_configs.py +++ b/pleskdistup/common/src/leapp_configs.py @@ -238,13 +238,19 @@ def add_repositories_mapping(repofiles: typing.List[str], ignore: typing.List = def set_package_repository(package: str, repository: str, leapp_pkgs_conf_path: str = LEAPP_PKGS_CONF_PATH) -> None: pkg_mapping = None + log.debug(f"Reconfigure mapping for package '{package}' to repository '{repository}'") with open(leapp_pkgs_conf_path, "r") as pkg_mapping_file: pkg_mapping = json.load(pkg_mapping_file) for info in pkg_mapping["packageinfo"]: + if not info["out_packageset"] or not info["out_packageset"]["package"]: + continue + for outpkg in info["out_packageset"]["package"]: if outpkg["name"] == package: + log.debug(f"Change '{package}' package repository in info '{info['id']}' -> out packageset '{info['out_packageset']['set_id']}'") outpkg["repository"] = repository + log.debug(f"Write json into '{leapp_pkgs_conf_path}'") files.rewrite_json_file(leapp_pkgs_conf_path, pkg_mapping) @@ -261,13 +267,19 @@ class LeappActionType(IntEnum): RENAMED = 7 -def set_package_action(package: str, type: LeappActionType, leapp_pkgs_conf_path: str = LEAPP_PKGS_CONF_PATH): +def set_package_action(package: str, actionType: LeappActionType, leapp_pkgs_conf_path: str = LEAPP_PKGS_CONF_PATH): pkg_mapping = None + log.debug(f"Reconfigure action for package '{package}' to type '{actionType}'") with open(leapp_pkgs_conf_path, "r") as pkg_mapping_file: pkg_mapping = json.load(pkg_mapping_file) for info in pkg_mapping["packageinfo"]: + if not info["in_packageset"] or not info["in_packageset"]["package"]: + continue + for inpackage in info["in_packageset"]["package"]: if inpackage["name"] == package: - info["action"] = type + log.debug(f"Change '{package}' package action in info '{info['id']}' -> out packageset '{info['in_packageset']['set_id']}'") + info["action"] = actionType + log.debug(f"Write json into '{leapp_pkgs_conf_path}'") files.rewrite_json_file(leapp_pkgs_conf_path, pkg_mapping) diff --git a/pleskdistup/common/tests/leapp_configs_tests.py b/pleskdistup/common/tests/leapp_configs_tests.py index 9948ef9..b4321f3 100644 --- a/pleskdistup/common/tests/leapp_configs_tests.py +++ b/pleskdistup/common/tests/leapp_configs_tests.py @@ -406,6 +406,7 @@ class SetPackageRepositoryTests(unittest.TestCase): INITIAL_JSON = { "packageinfo": [ { + "id": "1", "in_packageset": { "package": [ { @@ -413,6 +414,7 @@ class SetPackageRepositoryTests(unittest.TestCase): "repository": "some-repo", }, ], + "set_id": "1", }, "out_packageset": { "package": [ @@ -421,9 +423,11 @@ class SetPackageRepositoryTests(unittest.TestCase): "repository": "other-repo", }, ], + "set_id": "2", }, }, { + "id": "2", "in_packageset": { "package": [ { @@ -431,6 +435,7 @@ class SetPackageRepositoryTests(unittest.TestCase): "repository": "some-repo", }, ], + "set_id": "3", }, "out_packageset": { "package": [ @@ -439,8 +444,22 @@ class SetPackageRepositoryTests(unittest.TestCase): "repository": "other-repo", }, ], + "set_id": "4", }, - } + }, + { + "id": "3", + "in_packageset": { + "package": [ + { + "name": "empty", + "repository": "no-outpout-repo", + }, + ], + "set_id": "5", + }, + "out_packageset": None, + }, ] } @@ -479,6 +498,7 @@ class SetPackageActionTests(unittest.TestCase): INITIAL_JSON = { "packageinfo": [ { + "id": "1", "action": 1, "in_packageset": { "package": [ @@ -487,9 +507,11 @@ class SetPackageActionTests(unittest.TestCase): "repository": "some-repo", }, ], + "set_id": "1", }, }, { + "id": "2", "action": 4, "in_packageset": { "package": [ @@ -498,8 +520,14 @@ class SetPackageActionTests(unittest.TestCase): "repository": "some-repo", }, ], + "set_id": "2", }, - } + }, + { + "id": "3", + "action": 4, + "in_packageset": None, + }, ] }