Skip to content

Commit

Permalink
Make sure packageinfo object in leapp json configuration has out_pack…
Browse files Browse the repository at this point in the history
…ageset/in_packageset before do anything
  • Loading branch information
Mikhail Sandakov committed Dec 28, 2023
1 parent 8dedcfa commit 2f3f3d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 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("Reconfigure mapping for package '{}' to repository '{}'".format(package, 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("Change '{}' package repository in info '{}' -> out packageset '{}'".format(package, info["id"], info["out_packageset"]["set_id"]))
outpkg["repository"] = repository

log.debug("Write json into '{}'".format(leapp_pkgs_conf_path))
files.rewrite_json_file(leapp_pkgs_conf_path, pkg_mapping)


Expand All @@ -263,11 +269,17 @@ class LeappActionType(IntEnum):

def set_package_action(package: str, type: LeappActionType, leapp_pkgs_conf_path: str = LEAPP_PKGS_CONF_PATH):
pkg_mapping = None
log.debug("Reconfigure action for package '{}' to type '{}'".format(package, type))
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:
log.debug("Change '{}' package action in info '{}' -> out packageset '{}'".format(package, info["id"], info["in_packageset"]["set_id"]))
info["action"] = type

log.debug("Write json into '{}'".format(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 2f3f3d9

Please sign in to comment.