From bc79b636bb47491931cf4f5424b803faa3c1f600 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 22 Oct 2018 10:09:19 -0700 Subject: [PATCH] Use matchPackageNames instead of searchNames Some kickstart templates use globbing to match packages, searchNames doesn't support this. Add fallback code to find packages that are just a dep, matching the behavior of yum.install() This fixes things so that it can depsolve package names with globs in them like grub2-efi-*-cdboot, and deps like shim and grub2-efi. Results are still filtered by the version glob, with the highest NEVRA selected for installation. Resolves: rhbz#1641601 --- src/pylorax/api/projects.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/projects.py b/src/pylorax/api/projects.py index a6e64094..0fa1a75c 100644 --- a/src/pylorax/api/projects.py +++ b/src/pylorax/api/projects.py @@ -208,6 +208,29 @@ def filterVersionGlob(pkgs, version): # yum implements __cmd__ using verCMP so this will return the highest matching version return max(matches) +def _findPackageGlob(yb, pkg_name): + """Find the package(s) that match a name glob + + :param yb: yum base object + :type yb: YumBase + :param pkg_name: Name or fileglob of the name to find + :type pkg_name: str + :returns: list of yum package objects or empty list + """ + (exact, globbed, _unmatched) = yb.pkgSack.matchPackageNames([pkg_name]) + pkgs = exact + globbed + if pkgs: + return pkgs + + # Nothing matched, check rpmdb + pkgs = yb.rpmdb.returnPackages(patterns=[pkg_name], ignore_case=False) + if pkgs: + return pkgs + + # Nothing matched, find a matching dep + return yb.returnPackagesByDep(pkg_name) + + def _depsolve(yb, projects, groups): """Find the dependencies for a list of projects and groups @@ -234,7 +257,8 @@ def _depsolve(yb, projects, groups): # yum.install's pattern matches the whole nevra, which can result in -* matching # unexpected packages. So we need to implement our own version globbing. - pkgs = yb.pkgSack.searchNames([name]) + # First get a list of packages, then filter that by the version + pkgs = _findPackageGlob(yb, name) if not pkgs: install_errors.append((name, "No package name matching %s" % name)) continue