Skip to content

Commit

Permalink
Merge pull request #1 from plesk/fix-leapp-config-none-parts
Browse files Browse the repository at this point in the history
Make sure packageinfo object in leapp json configuration has out_packageset/in_packageset before do anything
  • Loading branch information
kpushkaryov authored Jan 16, 2024
2 parents 6f16700 + f7d9ded commit 6aac72d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
16 changes: 14 additions & 2 deletions pleskdistup/common/src/leapp_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)
32 changes: 30 additions & 2 deletions pleskdistup/common/tests/leapp_configs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,15 @@ class SetPackageRepositoryTests(unittest.TestCase):
INITIAL_JSON = {
"packageinfo": [
{
"id": "1",
"in_packageset": {
"package": [
{
"name": "some",
"repository": "some-repo",
},
],
"set_id": "1",
},
"out_packageset": {
"package": [
Expand All @@ -421,16 +423,19 @@ class SetPackageRepositoryTests(unittest.TestCase):
"repository": "other-repo",
},
],
"set_id": "2",
},
},
{
"id": "2",
"in_packageset": {
"package": [
{
"name": "other",
"repository": "some-repo",
},
],
"set_id": "3",
},
"out_packageset": {
"package": [
Expand All @@ -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,
},
]
}

Expand Down Expand Up @@ -479,6 +498,7 @@ class SetPackageActionTests(unittest.TestCase):
INITIAL_JSON = {
"packageinfo": [
{
"id": "1",
"action": 1,
"in_packageset": {
"package": [
Expand All @@ -487,9 +507,11 @@ class SetPackageActionTests(unittest.TestCase):
"repository": "some-repo",
},
],
"set_id": "1",
},
},
{
"id": "2",
"action": 4,
"in_packageset": {
"package": [
Expand All @@ -498,8 +520,14 @@ class SetPackageActionTests(unittest.TestCase):
"repository": "some-repo",
},
],
"set_id": "2",
},
}
},
{
"id": "3",
"action": 4,
"in_packageset": None,
},
]
}

Expand Down

0 comments on commit 6aac72d

Please sign in to comment.