blob: 5e63c0dd302f6d55b1c14a19c41453f1b58eaaaa [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
Masayuki Igawa134d9f72017-02-10 18:05:26 +090028
Masayuki Igawa73c33452017-06-19 12:08:58 +090029from six.moves import urllib
30
Clint Adamsa4136522016-03-10 20:24:34 -050031
32url = 'https://review.openstack.org/projects/'
33
34# This is what a project looks like
35'''
36 "openstack-attic/akanda": {
37 "id": "openstack-attic%2Fakanda",
38 "state": "READ_ONLY"
39 },
40'''
41
42
43def is_in_openstack_namespace(proj):
44 return proj.startswith('openstack/')
45
46# Rather than returning a 404 for a nonexistent file, cgit delivers a
47# 0-byte response to a GET request. It also does not provide a
48# Content-Length in a HEAD response, so the way we tell if a file exists
49# is to check the length of the entire GET response body.
50
51
52def has_tempest_plugin(proj):
Chandan Kumar1b1e6df2017-06-11 17:07:50 +053053 try:
Masayuki Igawa73c33452017-06-19 12:08:58 +090054 r = urllib.request.urlopen(
55 "https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj)
56 except urllib.error.HTTPError as err:
Chandan Kumar1b1e6df2017-06-11 17:07:50 +053057 if err.code == 404:
58 return False
Clint Adamsa4136522016-03-10 20:24:34 -050059 p = re.compile('^tempest\.test_plugins', re.M)
Masayuki Igawa73c33452017-06-19 12:08:58 +090060 if p.findall(r.read().decode('utf-8')):
Clint Adamsa4136522016-03-10 20:24:34 -050061 return True
62 else:
63 False
64
Masayuki Igawa73c33452017-06-19 12:08:58 +090065r = urllib.request.urlopen(url)
Clint Adamsa4136522016-03-10 20:24:34 -050066# Gerrit prepends 4 garbage octets to the JSON, in order to counter
67# cross-site scripting attacks. Therefore we must discard it so the
68# json library won't choke.
Chandan Kumar1b1e6df2017-06-11 17:07:50 +053069projects = sorted(filter(is_in_openstack_namespace, json.loads(r.read()[4:])))
Clint Adamsa4136522016-03-10 20:24:34 -050070
Chandan Kumar3c81b412017-06-13 15:48:20 +053071# Retrieve projects having no deb, ui or spec namespace as those namespaces
72# do not contains tempest plugins.
73projects_list = [i for i in projects if not (i.startswith('openstack/deb-') or
74 i.endswith('-ui') or
75 i.endswith('-specs'))]
76
77found_plugins = list(filter(has_tempest_plugin, projects_list))
Clint Adamsa4136522016-03-10 20:24:34 -050078
79# Every element of the found_plugins list begins with "openstack/".
80# We drop those initial 10 octets when printing the list.
81for project in found_plugins:
82 print(project[10:])