From 2a4f09673cd0d974fda76f9d5967ac452dc1aaf1 Mon Sep 17 00:00:00 2001 From: Christopher Aedo Date: Thu, 7 Jan 2016 13:47:25 -0800 Subject: [PATCH] Update app-catalog link check job This commit moves the propose-app-catalog-update job from experimental to periodic pipeline, as it will not run properly as an experimental job. Change-Id: I0b4e5ce398c0c8f019cd4f0cbefd0dd142a0dd92 --- jenkins/scripts/check_app_catalog_yaml.py | 39 ++++++++++++++++++----- zuul/layout.yaml | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/jenkins/scripts/check_app_catalog_yaml.py b/jenkins/scripts/check_app_catalog_yaml.py index 7dec25ef2e..dc0786a1a1 100755 --- a/jenkins/scripts/check_app_catalog_yaml.py +++ b/jenkins/scripts/check_app_catalog_yaml.py @@ -15,10 +15,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import yaml import requests -from collections import OrderedDict import requestsexceptions +import yaml + + +from collections import OrderedDict + def project_representer(dumper, data): return dumper.represent_mapping('tag:yaml.org,2002:map', @@ -82,6 +85,19 @@ class IndentedDumper(IndentedEmitter, yaml.serializer.Serializer, yaml.resolver.Resolver.__init__(self) +def get_hashes(hash_url): + hashes = {} + r = requests.get(hash_url, allow_redirects=True) + if r.status_code == 200: + for line in r.iter_lines(): + try: + hash, file = line.split(" ") + except ValueError: + continue + hashes[file] = hash + return hashes + + def main(): requestsexceptions.squelch_warnings() yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, @@ -94,14 +110,21 @@ def main(): assets = [] for a in data['assets']: - if not a.get('attributes', {}).get('active', True): + url = a.get('attributes', {}).get('url') + if not a.get('active', True) or not url: assets.append(a) continue - url = a.get('attributes', {}).get('url') - if url: - r = requests.head(url, allow_redirects=True) - if r.status_code != 200: - a['attributes']['active'] = False + + r = requests.head(url, allow_redirects=True) + if r.status_code != 200: + a['active'] = False + else: + hash_url = a.get('hash_url') + if hash_url: + hashes = get_hashes(hash_url) + filename = url.split("/")[-1] + a['attributes']['hash'] = hashes.get(filename, 'unknown') + assets.append(a) output = {'assets': assets} diff --git a/zuul/layout.yaml b/zuul/layout.yaml index 5c547bf6f9..6482d217bf 100644 --- a/zuul/layout.yaml +++ b/zuul/layout.yaml @@ -3709,7 +3709,7 @@ projects: - gate-app-catalog-npm-run-lint gate: - gate-app-catalog-npm-run-lint - experimental: + periodic: - propose-app-catalog-update - name: openstack/app-catalog-common