Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 1 | #! /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 | |
| 26 | import json |
| 27 | import re |
Masayuki Igawa | 134d9f7 | 2017-02-10 18:05:26 +0900 | [diff] [blame] | 28 | |
Masayuki Igawa | 3e1f330 | 2017-07-03 16:31:40 +0900 | [diff] [blame] | 29 | try: |
| 30 | # For Python 3.0 and later |
mmkmmk57 | 7295698 | 2017-09-15 15:05:43 +0900 | [diff] [blame] | 31 | from urllib.error import HTTPError |
Masayuki Igawa | 3e1f330 | 2017-07-03 16:31:40 +0900 | [diff] [blame] | 32 | import urllib.request as urllib |
| 33 | except ImportError: |
| 34 | # Fall back to Python 2's urllib2 |
| 35 | import urllib2 as urllib |
mmkmmk57 | 7295698 | 2017-09-15 15:05:43 +0900 | [diff] [blame] | 36 | from urllib2 import HTTPError |
Masayuki Igawa | 73c3345 | 2017-06-19 12:08:58 +0900 | [diff] [blame] | 37 | |
Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 38 | |
| 39 | url = 'https://review.openstack.org/projects/' |
| 40 | |
| 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 | |
| 50 | def 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 | |
| 59 | def has_tempest_plugin(proj): |
Chandan Kumar | 1b1e6df | 2017-06-11 17:07:50 +0530 | [diff] [blame] | 60 | try: |
Masayuki Igawa | 3e1f330 | 2017-07-03 16:31:40 +0900 | [diff] [blame] | 61 | r = urllib.urlopen( |
Masayuki Igawa | 73c3345 | 2017-06-19 12:08:58 +0900 | [diff] [blame] | 62 | "https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj) |
Masayuki Igawa | 3e1f330 | 2017-07-03 16:31:40 +0900 | [diff] [blame] | 63 | except HTTPError as err: |
Chandan Kumar | 1b1e6df | 2017-06-11 17:07:50 +0530 | [diff] [blame] | 64 | if err.code == 404: |
| 65 | return False |
Stephen Finucane | 7f4a621 | 2018-07-06 13:58:21 +0100 | [diff] [blame] | 66 | p = re.compile(r'^tempest\.test_plugins', re.M) |
Masayuki Igawa | 73c3345 | 2017-06-19 12:08:58 +0900 | [diff] [blame] | 67 | if p.findall(r.read().decode('utf-8')): |
Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 68 | return True |
| 69 | else: |
| 70 | False |
| 71 | |
Stephen Finucane | 7f4a621 | 2018-07-06 13:58:21 +0100 | [diff] [blame] | 72 | |
Masayuki Igawa | 3e1f330 | 2017-07-03 16:31:40 +0900 | [diff] [blame] | 73 | r = urllib.urlopen(url) |
Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 74 | # Gerrit prepends 4 garbage octets to the JSON, in order to counter |
| 75 | # cross-site scripting attacks. Therefore we must discard it so the |
| 76 | # json library won't choke. |
Felipe Monteiro | ec4c668 | 2018-11-03 18:20:54 -0400 | [diff] [blame^] | 77 | content = r.read().decode('utf-8')[4:] |
| 78 | projects = sorted(filter(is_in_openstack_namespace, json.loads(content))) |
Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 79 | |
ghanshyam | 95b68be | 2018-02-01 02:17:08 +0000 | [diff] [blame] | 80 | # Retrieve projects having no deb, puppet, ui or spec namespace as those |
| 81 | # namespaces do not contains tempest plugins. |
| 82 | projects_list = [i for i in projects if not ( |
| 83 | i.startswith('openstack/deb-') or |
| 84 | i.startswith('openstack/puppet-') or |
| 85 | i.endswith('-ui') or |
| 86 | i.endswith('-specs'))] |
Chandan Kumar | 3c81b41 | 2017-06-13 15:48:20 +0530 | [diff] [blame] | 87 | |
| 88 | found_plugins = list(filter(has_tempest_plugin, projects_list)) |
Clint Adams | a413652 | 2016-03-10 20:24:34 -0500 | [diff] [blame] | 89 | |
| 90 | # Every element of the found_plugins list begins with "openstack/". |
| 91 | # We drop those initial 10 octets when printing the list. |
| 92 | for project in found_plugins: |
| 93 | print(project[10:]) |