Use urllib2 instead of requests in tempest generate plugin list
While using generate-tempest-plugins-list.py in tempest-plugin-sanity CI jobs fails to run as it requires requests module to parse the git url and is not install by default in CI job. If we are going to install requests we need to use sudo for that which is not a good idea, so it is better to move the script to urllib2. Change-Id: Ifed51c67c03f993a4833413826ac15104db152fc
This commit is contained in:
parent
b9b03484e5
commit
1b1e6df9af
@ -26,7 +26,12 @@
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import requests
|
try:
|
||||||
|
# For Python 3.0 and later
|
||||||
|
import urllib
|
||||||
|
except ImportError:
|
||||||
|
# Fall back to Python 2's urllib2
|
||||||
|
import urllib2 as urllib
|
||||||
|
|
||||||
url = 'https://review.openstack.org/projects/'
|
url = 'https://review.openstack.org/projects/'
|
||||||
|
|
||||||
@ -49,21 +54,23 @@ def is_in_openstack_namespace(proj):
|
|||||||
|
|
||||||
|
|
||||||
def has_tempest_plugin(proj):
|
def has_tempest_plugin(proj):
|
||||||
if proj.startswith('openstack/deb-'):
|
try:
|
||||||
return False
|
r = urllib.urlopen("https://git.openstack.org/cgit/%s/plain/setup.cfg"
|
||||||
r = requests.get(
|
% proj)
|
||||||
"https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj)
|
except urllib.HTTPError as err:
|
||||||
|
if err.code == 404:
|
||||||
|
return False
|
||||||
p = re.compile('^tempest\.test_plugins', re.M)
|
p = re.compile('^tempest\.test_plugins', re.M)
|
||||||
if p.findall(r.text):
|
if p.findall(r.read()):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
False
|
False
|
||||||
|
|
||||||
r = requests.get(url)
|
r = urllib.urlopen(url)
|
||||||
# Gerrit prepends 4 garbage octets to the JSON, in order to counter
|
# Gerrit prepends 4 garbage octets to the JSON, in order to counter
|
||||||
# cross-site scripting attacks. Therefore we must discard it so the
|
# cross-site scripting attacks. Therefore we must discard it so the
|
||||||
# json library won't choke.
|
# json library won't choke.
|
||||||
projects = sorted(filter(is_in_openstack_namespace, json.loads(r.text[4:])))
|
projects = sorted(filter(is_in_openstack_namespace, json.loads(r.read()[4:])))
|
||||||
|
|
||||||
found_plugins = filter(has_tempest_plugin, projects)
|
found_plugins = filter(has_tempest_plugin, projects)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user