Fix installpkg error handling
If the query filter doesn't return anything it would just ignore the install request instead of logging and raising an error when required=True. This checks for no packages matching, and if required is True raises an error after all of the requested packages have been processed, instead of after the first one to fail.
This commit is contained in:
parent
fe17f970c9
commit
658df4f3f9
@ -549,6 +549,7 @@ class LoraxTemplateRunner(object):
|
|||||||
excludes.append(pkgs[idx+1])
|
excludes.append(pkgs[idx+1])
|
||||||
pkgs = pkgs[:idx] + pkgs[idx+2:]
|
pkgs = pkgs[:idx] + pkgs[idx+2:]
|
||||||
|
|
||||||
|
errors = False
|
||||||
for p in pkgs:
|
for p in pkgs:
|
||||||
try:
|
try:
|
||||||
# Start by using Subject to generate a package query, which will
|
# Start by using Subject to generate a package query, which will
|
||||||
@ -563,6 +564,8 @@ class LoraxTemplateRunner(object):
|
|||||||
# the filtering is done the hard way.
|
# the filtering is done the hard way.
|
||||||
|
|
||||||
pkgnames = {pkg.name for pkg in dnf.subject.Subject(p).get_best_query(self.dbo.sack)}
|
pkgnames = {pkg.name for pkg in dnf.subject.Subject(p).get_best_query(self.dbo.sack)}
|
||||||
|
if not pkgnames:
|
||||||
|
raise dnf.exceptions.PackageNotFoundError("no package matched", p)
|
||||||
|
|
||||||
for exclude in excludes:
|
for exclude in excludes:
|
||||||
pkgnames = {pkgname for pkgname in pkgnames if not fnmatch.fnmatch(pkgname, exclude)}
|
pkgnames = {pkgname for pkgname in pkgnames if not fnmatch.fnmatch(pkgname, exclude)}
|
||||||
@ -570,10 +573,11 @@ class LoraxTemplateRunner(object):
|
|||||||
for pkgname in pkgnames:
|
for pkgname in pkgnames:
|
||||||
self.dbo.install(pkgname)
|
self.dbo.install(pkgname)
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
# FIXME: save exception and re-raise after the loop finishes
|
|
||||||
logger.error("installpkg %s failed: %s", p, str(e))
|
logger.error("installpkg %s failed: %s", p, str(e))
|
||||||
if required:
|
errors = True
|
||||||
raise
|
|
||||||
|
if errors and required:
|
||||||
|
raise Exception("Required installpkg failed.")
|
||||||
|
|
||||||
def removepkg(self, *pkgs):
|
def removepkg(self, *pkgs):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user