From 94b11396e3fe5d22c2651666e5a3bc78a6539421 Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: Jul 04 2018 10:18:24 +0000 Subject: make critpath file optional Don't crash if critpath file is missing or is empty. This is a preparation for shutting down pkgdb where we pull critpath from currently. Critpath is also available in PDC, but that's also going away. New location is currently unknown. Since we don't use critpath in any task at the moment, let's keep this functionality but don't fail when the file is not present. --- diff --git a/jobtriggers/koji_build_msg.py b/jobtriggers/koji_build_msg.py index 3bc52bc..4823590 100644 --- a/jobtriggers/koji_build_msg.py +++ b/jobtriggers/koji_build_msg.py @@ -23,9 +23,8 @@ class KojiBuildCompletedJobTrigger(JobTrigger): def _process_package(self, msg): name, version, release = self._get_nvr(msg) item = '-'.join([name, version, release]) - critpath = utils.parse_yaml_from_file(config.critpath_filepath) distgit_branch = utils.get_distgit_branch(release) - critpath_pkgs = critpath['pkgs'].get(distgit_branch, critpath['pkgs']['master']) + critpath_pkgs = utils.get_critpath_pkgs(release) data = { "_msg": msg, "message_type": "KojiBuildPackageCompleted", diff --git a/jobtriggers/utils.py b/jobtriggers/utils.py index cc3eb35..cbbfb82 100644 --- a/jobtriggers/utils.py +++ b/jobtriggers/utils.py @@ -150,3 +150,15 @@ def git_repo_exists(repo): return False return True + +def get_critpath_pkgs(release): + '''Parse critpath definition file and return a list of critpath packages + for a given release. If the file doesn't exist, return an empty list.''' + if not os.path.exists(config.critpath_filepath): + return [] + critpath = parse_yaml_from_file(config.critpath_filepath) + if not critpath: # file is empty + return [] + distgit_branch = get_distgit_branch(release) + critpath_pkgs = critpath['pkgs'].get(distgit_branch, critpath['pkgs']['master']) + return critpath_pkgs