Federico Ressi | 21a10d3 | 2020-01-31 07:43:30 +0100 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 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 |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 22 | # * network access to the review.opendev.org Gerrit API |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 23 | # working directory |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 24 | # * network access to https://opendev.org/ |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 25 | |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 26 | import functools |
Ian Wienand | c10989b | 2016-03-21 13:03:34 +1100 | [diff] [blame] | 27 | import logging |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 28 | import json |
| 29 | import requests |
| 30 | |
Ian Wienand | 893817d | 2019-09-25 08:30:07 +1000 | [diff] [blame] | 31 | from requests.adapters import HTTPAdapter |
| 32 | from requests.packages.urllib3.util.retry import Retry |
| 33 | |
Ian Wienand | c10989b | 2016-03-21 13:03:34 +1100 | [diff] [blame] | 34 | logging.basicConfig(level=logging.DEBUG) |
| 35 | |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 36 | url = 'https://review.opendev.org/projects/' |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 37 | |
| 38 | # This is what a project looks like |
| 39 | ''' |
| 40 | "openstack-attic/akanda": { |
| 41 | "id": "openstack-attic%2Fakanda", |
| 42 | "state": "READ_ONLY" |
| 43 | }, |
| 44 | ''' |
| 45 | |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 46 | def is_in_wanted_namespace(proj): |
| 47 | # only interested in openstack or x namespace (e.g. not retired |
Ian Wienand | afd346a | 2020-01-23 13:13:05 +1100 | [diff] [blame] | 48 | # stackforge, etc). |
| 49 | # |
| 50 | # openstack/openstack "super-repo" of openstack projects as |
| 51 | # submodules, that can cause gitea to 500 timeout and thus stop |
| 52 | # this script. Skip it. |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 53 | if proj.startswith('stackforge/') or \ |
Ian Wienand | afd346a | 2020-01-23 13:13:05 +1100 | [diff] [blame] | 54 | proj.startswith('stackforge-attic/') or \ |
| 55 | proj == "openstack/openstack": |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 56 | return False |
| 57 | else: |
| 58 | return True |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 59 | |
Ian Wienand | db01ca6 | 2016-05-09 13:19:09 +1000 | [diff] [blame] | 60 | # Check if this project has a plugin file |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 61 | def has_devstack_plugin(session, proj): |
Ian Wienand | 9c69eac | 2016-09-12 14:58:20 +1000 | [diff] [blame] | 62 | # Don't link in the deb packaging repos |
| 63 | if "openstack/deb-" in proj: |
| 64 | return False |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 65 | r = session.get("https://opendev.org/%s/raw/branch/master/devstack/plugin.sh" % proj) |
Ian Wienand | db01ca6 | 2016-05-09 13:19:09 +1000 | [diff] [blame] | 66 | return r.status_code == 200 |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 67 | |
Ian Wienand | c10989b | 2016-03-21 13:03:34 +1100 | [diff] [blame] | 68 | logging.debug("Getting project list from %s" % url) |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 69 | r = requests.get(url) |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 70 | projects = sorted(filter(is_in_wanted_namespace, json.loads(r.text[4:]))) |
Ian Wienand | c10989b | 2016-03-21 13:03:34 +1100 | [diff] [blame] | 71 | logging.debug("Found %d projects" % len(projects)) |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 72 | |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 73 | s = requests.Session() |
Ian Wienand | 893817d | 2019-09-25 08:30:07 +1000 | [diff] [blame] | 74 | # sometimes gitea gives us a 500 error; retry sanely |
| 75 | # https://stackoverflow.com/a/35636367 |
Ghanshyam Mann | 1fe7707 | 2024-03-05 08:30:19 -0800 | [diff] [blame] | 76 | # We need to disable raise_on_status because if any repo endup with 500 then |
| 77 | # propose-updates job which run this script will fail. |
Ian Wienand | 893817d | 2019-09-25 08:30:07 +1000 | [diff] [blame] | 78 | retries = Retry(total=3, backoff_factor=1, |
Ghanshyam Mann | 1fe7707 | 2024-03-05 08:30:19 -0800 | [diff] [blame] | 79 | status_forcelist=[ 500 ], |
| 80 | raise_on_status=False) |
Ian Wienand | 893817d | 2019-09-25 08:30:07 +1000 | [diff] [blame] | 81 | s.mount('https://', HTTPAdapter(max_retries=retries)) |
| 82 | |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 83 | found_plugins = filter(functools.partial(has_devstack_plugin, s), projects) |
Clint Adams | e3e8051 | 2016-02-18 14:46:35 -0500 | [diff] [blame] | 84 | |
| 85 | for project in found_plugins: |
Ian Wienand | d5634c4 | 2019-06-04 17:30:13 +1000 | [diff] [blame] | 86 | print(project) |