dnfjson: detect/error if no repositories are defined
This commit adds an error message if no repositories are defined in the dnfjson query. We had the issue in https://github.com/osbuild/bootc-image-builder/issues/922 that in a RHEL bootc-container no repositories are defined. Here the error is quite confusing, as it complains about error marking packages which is technically correct but hides the root of the problem. With this detect we can construct a more useful error message in the higher layers.
This commit is contained in:
parent
6c961552ce
commit
d068c6d91f
5 changed files with 57 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ import os.path
|
|||
import sys
|
||||
import tempfile
|
||||
|
||||
from osbuild.solver import GPGKeyReadError, MarkingError, DepsolveError, RepoError, InvalidRequestError
|
||||
from osbuild.solver import GPGKeyReadError, MarkingError, DepsolveError, NoReposError, RepoError, InvalidRequestError
|
||||
|
||||
# Load the solver configuration
|
||||
config = {"use_dnf5": False}
|
||||
|
|
@ -77,6 +77,11 @@ def solve(request, cache_dir):
|
|||
"kind": "RepoError",
|
||||
"reason": f"There was a problem reading a repository: {e}"
|
||||
}
|
||||
except NoReposError as e:
|
||||
return None, {
|
||||
"kind": "NoReposError",
|
||||
"reason": f"There was a problem finding repositories: {e}"
|
||||
}
|
||||
except MarkingError as e:
|
||||
printe("error install_specs")
|
||||
return None, {
|
||||
|
|
|
|||
|
|
@ -1865,3 +1865,28 @@ def test_depsolve_result_api(tmp_path, repo_servers):
|
|||
"data",
|
||||
"path",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dnf_config, detect_fn", [
|
||||
({}, assert_dnf),
|
||||
({"use_dnf5": False}, assert_dnf),
|
||||
({"use_dnf5": True}, assert_dnf5),
|
||||
], ids=["no-config", "dnf4", "dnf5"])
|
||||
def test_depsolve_no_repos(tmp_path, dnf_config, detect_fn):
|
||||
try:
|
||||
detect_fn()
|
||||
except RuntimeError as e:
|
||||
pytest.skip(str(e))
|
||||
|
||||
transactions = [
|
||||
{
|
||||
"package-specs": [
|
||||
"filesystem",
|
||||
"pkg-with-no-deps"
|
||||
],
|
||||
},
|
||||
]
|
||||
res, exit_code = depsolve(transactions, tmp_path.as_posix(), dnf_config, root_dir=tmp_path.as_posix())
|
||||
assert exit_code == 1
|
||||
assert res["kind"] == "NoReposError"
|
||||
assert "There are no enabled repositories" in res["reason"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue