From 57d160b7b396840f7ddfd53ab5d5678e93003057 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 26 Jul 2018 11:53:31 +1000 Subject: [PATCH] Allow get_projects to fall-back to master. In the event that the governance repo isn't tagged we want to be able to fall-back to master so we can still potentially validate a candidate. Change-Id: Ie13770f92dd05a3aa79bdc85b1bb482df3f3b8f3 --- openstack_election/utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/openstack_election/utils.py b/openstack_election/utils.py index ff20d349..07a163d5 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -24,6 +24,7 @@ import sys import time import yaml +from six.moves.urllib.error import HTTPError from six.moves.urllib.parse import quote_plus from six.moves.urllib.request import urlopen @@ -204,7 +205,7 @@ def check_atc_date(atc): return conf['timeframe']['end'] < expires_in -def get_projects(tag=None): +def _get_projects(tag=None): url = PROJECTS_URL cache_file = '.projects.pkl' @@ -223,6 +224,17 @@ def get_projects(tag=None): return pickle.load(open(cache_file, "rb")) +def get_projects(tag=None, fallback_to_master=False): + try: + projects = _get_projects(tag) + except HTTPError as exc: + if exc.code == 404 and tag and fallback_to_master: + projects = _get_projects() + else: + raise + return projects + + # Election functions def name2dir(name): """Convert project name to directory name: only [a-zA-Z_] in camelcase"""