blob: 1cacd06bf83f92384cd50e238728a7ab803d2143 [file] [log] [blame]
Federico Ressi21a10d32020-01-31 07:43:30 +01001#! /usr/bin/env python3
Clint Adamse3e80512016-02-18 14:46:35 -05002
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 Riedemann9b6d2f22019-06-18 10:43:16 -040022# * network access to the review.opendev.org Gerrit API
Clint Adamse3e80512016-02-18 14:46:35 -050023# working directory
Matt Riedemann9b6d2f22019-06-18 10:43:16 -040024# * network access to https://opendev.org/
Clint Adamse3e80512016-02-18 14:46:35 -050025
Ian Wienandd5634c42019-06-04 17:30:13 +100026import functools
Ian Wienandc10989b2016-03-21 13:03:34 +110027import logging
Clint Adamse3e80512016-02-18 14:46:35 -050028import json
29import requests
30
Ian Wienand893817d2019-09-25 08:30:07 +100031from requests.adapters import HTTPAdapter
32from requests.packages.urllib3.util.retry import Retry
33
Ian Wienandc10989b2016-03-21 13:03:34 +110034logging.basicConfig(level=logging.DEBUG)
35
Ian Wienandd5634c42019-06-04 17:30:13 +100036url = 'https://review.opendev.org/projects/'
Clint Adamse3e80512016-02-18 14:46:35 -050037
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 Wienandd5634c42019-06-04 17:30:13 +100046def is_in_wanted_namespace(proj):
47 # only interested in openstack or x namespace (e.g. not retired
Ian Wienandafd346a2020-01-23 13:13:05 +110048 # 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 Wienandd5634c42019-06-04 17:30:13 +100053 if proj.startswith('stackforge/') or \
Ian Wienandafd346a2020-01-23 13:13:05 +110054 proj.startswith('stackforge-attic/') or \
55 proj == "openstack/openstack":
Ian Wienandd5634c42019-06-04 17:30:13 +100056 return False
57 else:
58 return True
Clint Adamse3e80512016-02-18 14:46:35 -050059
Ian Wienanddb01ca62016-05-09 13:19:09 +100060# Check if this project has a plugin file
Ian Wienandd5634c42019-06-04 17:30:13 +100061def has_devstack_plugin(session, proj):
Ian Wienand9c69eac2016-09-12 14:58:20 +100062 # Don't link in the deb packaging repos
63 if "openstack/deb-" in proj:
64 return False
Ian Wienandd5634c42019-06-04 17:30:13 +100065 r = session.get("https://opendev.org/%s/raw/branch/master/devstack/plugin.sh" % proj)
Ian Wienanddb01ca62016-05-09 13:19:09 +100066 return r.status_code == 200
Clint Adamse3e80512016-02-18 14:46:35 -050067
Ian Wienandc10989b2016-03-21 13:03:34 +110068logging.debug("Getting project list from %s" % url)
Clint Adamse3e80512016-02-18 14:46:35 -050069r = requests.get(url)
Ian Wienandd5634c42019-06-04 17:30:13 +100070projects = sorted(filter(is_in_wanted_namespace, json.loads(r.text[4:])))
Ian Wienandc10989b2016-03-21 13:03:34 +110071logging.debug("Found %d projects" % len(projects))
Clint Adamse3e80512016-02-18 14:46:35 -050072
Ian Wienandd5634c42019-06-04 17:30:13 +100073s = requests.Session()
Ian Wienand893817d2019-09-25 08:30:07 +100074# sometimes gitea gives us a 500 error; retry sanely
75# https://stackoverflow.com/a/35636367
76retries = Retry(total=3, backoff_factor=1,
77 status_forcelist=[ 500 ])
78s.mount('https://', HTTPAdapter(max_retries=retries))
79
Ian Wienandd5634c42019-06-04 17:30:13 +100080found_plugins = filter(functools.partial(has_devstack_plugin, s), projects)
Clint Adamse3e80512016-02-18 14:46:35 -050081
82for project in found_plugins:
Ian Wienandd5634c42019-06-04 17:30:13 +100083 print(project)