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
|
|
@ -40,6 +40,10 @@ class RepoError(SolverException):
|
|||
pass
|
||||
|
||||
|
||||
class NoReposError(SolverException):
|
||||
pass
|
||||
|
||||
|
||||
class MarkingError(SolverException):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,15 @@ from typing import Dict, List
|
|||
import dnf
|
||||
import hawkey
|
||||
|
||||
from osbuild.solver import DepsolveError, MarkingError, RepoError, SolverBase, modify_rootdir_path, read_keys
|
||||
from osbuild.solver import (
|
||||
DepsolveError,
|
||||
MarkingError,
|
||||
NoReposError,
|
||||
RepoError,
|
||||
SolverBase,
|
||||
modify_rootdir_path,
|
||||
read_keys,
|
||||
)
|
||||
from osbuild.util.sbom.dnf import dnf_pkgset_to_sbom_pkgset
|
||||
from osbuild.util.sbom.spdx import sbom_pkgset_to_spdx2_doc
|
||||
|
||||
|
|
@ -92,6 +100,9 @@ class DNF(SolverBase):
|
|||
except dnf.exceptions.Error as e:
|
||||
raise RepoError(e) from e
|
||||
|
||||
if not self.base.repos._any_enabled():
|
||||
raise NoReposError("There are no enabled repositories")
|
||||
|
||||
# enable module resolving
|
||||
self.base_module = dnf.module.module_base.ModuleBase(self.base)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from libdnf5.common import QueryCmp_GLOB as GLOB
|
|||
from osbuild.solver import (
|
||||
DepsolveError,
|
||||
MarkingError,
|
||||
NoReposError,
|
||||
RepoError,
|
||||
SolverBase,
|
||||
modify_rootdir_path,
|
||||
|
|
@ -48,6 +49,12 @@ def _invert(dct):
|
|||
return {v: k for k in dct for v in dct[k]}
|
||||
|
||||
|
||||
def any_repos_enabled(base):
|
||||
"""Return true if any repositories are enabled"""
|
||||
rq = dnf5.repo.RepoQuery(base)
|
||||
return rq.begin() != rq.end()
|
||||
|
||||
|
||||
class DNF5(SolverBase):
|
||||
"""Solver implements package related actions
|
||||
|
||||
|
|
@ -168,6 +175,9 @@ class DNF5(SolverBase):
|
|||
except RuntimeError as e:
|
||||
raise RepoError(e) from e
|
||||
|
||||
if not any_repos_enabled(self.base):
|
||||
raise NoReposError("There are no enabled repositories")
|
||||
|
||||
# Custom license index file path use for SBOM generation
|
||||
self.license_index_path = license_index_path
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue