Use six to fix imports on Python 3

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

Replaced imports:

* BaseHTTPServer
* __builtin__
* cookielib
* httplib

This patch was generated by the six_moves operation of the sixer tool
version 0.4:
https://pypi.python.org/pypi/sixer

Manual changes:

* Disable pylint warnings on the HTTPSConnection classes because pylint
  doesn't support importing from six.moves yet, see:
  https://bitbucket.org/logilab/pylint/issue/550/

Blueprint cinder-python3
Change-Id: Ide6d4e3480f2c0a7eb4500aa88affe152ecc0401
changes/17/185417/9
Victor Stinner 8 years ago
parent 6feb65dcf4
commit f484310fe6

@ -19,13 +19,13 @@ Module dedicated functions/classes dealing with rate limiting requests.
import collections
import copy
import httplib
import math
import re
import time
from oslo_serialization import jsonutils
from oslo_utils import importutils
from six.moves import http_client
import webob.dec
import webob.exc
@ -439,7 +439,7 @@ class WsgiLimiterProxy(object):
body = jsonutils.dumps({"verb": verb, "path": path})
headers = {"Content-Type": "application/json"}
conn = httplib.HTTPConnection(self.limiter_address)
conn = http_client.HTTPConnection(self.limiter_address)
if username:
conn.request("POST", "/%s" % (username), body, headers)

@ -19,13 +19,13 @@ Module dedicated functions/classes dealing with rate limiting requests.
import collections
import copy
import httplib
import math
import re
import time
from oslo_serialization import jsonutils
from oslo_utils import importutils
from six.moves import http_client
import webob.dec
import webob.exc
@ -437,7 +437,7 @@ class WsgiLimiterProxy(object):
body = jsonutils.dumps({"verb": verb, "path": path})
headers = {"Content-Type": "application/json"}
conn = httplib.HTTPConnection(self.limiter_address)
conn = http_client.HTTPConnection(self.limiter_address)
if username:
conn.request("POST", "/%s" % (username), body, headers)

@ -29,10 +29,10 @@
"""
import eventlet
from six.moves import builtins
eventlet.monkey_patch()
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
setattr(__builtin__, '_', lambda x: x)
setattr(builtins, '_', lambda x: x)

@ -17,12 +17,12 @@
Tests dealing with HTTP rate-limiting.
"""
import httplib
from xml.dom import minidom
from lxml import etree
from oslo_serialization import jsonutils
import six
from six.moves import http_client
import webob
from cinder.api.v1 import limits
@ -631,7 +631,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
class FakeHttplibSocket(object):
"""Fake `httplib.HTTPResponse` replacement."""
"""Fake `http_client.HTTPResponse` replacement."""
def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
@ -643,7 +643,7 @@ class FakeHttplibSocket(object):
class FakeHttplibConnection(object):
"""Fake `httplib.HTTPConnection`."""
"""Fake `http_client.HTTPConnection`."""
def __init__(self, app, host):
"""Initialize `FakeHttplibConnection`."""
@ -655,7 +655,7 @@ class FakeHttplibConnection(object):
Requests made via this connection actually get translated and
routed into our WSGI app, we then wait for the response and turn
it back into an `httplib.HTTPResponse`.
it back into an `http_client.HTTPResponse`.
"""
if not headers:
headers = {}
@ -669,7 +669,7 @@ class FakeHttplibConnection(object):
resp = str(req.get_response(self.app))
resp = "HTTP/1.0 %s" % resp
sock = FakeHttplibSocket(resp)
self.http_response = httplib.HTTPResponse(sock)
self.http_response = http_client.HTTPResponse(sock)
self.http_response.begin()
def getresponse(self):
@ -683,7 +683,7 @@ def wire_HTTPConnection_to_WSGI(host, app):
After calling this method, when any code calls
httplib.HTTPConnection(host)
http_client.HTTPConnection(host)
the connection object will be a fake. Its requests will be sent directly
to the given WSGI app rather than through a socket.
@ -710,8 +710,9 @@ def wire_HTTPConnection_to_WSGI(host, app):
else:
return self.wrapped(connection_host, *args, **kwargs)
oldHTTPConnection = httplib.HTTPConnection
httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection)
oldHTTPConnection = http_client.HTTPConnection
new_http_connection = HTTPConnectionDecorator(http_client.HTTPConnection)
http_client.HTTPConnection = new_http_connection
return oldHTTPConnection
@ -722,7 +723,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
"""setUp for test suite.
Do some nifty HTTP/WSGI magic which allows for WSGI to be called
directly by something like the `httplib` library.
directly by something like the `http_client` library.
"""
super(WsgiLimiterProxyTest, self).setUp()
self.app = limits.WsgiLimiter(TEST_LIMITS)
@ -733,7 +734,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
def _restore(self, oldHTTPConnection):
# restore original HTTPConnection object
httplib.HTTPConnection = oldHTTPConnection
http_client.HTTPConnection = oldHTTPConnection
def test_200(self):
"""Successful request test."""

@ -17,12 +17,12 @@
Tests dealing with HTTP rate-limiting.
"""
import httplib
from xml.dom import minidom
from lxml import etree
from oslo_serialization import jsonutils
import six
from six.moves import http_client
import webob
from cinder.api.v2 import limits
@ -634,7 +634,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
class FakeHttplibSocket(object):
"""Fake `httplib.HTTPResponse` replacement."""
"""Fake `http_client.HTTPResponse` replacement."""
def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
@ -647,7 +647,7 @@ class FakeHttplibSocket(object):
class FakeHttplibConnection(object):
"""Fake `httplib.HTTPConnection`."""
"""Fake `http_client.HTTPConnection`."""
def __init__(self, app, host):
"""Initialize `FakeHttplibConnection`."""
@ -659,7 +659,7 @@ class FakeHttplibConnection(object):
Requests made via this connection actually get translated and
routed into our WSGI app, we then wait for the response and turn
it back into an `httplib.HTTPResponse`.
it back into an `http_client.HTTPResponse`.
"""
if not headers:
headers = {}
@ -673,7 +673,7 @@ class FakeHttplibConnection(object):
resp = str(req.get_response(self.app))
resp = "HTTP/1.0 %s" % resp
sock = FakeHttplibSocket(resp)
self.http_response = httplib.HTTPResponse(sock)
self.http_response = http_client.HTTPResponse(sock)
self.http_response.begin()
def getresponse(self):
@ -687,7 +687,7 @@ def wire_HTTPConnection_to_WSGI(host, app):
After calling this method, when any code calls
httplib.HTTPConnection(host)
http_client.HTTPConnection(host)
the connection object will be a fake. Its requests will be sent directly
to the given WSGI app rather than through a socket.
@ -714,8 +714,9 @@ def wire_HTTPConnection_to_WSGI(host, app):
else:
return self.wrapped(connection_host, *args, **kwargs)
oldHTTPConnection = httplib.HTTPConnection
httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection)
oldHTTPConnection = http_client.HTTPConnection
new_http_connection = HTTPConnectionDecorator(http_client.HTTPConnection)
http_client.HTTPConnection = new_http_connection
return oldHTTPConnection
@ -727,7 +728,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
"""setUp() for WsgiLimiterProxyTest.
Do some nifty HTTP/WSGI magic which allows for WSGI to be called
directly by something like the `httplib` library.
directly by something like the `http_client` library.
"""
super(WsgiLimiterProxyTest, self).setUp()
self.app = limits.WsgiLimiter(TEST_LIMITS)
@ -738,7 +739,7 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
def _restore(self, oldHTTPConnection):
# restore original HTTPConnection object
httplib.HTTPConnection = oldHTTPConnection
http_client.HTTPConnection = oldHTTPConnection
def test_200(self):
"""Successful request test."""

@ -16,7 +16,6 @@
Tests for Backup NFS driver.
"""
import __builtin__
import bz2
import exceptions
import filecmp
@ -30,6 +29,7 @@ import mock
from os_brick.remotefs import remotefs as remotefs_brick
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import builtins
from cinder.backup.drivers import nfs
from cinder import context
@ -214,20 +214,20 @@ class BackupNFSTestCase(test.TestCase):
self.assertEqual([], result)
def test_get_object_writer(self):
self.mock_object(__builtin__, 'open', mock.mock_open())
self.mock_object(builtins, 'open', mock.mock_open())
self.mock_object(os, 'chmod')
self.driver.get_object_writer(FAKE_CONTAINER, FAKE_OBJECT_NAME)
os.chmod.assert_called_once_with(FAKE_OBJECT_PATH, 0o660)
__builtin__.open.assert_called_once_with(FAKE_OBJECT_PATH, 'w')
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'w')
def test_get_object_reader(self):
self.mock_object(__builtin__, 'open', mock.mock_open())
self.mock_object(builtins, 'open', mock.mock_open())
self.driver.get_object_reader(FAKE_CONTAINER, FAKE_OBJECT_NAME)
__builtin__.open.assert_called_once_with(FAKE_OBJECT_PATH, 'r')
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'r')
def test_delete_object(self):
self.mock_object(os, 'remove')

@ -13,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import httplib
import json
import os
import socket
import zlib
from oslo_log import log as logging
from six.moves import http_client
from swiftclient import client as swift
LOG = logging.getLogger(__name__)
@ -45,10 +45,10 @@ class FakeSwiftConnection(object):
LOG.debug("fake head_container(%s)" % container)
if container == 'missing_container':
raise swift.ClientException('fake exception',
http_status=httplib.NOT_FOUND)
http_status=http_client.NOT_FOUND)
elif container == 'unauthorized_container':
raise swift.ClientException('fake exception',
http_status=httplib.UNAUTHORIZED)
http_status=http_client.UNAUTHORIZED)
elif container == 'socket_error_on_head':
raise socket.error(111, 'ECONNREFUSED')
pass

@ -15,12 +15,12 @@
# under the License.
import hashlib
import httplib
import os
import socket
import tempfile
from oslo_log import log as logging
from six.moves import http_client
from swiftclient import client as swift
from cinder.openstack.common import fileutils
@ -48,10 +48,10 @@ class FakeSwiftConnection2(object):
LOG.debug("fake head_container(%s)", container)
if container == 'missing_container':
raise swift.ClientException('fake exception',
http_status=httplib.NOT_FOUND)
http_status=http_client.NOT_FOUND)
elif container == 'unauthorized_container':
raise swift.ClientException('fake exception',
http_status=httplib.UNAUTHORIZED)
http_status=http_client.UNAUTHORIZED)
elif container == 'socket_error_on_head':
raise socket.error(111, 'ECONNREFUSED')

@ -17,14 +17,13 @@
"""Unit tests for the API endpoint."""
import httplib
import six
from six.moves import http_client
import webob
class FakeHttplibSocket(object):
"""A fake socket implementation for httplib.HTTPResponse, trivial."""
"""A fake socket implementation for http_client.HTTPResponse, trivial."""
def __init__(self, response_string):
self.response_string = response_string
self._buffer = six.StringIO(response_string)
@ -35,11 +34,11 @@ class FakeHttplibSocket(object):
class FakeHttplibConnection(object):
"""A fake httplib.HTTPConnection for boto.
"""A fake http_client.HTTPConnection for boto.
requests made via this connection actually get translated and routed into
our WSGI app, we then wait for the response and turn it back into
the httplib.HTTPResponse that boto expects.
the http_client.HTTPResponse that boto expects.
"""
def __init__(self, app, host, is_secure=False):
self.app = app
@ -58,7 +57,7 @@ class FakeHttplibConnection(object):
# guess that's a function the web server usually provides.
resp = "HTTP/1.0 %s" % resp
self.sock = FakeHttplibSocket(resp)
self.http_response = httplib.HTTPResponse(self.sock)
self.http_response = http_client.HTTPResponse(self.sock)
# NOTE(vish): boto is accessing private variables for some reason
self._HTTPConnection__response = self.http_response
self.http_response.begin()

@ -17,13 +17,12 @@ Tests for NetApp volume driver
"""
import BaseHTTPServer
import httplib
from lxml import etree
import mock
from oslo_log import log as logging
import six
from six.moves import BaseHTTPServer
from six.moves import http_client
from cinder import exception
from cinder import test
@ -58,7 +57,7 @@ class FakeHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class FakeHttplibSocket(object):
"""A fake socket implementation for httplib.HTTPResponse."""
"""A fake socket implementation for http_client.HTTPResponse."""
def __init__(self, value):
self._rbuffer = six.StringIO(value)
self._wbuffer = six.StringIO('')
@ -444,11 +443,11 @@ class FakeDirectCMODEServerHandler(FakeHTTPRequestHandler):
class FakeDirectCmodeHTTPConnection(object):
"""A fake httplib.HTTPConnection for netapp tests
"""A fake http_client.HTTPConnection for netapp tests
Requests made via this connection actually get translated and routed into
the fake direct handler above, we then turn the response into
the httplib.HTTPResponse that the caller expects.
the http_client.HTTPResponse that the caller expects.
"""
def __init__(self, host, timeout=None):
self.host = host
@ -470,7 +469,7 @@ class FakeDirectCmodeHTTPConnection(object):
self.app = FakeDirectCMODEServerHandler(sock, '127.0.0.1:80', None)
self.sock = FakeHttplibSocket(sock.result)
self.http_response = httplib.HTTPResponse(self.sock)
self.http_response = http_client.HTTPResponse(self.sock)
def set_debuglevel(self, level):
pass
@ -553,7 +552,7 @@ class NetAppDirectCmodeISCSIDriverTestCase(test.TestCase):
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',
self.stubs.Set(http_client, 'HTTPConnection',
FakeDirectCmodeHTTPConnection)
driver.do_setup(context='')
self.driver = driver
@ -1126,11 +1125,11 @@ class FakeDirect7MODEServerHandler(FakeHTTPRequestHandler):
class FakeDirect7modeHTTPConnection(object):
"""A fake httplib.HTTPConnection for netapp tests
"""A fake http_client.HTTPConnection for netapp tests
Requests made via this connection actually get translated and routed into
the fake direct handler above, we then turn the response into
the httplib.HTTPResponse that the caller expects.
the http_client.HTTPResponse that the caller expects.
"""
def __init__(self, host, timeout=None):
self.host = host
@ -1152,7 +1151,7 @@ class FakeDirect7modeHTTPConnection(object):
self.app = FakeDirect7MODEServerHandler(sock, '127.0.0.1:80', None)
self.sock = FakeHttplibSocket(sock.result)
self.http_response = httplib.HTTPResponse(self.sock)
self.http_response = http_client.HTTPResponse(self.sock)
def set_debuglevel(self, level):
pass
@ -1177,7 +1176,7 @@ class NetAppDirect7modeISCSIDriverTestCase_NV(
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',
self.stubs.Set(http_client, 'HTTPConnection',
FakeDirect7modeHTTPConnection)
driver.do_setup(context='')
driver.root_volume_name = 'root'
@ -1233,7 +1232,7 @@ class NetAppDirect7modeISCSIDriverTestCase_WV(
self.mock_object(utils, 'OpenStackInfo')
configuration = self._set_config(create_configuration())
driver = common.NetAppDriver(configuration=configuration)
self.stubs.Set(httplib, 'HTTPConnection',
self.stubs.Set(http_client, 'HTTPConnection',
FakeDirect7modeHTTPConnection)
driver.do_setup(context='')
self.driver = driver

@ -14,13 +14,12 @@
# under the License.
"""Unit tests for the NetApp-specific ssc module."""
import BaseHTTPServer
import copy
import httplib
from lxml import etree
from mox3 import mox
import six
from six.moves import BaseHTTPServer
from six.moves import http_client
from cinder import exception
from cinder import test
@ -36,7 +35,7 @@ class FakeHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class FakeHttplibSocket(object):
"""A fake socket implementation for httplib.HTTPResponse."""
"""A fake socket implementation for http_client.HTTPResponse."""
def __init__(self, value):
self._rbuffer = six.StringIO(value)
self._wbuffer = six.StringIO('')
@ -252,11 +251,11 @@ class FakeDirectCMODEServerHandler(FakeHTTPRequestHandler):
class FakeDirectCmodeHTTPConnection(object):
"""A fake httplib.HTTPConnection for netapp tests.
"""A fake http_client.HTTPConnection for netapp tests.
Requests made via this connection actually get translated and routed into
the fake direct handler above, we then turn the response into
the httplib.HTTPResponse that the caller expects.
the http_client.HTTPResponse that the caller expects.
"""
def __init__(self, host, timeout=None):
self.host = host
@ -278,7 +277,7 @@ class FakeDirectCmodeHTTPConnection(object):
self.app = FakeDirectCMODEServerHandler(sock, '127.0.0.1:80', None)
self.sock = FakeHttplibSocket(sock.result)
self.http_response = httplib.HTTPResponse(self.sock)
self.http_response = http_client.HTTPResponse(self.sock)
def set_debuglevel(self, level):
pass
@ -372,7 +371,7 @@ class SscUtilsTestCase(test.TestCase):
def setUp(self):
super(SscUtilsTestCase, self).setUp()
self.stubs.Set(httplib, 'HTTPConnection',
self.stubs.Set(http_client, 'HTTPConnection',
FakeDirectCmodeHTTPConnection)
def test_cl_vols_ssc_all(self):

@ -14,11 +14,11 @@
import copy
import errno
import httplib
import re
import mock
from oslo_utils import units
from six.moves import http_client
from cinder import exception
from cinder import test
@ -206,7 +206,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'GET',
'/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_SYSTEM),
None,
[httplib.OK, httplib.ACCEPTED])
[http_client.OK, http_client.ACCEPTED])
def test_createvdev(self):
self.dplcmd.create_vdev(DATA_IN_VOLUME['id'],
@ -229,7 +229,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED, http_client.CREATED])
def test_extendvdev(self):
self.dplcmd.extend_vdev(DATA_IN_VOLUME['id'],
@ -248,7 +248,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED, http_client.CREATED])
def test_deletevdev(self):
self.dplcmd.delete_vdev(DATA_IN_VOLUME['id'], True)
@ -261,8 +261,8 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED, httplib.NOT_FOUND,
httplib.NO_CONTENT])
[http_client.OK, http_client.ACCEPTED, http_client.NOT_FOUND,
http_client.NO_CONTENT])
def test_createvdevfromsnapshot(self):
self.dplcmd.create_vdev_from_snapshot(
@ -287,7 +287,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED, http_client.CREATED])
def test_getpool(self):
self.dplcmd.get_pool(POOLUUID)
@ -296,7 +296,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_POOL,
POOLUUID),
None,
[httplib.OK, httplib.ACCEPTED])
[http_client.OK, http_client.ACCEPTED])
def test_clonevdev(self):
self.dplcmd.clone_vdev(
@ -324,7 +324,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME1['id']),
params,
[httplib.OK, httplib.CREATED, httplib.ACCEPTED])
[http_client.OK, http_client.CREATED, http_client.ACCEPTED])
def test_createvdevsnapshot(self):
self.dplcmd.create_vdev_snapshot(
@ -346,7 +346,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.CREATED, httplib.ACCEPTED])
[http_client.OK, http_client.CREATED, http_client.ACCEPTED])
def test_getvdev(self):
self.dplcmd.get_vdev(DATA_IN_VOLUME['id'])
@ -355,7 +355,7 @@ class TestProphetStorDPLVolume(test.TestCase):
'/%s/%s/%s/' % (DPLCOMMON.DPL_VER_V1, DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
None,
[httplib.OK, httplib.ACCEPTED, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED, http_client.NOT_FOUND])
def test_getvdevstatus(self):
self.dplcmd.get_vdev_status(DATA_IN_VOLUME['id'], '123456')
@ -366,7 +366,7 @@ class TestProphetStorDPLVolume(test.TestCase):
DATA_IN_VOLUME['id'],
'123456'),
None,
[httplib.OK, httplib.NOT_FOUND])
[http_client.OK, http_client.NOT_FOUND])
def test_getpoolstatus(self):
self.dplcmd.get_pool_status(POOLUUID, '123456')
@ -377,7 +377,7 @@ class TestProphetStorDPLVolume(test.TestCase):
POOLUUID,
'123456'),
None,
[httplib.OK, httplib.NOT_FOUND])
[http_client.OK, http_client.NOT_FOUND])
def test_assignvdev(self):
self.dplcmd.assign_vdev(
@ -411,7 +411,7 @@ class TestProphetStorDPLVolume(test.TestCase):
DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED, http_client.CREATED])
def test_unassignvdev(self):
self.dplcmd.unassign_vdev(DATA_IN_VOLUME['id'],
@ -436,8 +436,8 @@ class TestProphetStorDPLVolume(test.TestCase):
DPLCOMMON.DPL_OBJ_VOLUME,
DATA_IN_VOLUME['id']),
params,
[httplib.OK, httplib.ACCEPTED,
httplib.NO_CONTENT, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NO_CONTENT, http_client.NOT_FOUND])
def test_deletevdevsnapshot(self):
self.dplcmd.delete_vdev_snapshot(DATA_IN_VOLUME['id'],
@ -453,8 +453,8 @@ class TestProphetStorDPLVolume(test.TestCase):
DPLCOMMON.DPL_OBJ_SNAPSHOT,
DATA_IN_SNAPSHOT['id']),
None,
[httplib.OK, httplib.ACCEPTED, httplib.NO_CONTENT,
httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED, http_client.NO_CONTENT,
http_client.NOT_FOUND])
def test_listvdevsnapshots(self):
self.dplcmd.list_vdev_snapshots(DATA_IN_VOLUME['id'])
@ -465,7 +465,7 @@ class TestProphetStorDPLVolume(test.TestCase):
DATA_IN_VOLUME['id'],
DPLCOMMON.DPL_OBJ_SNAPSHOT),
None,
[httplib.OK])
[http_client.OK])
class TestProphetStorDPLDriver(test.TestCase):

@ -13,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import httplib
import json
import uuid
from oslo_log import log as logging
from oslo_utils import units
import six
from six.moves import http_client
from six.moves import urllib
from cinder import exception
@ -97,7 +97,7 @@ class CloudByteISCSIDriver(san.SanISCSIDriver):
res_details = {}
try:
# Prepare the connection
connection = httplib.HTTPSConnection(host)
connection = http_client.HTTPSConnection(host)
# Make the connection
connection.request('GET', url)
# Extract the response as the connection was successful
@ -153,7 +153,7 @@ class CloudByteISCSIDriver(san.SanISCSIDriver):
error_details = res_obj['error']
http_status = res_obj['http_status']
except httplib.HTTPException as ex:
except http_client.HTTPException as ex:
msg = (_("Error executing CloudByte API [%(cmd)s], "
"Error: %(err)s.") %
{'cmd': cmd, 'err': ex})

@ -14,7 +14,6 @@
# under the License.
import base64
import httplib
import os
import socket
import ssl
@ -25,6 +24,7 @@ from eventlet import patcher
import OpenSSL
from oslo_log import log as logging
import six
from six.moves import http_client
from six.moves import urllib
from cinder.i18n import _, _LI
@ -74,7 +74,7 @@ def get_default_ca_certs():
class OpenSSLConnectionDelegator(object):
"""An OpenSSL.SSL.Connection delegator.
Supplies an additional 'makefile' method which httplib requires
Supplies an additional 'makefile' method which http_client requires
and is not present in OpenSSL.SSL.Connection.
Note: Since it is not possible to inherit from OpenSSL.SSL.Connection
a delegator must be used.
@ -89,7 +89,7 @@ class OpenSSLConnectionDelegator(object):
return socket._fileobject(self.connection, *args, **kwargs)
class HTTPSConnection(httplib.HTTPSConnection):
class HTTPSConnection(http_client.HTTPSConnection):
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=None, ca_certs=None, no_verification=False):
if not pywbemAvailable:
@ -101,9 +101,9 @@ class HTTPSConnection(httplib.HTTPSConnection):
else:
excp_lst = ()
try:
httplib.HTTPSConnection.__init__(self, host, port,
key_file=key_file,
cert_file=cert_file)
http_client.HTTPSConnection.__init__(self, host, port,
key_file=key_file,
cert_file=cert_file)
self.key_file = None if key_file is None else key_file
self.cert_file = None if cert_file is None else cert_file
@ -255,7 +255,7 @@ def wbem_request(url, data, creds, headers=None, debug=0, x509=None,
"""Send request over HTTP.
Send XML data over HTTP to the specified url. Return the
response in XML. Uses Python's build-in httplib. x509 may be a
response in XML. Uses Python's build-in http_client. x509 may be a
dictionary containing the location of the SSL certificate and key
files.
"""
@ -328,7 +328,7 @@ def wbem_request(url, data, creds, headers=None, debug=0, x509=None,
if response.status != 200:
raise pywbem.cim_http.Error('HTTP error')
except httplib.BadStatusLine as arg:
except http_client.BadStatusLine as arg:
msg = (_("Bad Status line returned: %(arg)s.")
% {'arg': arg})
raise pywbem.cim_http.Error(msg)

@ -15,7 +15,6 @@
"""Common class for Huawei 18000 storage drivers."""
import base64
import cookielib
import json
import socket
import time
@ -26,6 +25,7 @@ from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import units
import six
from six.moves import http_cookiejar
from six.moves import urllib
from cinder import context
@ -54,7 +54,7 @@ class RestCommon(object):
def __init__(self, configuration):
self.configuration = configuration
self.cookie = cookielib.CookieJar()
self.cookie = http_cookiejar.CookieJar()
self.url = None
self.productversion = None
self.headers = {"Connection": "keep-alive",

@ -22,7 +22,6 @@ Implementation of the class of ProphetStor DPL storage adapter of Federator.
import base64
import errno
import httplib
import json
import random
import time
@ -30,6 +29,7 @@ import time
from oslo_log import log as logging
from oslo_utils import units
import six
from six.moves import http_client
from cinder import exception
from cinder.i18n import _, _LI, _LW, _LE
@ -98,9 +98,9 @@ class DPLCommand(object):
retcode = errno.EINVAL
for i in range(CONNECTION_RETRY):
try:
connection = httplib.HTTPSConnection(self.ip,
self.port,
timeout=60)
connection = http_client.HTTPSConnection(self.ip,
self.port,
timeout=60)
if connection:
retcode = 0
break
@ -117,12 +117,12 @@ class DPLCommand(object):
while (connection and retry):
try:
connection.request(method, url, payload, header)
except httplib.CannotSendRequest as e:
except http_client.CannotSendRequest as e:
connection.close()
time.sleep(1)
connection = httplib.HTTPSConnection(self.ip,
self.port,
timeout=60)
connection = http_client.HTTPSConnection(self.ip,
self.port,
timeout=60)
retry -= 1
if connection:
if retry == 0:
@ -141,7 +141,7 @@ class DPLCommand(object):
if retcode == 0:
try:
response = connection.getresponse()
if response.status == httplib.SERVICE_UNAVAILABLE:
if response.status == http_client.SERVICE_UNAVAILABLE:
LOG.error(_LE('The Flexvisor service is unavailable.'))
time.sleep(1)
retry -= 1
@ -150,7 +150,7 @@ class DPLCommand(object):
else:
retcode = 0
break
except httplib.ResponseNotReady as e:
except http_client.ResponseNotReady as e:
time.sleep(1)
retry -= 1
retcode = errno.EFAULT
@ -162,23 +162,23 @@ class DPLCommand(object):
break
if (retcode == 0 and response.status in expected_status
and response.status == httplib.NOT_FOUND):
and response.status == http_client.NOT_FOUND):
retcode = errno.ENODATA
elif retcode == 0 and response.status not in expected_status:
LOG.error(_LE('%(method)s %(url)s unexpected response status: '
'%(response)s (expects: %(expects)s).'),
{'method': method,
'url': url,
'response': httplib.responses[response.status],
'response': http_client.responses[response.status],
'expects': expected_status})
if response.status == httplib.UNAUTHORIZED:
if response.status == http_client.UNAUTHORIZED:
raise exception.NotAuthorized
retcode = errno.EACCES
else:
retcode = errno.EIO
elif retcode == 0 and response.status is httplib.NOT_FOUND:
elif retcode == 0 and response.status is http_client.NOT_FOUND:
retcode = errno.ENODATA
elif retcode == 0 and response.status is httplib.ACCEPTED:
elif retcode == 0 and response.status is http_client.ACCEPTED:
retcode = errno.EAGAIN
try:
data = response.read()
@ -192,8 +192,8 @@ class DPLCommand(object):
e)
retcode = errno.ENOEXEC
elif (retcode == 0 and
response.status in [httplib.OK, httplib.CREATED] and
httplib.NO_CONTENT not in expected_status):
response.status in [http_client.OK, http_client.CREATED] and
http_client.NO_CONTENT not in expected_status):
try:
data = response.read()
data = json.loads(data)
@ -229,7 +229,8 @@ class DPLVolume(object):
def get_server_info(self):
method = 'GET'
url = ('/%s/%s/' % (DPL_VER_V1, DPL_OBJ_SYSTEM))
return self._execute(method, url, None, [httplib.OK, httplib.ACCEPTED])
return self._execute(method, url, None,
[http_client.OK, http_client.ACCEPTED])
def create_vdev(self, volumeID, volumeName, volumeDesc, poolID, volumeSize,
fthinprovision=True, maximum_snapshot=MAXSNAPSHOTS,
@ -253,7 +254,8 @@ class DPLVolume(object):
params['metadata'] = metadata
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def extend_vdev(self, volumeID, volumeName, volumeDesc, volumeSize,
maximum_snapshot=MAXSNAPSHOTS, snapshot_quota=None):
@ -274,7 +276,8 @@ class DPLVolume(object):
params['metadata'] = metadata
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def delete_vdev(self, volumeID, force=True):
method = 'DELETE'
@ -286,8 +289,8 @@ class DPLVolume(object):
params['metadata'] = metadata
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.NOT_FOUND,
httplib.NO_CONTENT])
[http_client.OK, http_client.ACCEPTED,
http_client.NOT_FOUND, http_client.NO_CONTENT])
def create_vdev_from_snapshot(self, vdevID, vdevDisplayName, vdevDesc,
snapshotID, poolID, fthinprovision=True,
@ -314,7 +317,8 @@ class DPLVolume(object):
params['copy'] = self._gen_snapshot_url(vdevID, snapshotID)
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def spawn_vdev_from_snapshot(self, new_vol_id, src_vol_id,
vol_display_name, description, snap_id):
@ -333,17 +337,19 @@ class DPLVolume(object):
params['copy'] = self._gen_snapshot_url(src_vol_id, snap_id)
return self._execute(method, url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def get_pools(self):
method = 'GET'
url = '/%s/%s/' % (DPL_VER_V1, DPL_OBJ_POOL)
return self._execute(method, url, None, [httplib.OK])
return self._execute(method, url, None, [http_client.OK])
def get_pool(self, poolid):
method = 'GET'
url = '/%s/%s/%s/' % (DPL_VER_V1, DPL_OBJ_POOL, poolid)
return self._execute(method, url, None, [httplib.OK, httplib.ACCEPTED])
return self._execute(method, url, None,
[http_client.OK, http_client.ACCEPTED])
def clone_vdev(self, SourceVolumeID, NewVolumeID, poolID, volumeName,
volumeDesc, volumeSize, fthinprovision=True,
@ -369,7 +375,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.CREATED, httplib.ACCEPTED])
[http_client.OK, http_client.CREATED,
http_client.ACCEPTED])
def create_vdev_snapshot(self, vdevid, snapshotid, snapshotname='',
snapshotdes='', isgroup=False):
@ -392,7 +399,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.CREATED, httplib.ACCEPTED])
[http_client.OK, http_client.CREATED,
http_client.ACCEPTED])
def get_vdev(self, vdevid):
method = 'GET'
@ -400,7 +408,8 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK, httplib.ACCEPTED, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NOT_FOUND])
def get_vdev_status(self, vdevid, eventid):
method = 'GET'
@ -409,7 +418,7 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK, httplib.NOT_FOUND])
[http_client.OK, http_client.NOT_FOUND])
def get_pool_status(self, poolid, eventid):
method = 'GET'
@ -418,7 +427,7 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK, httplib.NOT_FOUND])
[http_client.OK, http_client.NOT_FOUND])
def assign_vdev(self, vdevid, iqn, lunname, portal, lunid=0):
method = 'PUT'
@ -445,7 +454,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def assign_vdev_fc(self, vdevid, targetwwpn, initiatorwwpn, lunname,
lunid=-1):
@ -468,7 +478,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
def unassign_vdev(self, vdevid, initiatorIqn, targetIqn=''):
method = 'PUT'
@ -490,8 +501,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED,
httplib.NO_CONTENT, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NO_CONTENT, http_client.NOT_FOUND])
def unassign_vdev_fc(self, vdevid, targetwwpn, initiatorwwpns):
method = 'PUT'
@ -512,8 +523,8 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED,
httplib.NO_CONTENT, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NO_CONTENT, http_client.NOT_FOUND])
def delete_vdev_snapshot(self, objID, snapshotID, isGroup=False):
method = 'DELETE'
@ -529,8 +540,8 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK, httplib.ACCEPTED, httplib.NO_CONTENT,
httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NO_CONTENT, http_client.NOT_FOUND])
def rollback_vdev(self, vdevid, snapshotid):
method = 'PUT'
@ -541,7 +552,7 @@ class DPLVolume(object):
return self._execute(method,
url, params,
[httplib.OK, httplib.ACCEPTED])
[http_client.OK, http_client.ACCEPTED])
def list_vdev_snapshots(self, vdevid, isGroup=False):
method = 'GET'
@ -554,7 +565,7 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK])
[http_client.OK])
def query_vdev_snapshot(self, vdevid, snapshotID, isGroup=False):
method = 'GET'
@ -567,7 +578,7 @@ class DPLVolume(object):
return self._execute(method,
url, None,
[httplib.OK])
[http_client.OK])
def create_target(self, targetID, protocol, displayName, targetAddress,
description=''):
@ -584,19 +595,20 @@ class DPLVolume(object):
metadata['display_name'] = displayName
metadata['display_description'] = description
metadata['address'] = targetAddress
return self._execute(method, url, params, [httplib.OK])
return self._execute(method, url, params, [http_client.OK])
def get_target(self, targetID):
method = 'GET'
url = '/%s/%s/%s/' % (DPL_VER_V1, DPL_OBJ_EXPORT, targetID)
return self._execute(method, url, None, [httplib.OK])
return self._execute(method, url, None, [http_client.OK])
def delete_target(self, targetID):
method = 'DELETE'
url = '/%s/%s/%s/' % (DPL_VER_V1, DPL_OBJ_EXPORT, targetID)
return self._execute(method,
url, None,
[httplib.OK, httplib.ACCEPTED, httplib.NOT_FOUND])
[http_client.OK, http_client.ACCEPTED,
http_client.NOT_FOUND])
def get_target_list(self, type='target'):
# type = target/initiator
@ -605,7 +617,7 @@ class DPLVolume(object):
url = '/%s/%s/' % (DPL_VER_V1, DPL_OBJ_EXPORT)
else:
url = '/%s/%s/?type=%s' % (DPL_VER_V1, DPL_OBJ_EXPORT, type)
return self._execute(method, url, None, [httplib.OK])
return self._execute(method, url, None, [http_client.OK])
def get_sns_table(self, wwpn):
method = 'PUT'
@ -614,7 +626,7 @@ class DPLVolume(object):
params['metadata'] = {}
params['metadata']['protocol'] = 'fc'
params['metadata']['address'] = str(wwpn)
return self._execute(method, url, params, [httplib.OK])
return self._execute(method, url, params, [http_client.OK])
def create_vg(self, groupID, groupName, groupDesc='', listVolume=None,
maxSnapshots=MAXSNAPSHOTS, rotationSnapshot=True):
@ -634,7 +646,8 @@ class DPLVolume(object):
metadata['properties'] = properties
params['metadata'] = metadata
return self._execute(method, url, params,
[httplib.OK, httplib.ACCEPTED, httplib.CREATED])
[http_client.OK, http_client.ACCEPTED,
http_client.CREATED])
</