blob: 03e838eda7d86d7c50ed13da70eca1af16f9b311 [file] [log] [blame]
Clint Adamsa4136522016-03-10 20:24:34 -05001#! /usr/bin/env python
2
3# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17# This script is intended to be run as part of a periodic proposal bot
18# job in OpenStack infrastructure.
19#
20# In order to function correctly, the environment in which the
21# script runs must have
22# * network access to the review.openstack.org Gerrit API
23# working directory
24# * network access to https://git.openstack.org/cgit
25
26import json
27import re
28import requests
29
30url = 'https://review.openstack.org/projects/'
31
32# This is what a project looks like
33'''
34 "openstack-attic/akanda": {
35 "id": "openstack-attic%2Fakanda",
36 "state": "READ_ONLY"
37 },
38'''
39
40
41def is_in_openstack_namespace(proj):
42 return proj.startswith('openstack/')
43
44# Rather than returning a 404 for a nonexistent file, cgit delivers a
45# 0-byte response to a GET request. It also does not provide a
46# Content-Length in a HEAD response, so the way we tell if a file exists
47# is to check the length of the entire GET response body.
48
49
50def has_tempest_plugin(proj):
Matthew Treinishcc4ae482016-09-13 19:23:18 -040051 if proj.startswith('openstack/deb-'):
52 return False
Clint Adamsa4136522016-03-10 20:24:34 -050053 r = requests.get(
54 "https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj)
55 p = re.compile('^tempest\.test_plugins', re.M)
56 if p.findall(r.text):
57 return True
58 else:
59 False
60
61r = requests.get(url)
62# Gerrit prepends 4 garbage octets to the JSON, in order to counter
63# cross-site scripting attacks. Therefore we must discard it so the
64# json library won't choke.
65projects = sorted(filter(is_in_openstack_namespace, json.loads(r.text[4:])))
66
67found_plugins = filter(has_tempest_plugin, projects)
68
69# Every element of the found_plugins list begins with "openstack/".
70# We drop those initial 10 octets when printing the list.
71for project in found_plugins:
72 print(project[10:])