Fix no attribute 'urlopen' error in python3
This commit fixes an error: "AttributeError: module 'urllib' has no
attribute 'urlopen'" with using six library. This is an incompatible
thing between python2 and python3.
Change-Id: I62ee7ee555708a2e948e6b812d996c3bb93cd6e8
diff --git a/tools/generate-tempest-plugins-list.py b/tools/generate-tempest-plugins-list.py
index 238a976..80a328b 100644
--- a/tools/generate-tempest-plugins-list.py
+++ b/tools/generate-tempest-plugins-list.py
@@ -26,12 +26,8 @@
import json
import re
-try:
- # For Python 3.0 and later
- import urllib
-except ImportError:
- # Fall back to Python 2's urllib2
- import urllib2 as urllib
+from six.moves import urllib
+
url = 'https://review.openstack.org/projects/'
@@ -55,18 +51,18 @@
def has_tempest_plugin(proj):
try:
- r = urllib.urlopen("https://git.openstack.org/cgit/%s/plain/setup.cfg"
- % proj)
- except urllib.HTTPError as err:
+ r = urllib.request.urlopen(
+ "https://git.openstack.org/cgit/%s/plain/setup.cfg" % proj)
+ except urllib.error.HTTPError as err:
if err.code == 404:
return False
p = re.compile('^tempest\.test_plugins', re.M)
- if p.findall(r.read()):
+ if p.findall(r.read().decode('utf-8')):
return True
else:
False
-r = urllib.urlopen(url)
+r = urllib.request.urlopen(url)
# Gerrit prepends 4 garbage octets to the JSON, in order to counter
# cross-site scripting attacks. Therefore we must discard it so the
# json library won't choke.