From 8080abda671bb25991ea6e04dbd952c77507df59 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 17 Jul 2018 13:47:26 -0700 Subject: [PATCH] Log and exit on metadata update errors at startup A bad system repo can cause lorax-composer to fail to start. Instead of a traceback log the error and exit. (note that the exit still results in an OSError traceback due to part of it running as root, this needs to be addressed in another commit). --- src/pylorax/api/yumbase.py | 12 +++++++++--- src/sbin/lorax-composer | 6 +++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pylorax/api/yumbase.py b/src/pylorax/api/yumbase.py index 704ce159..11b38d40 100644 --- a/src/pylorax/api/yumbase.py +++ b/src/pylorax/api/yumbase.py @@ -24,6 +24,8 @@ from fnmatch import fnmatchcase from glob import glob import os import yum +from yum.Errors import YumBaseError + # This is a hack to short circuit yum's internal logging yum.logginglevels._added_handlers = True @@ -118,6 +120,10 @@ def update_metadata(yb): for r in yb.repos.sort(): r.metadata_expire = 0 r.mdpolicy = "group:all" - yb.doRepoSetup() - yb.repos.doSetup() - yb.repos.populateSack(mdtype='all', cacheonly=0) + try: + yb.doRepoSetup() + yb.repos.doSetup() + yb.repos.populateSack(mdtype='all', cacheonly=0) + except YumBaseError as e: + log.error("Failed to update metadata: %s", str(e)) + raise RuntimeError("Fetching metadata failed: %s" % str(e)) diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index 234b161a..b5de76a5 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -278,7 +278,11 @@ if __name__ == '__main__': make_yum_dirs(server.config["COMPOSER_CFG"]) # Get a YumBase to share with the requests - yb = get_base_object(server.config["COMPOSER_CFG"]) + try: + yb = get_base_object(server.config["COMPOSER_CFG"]) + except RuntimeError: + # Error has already been logged. Just exit cleanly. + sys.exit(1) server.config["YUMLOCK"] = YumLock(yb=yb, lock=Lock()) # Depsolve the templates and make a note of the failures for /api/status to report