blob: 746cb34e9e859596d8719f0104744784e68a57a8 [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
caoyuan349ba752019-04-23 19:40:06 +080022# * network access to the review.opendev.org Gerrit API
Clint Adamsa4136522016-03-10 20:24:34 -050023# working directory
caoyuan349ba752019-04-23 19:40:06 +080024# * network access to https://opendev.org/openstack
Clint Adamsa4136522016-03-10 20:24:34 -050025
26import json
27import re
Masayuki Igawa134d9f72017-02-10 18:05:26 +090028
Masayuki Igawa3e1f3302017-07-03 16:31:40 +090029try:
30 # For Python 3.0 and later
mmkmmk5772956982017-09-15 15:05:43 +090031 from urllib.error import HTTPError
Masayuki Igawa3e1f3302017-07-03 16:31:40 +090032 import urllib.request as urllib
33except ImportError:
34 # Fall back to Python 2's urllib2
35 import urllib2 as urllib
mmkmmk5772956982017-09-15 15:05:43 +090036 from urllib2 import HTTPError
Masayuki Igawa73c33452017-06-19 12:08:58 +090037
Clint Adamsa4136522016-03-10 20:24:34 -050038
caoyuan349ba752019-04-23 19:40:06 +080039url = 'https://review.opendev.org/projects/'
Clint Adamsa4136522016-03-10 20:24:34 -050040
41# This is what a project looks like
42'''
43 "openstack-attic/akanda": {
44 "id": "openstack-attic%2Fakanda",
45 "state": "READ_ONLY"
46 },
47'''
48
49
50def is_in_openstack_namespace(proj):
51 return proj.startswith('openstack/')
52
53# Rather than returning a 404 for a nonexistent file, cgit delivers a
54# 0-byte response to a GET request. It also does not provide a
55# Content-Length in a HEAD response, so the way we tell if a file exists
56# is to check the length of the entire GET response body.
57
58
59def has_tempest_plugin(proj):
Chandan Kumar1b1e6df2017-06-11 17:07:50 +053060 try:
Masayuki Igawa3e1f3302017-07-03 16:31:40 +090061 r = urllib.urlopen(
caoyuan349ba752019-04-23 19:40:06 +080062 "https://opendev.org/%s/raw/branch/"
63 "master/setup.cfg" % proj)
Masayuki Igawa3e1f3302017-07-03 16:31:40 +090064 except HTTPError as err:
Chandan Kumar1b1e6df2017-06-11 17:07:50 +053065 if err.code == 404:
66 return False
Stephen Finucane7f4a6212018-07-06 13:58:21 +010067 p = re.compile(r'^tempest\.test_plugins', re.M)
Masayuki Igawa73c33452017-06-19 12:08:58 +090068 if p.findall(r.read().decode('utf-8')):
Clint Adamsa4136522016-03-10 20:24:34 -050069 return True
70 else:
71 False
72
Stephen Finucane7f4a6212018-07-06 13:58:21 +010073
Masayuki Igawa3e1f3302017-07-03 16:31:40 +090074r = urllib.urlopen(url)
Clint Adamsa4136522016-03-10 20:24:34 -050075# Gerrit prepends 4 garbage octets to the JSON, in order to counter
76# cross-site scripting attacks. Therefore we must discard it so the
77# json library won't choke.
Felipe Monteiroec4c6682018-11-03 18:20:54 -040078content = r.read().decode('utf-8')[4:]
79projects = sorted(filter(is_in_openstack_namespace, json.loads(content)))
Clint Adamsa4136522016-03-10 20:24:34 -050080
ghanshyam95b68be2018-02-01 02:17:08 +000081# Retrieve projects having no deb, puppet, ui or spec namespace as those
82# namespaces do not contains tempest plugins.
83projects_list = [i for i in projects if not (
84 i.startswith('openstack/deb-') or
85 i.startswith('openstack/puppet-') or
86 i.endswith('-ui') or
87 i.endswith('-specs'))]
Chandan Kumar3c81b412017-06-13 15:48:20 +053088
89found_plugins = list(filter(has_tempest_plugin, projects_list))
Clint Adamsa4136522016-03-10 20:24:34 -050090
91# Every element of the found_plugins list begins with "openstack/".
92# We drop those initial 10 octets when printing the list.
93for project in found_plugins:
94 print(project[10:])