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:
Brian C. Lane 2016-06-22 11:01:42 -07:00
parent fe17f970c9
commit 658df4f3f9
1 changed files with 7 additions and 3 deletions

View File

@ -549,6 +549,7 @@ class LoraxTemplateRunner(object):
excludes.append(pkgs[idx+1])
pkgs = pkgs[:idx] + pkgs[idx+2:]
errors = False
for p in pkgs:
try:
# 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.
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:
pkgnames = {pkgname for pkgname in pkgnames if not fnmatch.fnmatch(pkgname, exclude)}
@ -570,10 +573,11 @@ class LoraxTemplateRunner(object):
for pkgname in pkgnames:
self.dbo.install(pkgname)
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))
if required:
raise
errors = True
if errors and required:
raise Exception("Required installpkg failed.")
def removepkg(self, *pkgs):
'''