Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure packageinfo object in leapp json configuration has out_packageset/in_packageset before do anything #1

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
SandakovMM marked this conversation as resolved.
Show resolved Hide resolved
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