py3: Get urllib modules from six.moves

Replace urllib imports with six.moves.urllib to make modified code
compatible with Python 2 and Python 3.

This patch was generated by the urllib operation on the sixer tool.

The mock in cue.tests.functional.fixtures.urllib2_fixture is not
modified because it breaks functional tests on Python 2. It can be
fixed later.

Change-Id: Idd561fef168d234311a469c35f8672c518b90543
This commit is contained in:
Victor Stinner 2015-09-29 22:09:43 +02:00
parent 49981f2004
commit 312dda7866
4 changed files with 17 additions and 19 deletions

View File

@ -14,9 +14,8 @@
# under the License.
import json
import urllib
import urllib2
from six.moves import urllib
import taskflow.task
@ -48,38 +47,38 @@ class GetRabbitClusterStatus(taskflow.task.Task):
# RMQ management url to query whether the RMQ nodes have clustered
aliveness_url = base_url + '/aliveness-test'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None,
vhosts_url,
default_rabbit_user,
default_rabbit_pass)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
retval = "NOT-OK"
try:
res = opener.open(vhosts_url)
except urllib2.URLError:
except urllib.error.URLError:
pass
else:
json_res = json.load(res)
result = {}
for x in json_res:
vhost = urllib.quote(x['name'], '')
vhost = urllib.parse.quote(x['name'], '')
cur_aliveness_url = aliveness_url + '/' + vhost
password_mgr.add_password(None,
cur_aliveness_url,
default_rabbit_user,
default_rabbit_pass)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
res = opener.open(cur_aliveness_url)
result[x['name']] = json.load(res)['status']
if all(val == 'ok' for val in result.values()):
retval = 'OK'
return retval
return retval

View File

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib2
import six
from six.moves import urllib
import cue.tests.functional.fixtures.base as base
@ -66,5 +65,5 @@ class Urllib2Fixture(base.BaseFixture):
def open(self, url):
result = Urllib2ResultDetails.get_urllib2_result()
if result.getvalue() is 'URLError':
raise urllib2.URLError('urlerror')
return result
raise urllib.error.URLError('urlerror')
return result

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves import urllib
from cue.taskflow.task import get_rabbit_cluster_status
from cue.tests.functional import base
from cue.tests.functional.fixtures import urllib2_fixture as urllib2_fixture
@ -20,8 +22,6 @@ from cue.tests.functional.fixtures import urllib2_fixture as urllib2_fixture
from taskflow import engines
from taskflow.patterns import linear_flow
import urllib2
class GetRabbitClusterStatusTest(base.FunctionalTestCase):
additional_fixtures = [
@ -85,6 +85,6 @@ class GetRabbitClusterStatusTest(base.FunctionalTestCase):
try:
# start engine
engines.run(self.flow, store=GetRabbitClusterStatusTest.task_store)
except urllib2.URLError:
except urllib.error.URLError:
# Expected
pass

View File

@ -15,8 +15,8 @@
import json
import logging
import urllib
from six.moves import urllib
from tempest_lib.common import rest_client
from tests.integration.common import client
@ -37,7 +37,7 @@ class MessageQueueClustersClient(client.BaseMessageQueueClient):
:param url: Optional parameter for custom url
"""
if params:
url += '?%s' % urllib.urlencode(params)
url += '?%s' % urllib.parse.urlencode(params)
resp, body = self.get(url)
self.expected_success(200, resp.status)