From b780bc865e94fbb4d42366be19b3bf26f64a35d7 Mon Sep 17 00:00:00 2001 From: ZhuoX Li Date: Fri, 20 Jun 2014 15:46:02 +0800 Subject: [PATCH] Fix the crash about getting repo name from redis When the repo name doesn't exist in redis,we can't get it from redis. It should normally stop to create repos, not raise exception. Fixes: #1993 Change-Id: Iac77e7c3321071c6db0360998f45f642504ad4f2 --- common/snapshot.py | 19 ++++++++++++++----- job_create_snapshot.py | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common/snapshot.py b/common/snapshot.py index f60efb9..dcb9531 100644 --- a/common/snapshot.py +++ b/common/snapshot.py @@ -60,11 +60,7 @@ class Snapshot(object): """Get snapshot properties from backend db. Init snapshot attributes.""" self.backenddb = backenddb self.base_path = base_path - try: - self.repo_name = repo_name or backenddb.get_obs_repo_map()[obs_project] - except (BackendDBError, EntityError), err: - raise SnapshotError("Can't get repo name for '%s' : %s" % \ - (obs_project, str(err))) + self.repo_name = repo_name or backenddb.get_obs_repo_map()[obs_project] try: self.repo = backenddb.get_repos()[self.repo_name] except BackendDBError, err: @@ -145,3 +141,16 @@ class Snapshot(object): def get_prerelease(self, base_url, tstamp): """Factory for Prerelease object.""" return Prerelease(self, base_url, tstamp) + +def snapshot_project_enabled(backenddb, obs_project): + """Check if project is enabled for OBS project. + This is done by querying repo name from Redis + return the True if repo name exists,otherwise + return False + """ + try: + repo_name = backenddb.get_obs_repo_map()[obs_project] + return True + except (BackendDBError, EntityError), err: + print err + return False diff --git a/job_create_snapshot.py b/job_create_snapshot.py index de3059d..169859b 100755 --- a/job_create_snapshot.py +++ b/job_create_snapshot.py @@ -13,7 +13,7 @@ from common.buildtrigger import trigger_info, trigger_next from common.buildservice import BuildService from common.repomaker import RepoMaker, RepoMakerError from common.backenddb import BackendDB -from common.snapshot import Snapshot, SnapshotError +from common.snapshot import Snapshot, SnapshotError, snapshot_project_enabled from common.utils import make_latest_link class LocalError(Exception): @@ -79,7 +79,6 @@ def make_repo(project, backenddb, base_path, live_repo_base, buildconf=None): Raises: LocalError if can't create repos or can't find image configurations """ - try: snapshot = Snapshot(backenddb, base_path, obs_project=project) except SnapshotError, err: @@ -162,6 +161,11 @@ def main(): # Get buildconf from OBS, put the buildconf together with repo-md buildconf_str = build.get_project_config(project) + # whether project is not enabled + if not snapshot_project_enabled(backenddb, project): + print "Skipping, project isn't found in repo.yaml" + return 0 + repo_data = make_repo(project, backenddb, base_path, live_repo_base, buildconf = buildconf_str) -- 2.7.4