diff --git a/doc/source/conf.py b/doc/source/conf.py index 2899b228..406b869c 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -52,8 +52,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'glance_store' -copyright = u'2014, OpenStack Foundation' +project = 'glance_store' +copyright = '2014, OpenStack Foundation' # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py index 1fe06b41..feee5ac8 100644 --- a/glance_store/_drivers/cinder.py +++ b/glance_store/_drivers/cinder.py @@ -1047,7 +1047,7 @@ class Store(glance_store.driver.Store): image_metadata = {} location_url = 'cinder://%s' % volume.id if self.backend_group: - image_metadata['store'] = u"%s" % self.backend_group + image_metadata['store'] = self.backend_group location_url = 'cinder://%s/%s' % (self.backend_group, volume.id) diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index c9f9ec4e..6ff4eb55 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -22,6 +22,7 @@ import errno import logging import os import stat +import urllib import jsonschema from oslo_config import cfg @@ -29,7 +30,6 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import excutils from oslo_utils import units -from six.moves import urllib import glance_store from glance_store import capabilities @@ -793,7 +793,7 @@ class Store(glance_store.driver.Store): # Add store backend information to location metadata if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return ('file://%s' % filepath, bytes_written, diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index b0b70f57..79d3ab7f 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -14,11 +14,11 @@ # under the License. import logging +import urllib from oslo_config import cfg from oslo_utils import encodeutils -from six.moves import urllib import requests diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py index 9c1d45b4..b6328541 100644 --- a/glance_store/_drivers/rbd.py +++ b/glance_store/_drivers/rbd.py @@ -20,11 +20,11 @@ import contextlib import logging import math +import urllib from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import units -from six.moves import urllib from glance_store import capabilities from glance_store.common import utils @@ -651,7 +651,7 @@ class Store(driver.Store): # Add store backend information to location metadata metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (loc.get_uri(), image_size, diff --git a/glance_store/_drivers/s3.py b/glance_store/_drivers/s3.py index 6eeba86b..1a21ddd3 100644 --- a/glance_store/_drivers/s3.py +++ b/glance_store/_drivers/s3.py @@ -15,9 +15,11 @@ """Storage backend for S3 or Storage Servers that follow the S3 Protocol""" +import io import logging import math import re +import urllib from boto3 import session as boto_session from botocore import client as boto_client @@ -27,8 +29,6 @@ import eventlet from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import units -import six -from six.moves import urllib import glance_store from glance_store import capabilities @@ -706,7 +706,7 @@ class Store(glance_store.driver.Store): checksum.update(write_chunk) if verifier: verifier.update(write_chunk) - fp = six.BytesIO(write_chunk) + fp = io.BytesIO(write_chunk) fp.seek(0) part = UploadPart(mpu, fp, cstart + 1, len(write_chunk)) pool.spawn_n(run_upload, s3_client, bucket, key, part) @@ -721,7 +721,7 @@ class Store(glance_store.driver.Store): checksum.update(write_chunk) if verifier: verifier.update(write_chunk) - fp = six.BytesIO(write_chunk) + fp = io.BytesIO(write_chunk) fp.seek(0) part = UploadPart(mpu, fp, cstart + 1, len(write_chunk)) pool.spawn_n(run_upload, s3_client, bucket, key, part) @@ -888,7 +888,7 @@ class Store(glance_store.driver.Store): { 'PartNumber': pnum, 'ETag': etag - } for pnum, etag in six.iteritems(pedict) + } for pnum, etag in pedict.items() ] } diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py index c5d415c9..ab8b49fa 100644 --- a/glance_store/_drivers/swift/store.py +++ b/glance_store/_drivers/swift/store.py @@ -15,8 +15,11 @@ """Storage backend for SWIFT""" +import http.client +import io import logging import math +import urllib.parse from keystoneauth1.access import service_catalog as keystone_sc from keystoneauth1 import identity as ks_identity @@ -26,9 +29,6 @@ from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import excutils from oslo_utils import units -import six -from six.moves import http_client -from six.moves import urllib try: import swiftclient except ImportError: @@ -478,17 +478,13 @@ Related options: def swift_retry_iter(resp_iter, length, store, location, manager): - if not length and isinstance(resp_iter, six.BytesIO): - if six.PY3: - # On Python 3, io.BytesIO does not have a len attribute, instead - # go the end using seek to get the size of the file - pos = resp_iter.tell() - resp_iter.seek(0, 2) - length = resp_iter.tell() - resp_iter.seek(pos) - else: - # On Python 2, StringIO has a len attribute - length = resp_iter.len + if not length and isinstance(resp_iter, io.BytesIO): + # io.BytesIO does not have a len attribute, instead go the end using + # seek to get the size of the file + pos = resp_iter.tell() + resp_iter.seek(0, 2) + length = resp_iter.tell() + resp_iter.seek(pos) length = length if length else (resp_iter.len if hasattr(resp_iter, 'len') else 0) @@ -773,7 +769,7 @@ Store.OPTIONS = _SWIFT_OPTS + sutils.swift_opts + buffered.BUFFERING_OPTS def _is_slo(slo_header): - if (slo_header is not None and isinstance(slo_header, six.string_types) + if (slo_header is not None and isinstance(slo_header, str) and slo_header.lower() == 'true'): return True @@ -836,7 +832,7 @@ class BaseStore(driver.Store): location.container, location.obj, resp_chunk_size=self.CHUNKSIZE, headers=headers) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find object %s.") % location.obj LOG.warning(msg) raise exceptions.NotFound(message=msg) @@ -1065,19 +1061,19 @@ class BaseStore(driver.Store): metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (location.get_uri(credentials_included=include_creds), image_size, obj_etag, os_hash_value.hexdigest(), metadata) except swiftclient.ClientException as e: - if e.http_status == http_client.CONFLICT: + if e.http_status == http.client.CONFLICT: msg = _("Swift already has an image at this location") raise exceptions.Duplicate(message=msg) - elif e.http_status == http_client.REQUEST_ENTITY_TOO_LARGE: + elif e.http_status == http.client.REQUEST_ENTITY_TOO_LARGE: raise exceptions.StorageFull(message=e.msg) - msg = (_(u"Failed to add object to Swift.\n" + msg = (_("Failed to add object to Swift.\n" "Got error from Swift: %s.") % encodeutils.exception_to_unicode(e)) LOG.error(msg) @@ -1102,7 +1098,7 @@ class BaseStore(driver.Store): dlo_manifest = headers.get('x-object-manifest') slo_manifest = headers.get('x-static-large-object') except swiftclient.ClientException as e: - if e.http_status != http_client.NOT_FOUND: + if e.http_status != http.client.NOT_FOUND: raise if _is_slo(slo_manifest): @@ -1134,7 +1130,7 @@ class BaseStore(driver.Store): connection.delete_object(location.container, location.obj) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find image at URI.") raise exceptions.NotFound(message=msg) else: @@ -1155,7 +1151,7 @@ class BaseStore(driver.Store): try: connection.head_container(container) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: if store_conf.swift_store_create_container_on_put: try: msg = (_LI("Creating swift container %(container)s") % @@ -1541,7 +1537,7 @@ class MultiTenantStore(BaseStore): try: connection.post_container(location.container, headers=headers) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find image at URI.") raise exceptions.NotFound(message=msg) else: diff --git a/glance_store/_drivers/swift/utils.py b/glance_store/_drivers/swift/utils.py index 7285ba15..da034b47 100644 --- a/glance_store/_drivers/swift/utils.py +++ b/glance_store/_drivers/swift/utils.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging -import sys from oslo_config import cfg -from six.moves import configparser from glance_store import exceptions from glance_store.i18n import _, _LE @@ -104,16 +103,11 @@ _config_defaults = {'user_domain_id': 'default', 'project_domain_id': 'default', 'project_domain_name': 'default'} -if sys.version_info >= (3, 2): - parser_class = configparser.ConfigParser -else: - parser_class = configparser.SafeConfigParser - -class SwiftConfigParser(parser_class): +class SwiftConfigParser(configparser.ConfigParser): def get(self, *args, **kwargs): - value = super(parser_class, self).get(*args, **kwargs) + value = super(configparser.ConfigParser, self).get(*args, **kwargs) return self._process_quotes(value) @staticmethod @@ -127,10 +121,7 @@ class SwiftConfigParser(parser_class): return value -if sys.version_info >= (3,): - CONFIG = SwiftConfigParser(defaults=_config_defaults) -else: - CONFIG = parser_class(defaults=_config_defaults) +CONFIG = SwiftConfigParser(defaults=_config_defaults) LOG = logging.getLogger(__name__) diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index 2b304cd1..993f6d09 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -17,6 +17,7 @@ import logging import os +import urllib.parse from oslo_config import cfg from oslo_utils import excutils @@ -31,15 +32,9 @@ try: except ImportError: api = None -from six.moves import urllib -import six.moves.urllib.parse as urlparse - import requests from requests import adapters from requests.packages.urllib3.util import retry -import six -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range import glance_store from glance_store import capabilities @@ -349,9 +344,9 @@ class StoreLocation(location.StoreLocation): Creates a https url that can be used to upload/download data from a vmware store. """ - parsed_url = urlparse.urlparse(self.get_uri()) + parsed_url = urllib.parse.urlparse(self.get_uri()) new_url = parsed_url._replace(scheme='https') - return urlparse.urlunparse(new_url) + return urllib.parse.urlunparse(new_url) class Store(glance_store.Store): @@ -597,7 +592,7 @@ class Store(glance_store.Store): image_file = _Reader(image_file, hashing_algo, verifier) headers = {} if image_size > 0: - headers.update({'Content-Length': six.text_type(image_size)}) + headers.update({'Content-Length': str(image_size)}) data = image_file else: data = utils.chunkiter(image_file, CHUNKSIZE) @@ -656,7 +651,7 @@ class Store(glance_store.Store): metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (loc.get_uri(), image_file.size, @@ -804,9 +799,9 @@ class Store(glance_store.Store): # Note(sabari): The redirect url will have a scheme 'http(s)', but the # store only accepts url with scheme 'vsphere'. Thus, replacing with # store's scheme. - parsed_url = urlparse.urlparse(url) + parsed_url = urllib.parse.urlparse(url) new_url = parsed_url._replace(scheme='vsphere') - vsphere_url = urlparse.urlunparse(new_url) + vsphere_url = urllib.parse.urlunparse(new_url) return glance_store.location.Location(store_name, store_class, self.conf, diff --git a/glance_store/backend.py b/glance_store/backend.py index d2a54617..38cc7e05 100644 --- a/glance_store/backend.py +++ b/glance_store/backend.py @@ -19,7 +19,6 @@ import logging from oslo_config import cfg from oslo_utils import encodeutils -import six from stevedore import driver from stevedore import extension @@ -380,7 +379,7 @@ def check_location_metadata(val, key=''): for v in val: check_location_metadata(v, key='%s[%d]' % (key, ndx)) ndx = ndx + 1 - elif not isinstance(val, six.text_type): + elif not isinstance(val, str): raise exceptions.BackendException(_("The image metadata key %(key)s " "has an invalid type of %(type)s. " "Only dict, list, and unicode are " diff --git a/glance_store/driver.py b/glance_store/driver.py index b11012a2..9f85c7c7 100644 --- a/glance_store/driver.py +++ b/glance_store/driver.py @@ -24,7 +24,6 @@ from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import importutils from oslo_utils import units -import six from glance_store import capabilities from glance_store import exceptions @@ -93,7 +92,7 @@ class Store(capabilities.StoreCapability): self.configure_add() except exceptions.BadStoreConfiguration as e: self.unset_capabilities(capabilities.BitMasks.WRITE_ACCESS) - msg = (_(u"Failed to configure store correctly: %s " + msg = (_("Failed to configure store correctly: %s " "Disabling add method.") % encodeutils.exception_to_unicode(e)) LOG.warning(msg) @@ -257,8 +256,7 @@ def back_compat_add(store_add_fun): # everything is present, including hashing_algo back_compat_required = False elif ('hashing_algo' in kwargs or - (num_args >= p_algo + 1 and isinstance(args[p_algo], - six.string_types))): + (num_args >= p_algo + 1 and isinstance(args[p_algo], str))): # there is a hashing_algo argument present back_compat_required = False else: diff --git a/glance_store/exceptions.py b/glance_store/exceptions.py index 99bc1b0c..448e7548 100644 --- a/glance_store/exceptions.py +++ b/glance_store/exceptions.py @@ -15,8 +15,7 @@ """Glance Store exception subclasses""" -import six -import six.moves.urllib.parse as urlparse +import urllib.parse from glance_store.i18n import _ @@ -31,7 +30,7 @@ class UnsupportedBackend(BackendException): class RedirectException(Exception): def __init__(self, url): - self.url = urlparse.urlparse(url) + self.url = urllib.parse.urlparse(url) class GlanceStoreException(Exception): @@ -55,12 +54,6 @@ class GlanceStoreException(Exception): self.msg = message super(GlanceStoreException, self).__init__(message) - def __unicode__(self): - # NOTE(flwang): By default, self.msg is an instance of Message, which - # can't be converted by str(). Based on the definition of - # __unicode__, it should return unicode always. - return six.text_type(self.msg) - class MissingCredentialError(GlanceStoreException): message = _("Missing required credential: %(required)s") diff --git a/glance_store/location.py b/glance_store/location.py index d0d2f059..13aa5a85 100644 --- a/glance_store/location.py +++ b/glance_store/location.py @@ -38,9 +38,9 @@ credentials and is **not** user-facing. """ import logging +import urllib.parse from oslo_config import cfg -from six.moves import urllib from glance_store import exceptions from glance_store.i18n import _ diff --git a/glance_store/multi_backend.py b/glance_store/multi_backend.py index cfd80c09..e53222fb 100644 --- a/glance_store/multi_backend.py +++ b/glance_store/multi_backend.py @@ -20,7 +20,6 @@ import logging from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import units -import six from stevedore import driver from stevedore import extension @@ -495,7 +494,7 @@ def check_location_metadata(val, key=''): for v in val: check_location_metadata(v, key='%s[%d]' % (key, ndx)) ndx = ndx + 1 - elif not isinstance(val, six.text_type): + elif not isinstance(val, str): raise exceptions.BackendException(_("The image metadata key %(key)s " "has an invalid type of %(type)s. " "Only dict, list, and unicode are " diff --git a/glance_store/tests/unit/test_backend.py b/glance_store/tests/unit/test_backend.py index 7a3d03e2..8741826c 100644 --- a/glance_store/tests/unit/test_backend.py +++ b/glance_store/tests/unit/test_backend.py @@ -122,25 +122,25 @@ class TestStoreAddToBackend(base.StoreBaseTest): self._good_metadata(metadata) def test_string(self): - metadata = {'key': u'somevalue'} + metadata = {'key': 'somevalue'} self._good_metadata(metadata) def test_list(self): - m = {'key': [u'somevalue', u'2']} + m = {'key': ['somevalue', '2']} self._good_metadata(m) def test_unicode_dict(self): - inner = {'key1': u'somevalue', 'key2': u'somevalue'} + inner = {'key1': 'somevalue', 'key2': 'somevalue'} m = {'topkey': inner} self._good_metadata(m) def test_unicode_dict_list(self): - inner = {'key1': u'somevalue', 'key2': u'somevalue'} - m = {'topkey': inner, 'list': [u'somevalue', u'2'], 'u': u'2'} + inner = {'key1': 'somevalue', 'key2': 'somevalue'} + m = {'topkey': inner, 'list': ['somevalue', '2'], 'u': '2'} self._good_metadata(m) def test_nested_dict(self): - inner = {'key1': u'somevalue', 'key2': u'somevalue'} + inner = {'key1': 'somevalue', 'key2': 'somevalue'} inner = {'newkey': inner} inner = {'anotherkey': inner} m = {'topkey': inner} @@ -151,9 +151,9 @@ class TestStoreAddToBackend(base.StoreBaseTest): self._bad_metadata(metadata) def test_bad_nonunicode_dict_list(self): - inner = {'key1': u'somevalue', 'key2': u'somevalue', + inner = {'key1': 'somevalue', 'key2': 'somevalue', 'k3': [1, object()]} - m = {'topkey': inner, 'list': [u'somevalue', u'2'], 'u': u'2'} + m = {'topkey': inner, 'list': ['somevalue', '2'], 'u': '2'} self._bad_metadata(m) def test_bad_metadata_not_dict(self): diff --git a/glance_store/tests/unit/test_cinder_store.py b/glance_store/tests/unit/test_cinder_store.py index efd54197..68abba3a 100644 --- a/glance_store/tests/unit/test_cinder_store.py +++ b/glance_store/tests/unit/test_cinder_store.py @@ -43,10 +43,10 @@ class TestCinderStore(base.StoreBaseTest, self.store.READ_CHUNKSIZE = 4096 self.store.WRITE_CHUNKSIZE = 4096 - fake_sc = [{u'endpoints': [{u'publicURL': u'http://foo/public_url'}], - u'endpoints_links': [], - u'name': u'cinder', - u'type': u'volumev3'}] + fake_sc = [{'endpoints': [{'publicURL': 'http://foo/public_url'}], + 'endpoints_links': [], + 'name': 'cinder', + 'type': 'volumev3'}] self.context = mock.MagicMock(service_catalog=fake_sc, user_id='fake_user', auth_token='fake_token', diff --git a/glance_store/tests/unit/test_exceptions.py b/glance_store/tests/unit/test_exceptions.py index d9fe1e18..ed2bf052 100644 --- a/glance_store/tests/unit/test_exceptions.py +++ b/glance_store/tests/unit/test_exceptions.py @@ -14,7 +14,6 @@ # under the License. from oslo_utils import encodeutils from oslotest import base -import six import glance_store @@ -23,11 +22,11 @@ class TestExceptions(base.BaseTestCase): """Test routines in glance_store.common.utils.""" def test_backend_exception(self): msg = glance_store.BackendException() - self.assertIn(u'', encodeutils.exception_to_unicode(msg)) + self.assertIn('', encodeutils.exception_to_unicode(msg)) def test_unsupported_backend_exception(self): msg = glance_store.UnsupportedBackend() - self.assertIn(u'', encodeutils.exception_to_unicode(msg)) + self.assertIn('', encodeutils.exception_to_unicode(msg)) def test_redirect_exception(self): # Just checks imports work ok @@ -54,4 +53,4 @@ class TestExceptions(base.BaseTestCase): def test_non_unicode_error_msg(self): exc = glance_store.NotFound(str('test')) self.assertIsInstance(encodeutils.exception_to_unicode(exc), - six.text_type) + str) diff --git a/glance_store/tests/unit/test_filesystem_store.py b/glance_store/tests/unit/test_filesystem_store.py index db61e891..5dee2669 100644 --- a/glance_store/tests/unit/test_filesystem_store.py +++ b/glance_store/tests/unit/test_filesystem_store.py @@ -15,8 +15,10 @@ """Tests the filesystem backend store""" +import builtins import errno import hashlib +import io import json import os import stat @@ -26,10 +28,6 @@ import uuid import fixtures from oslo_utils.secretutils import md5 from oslo_utils import units -import six -from six.moves import builtins -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range from glance_store._drivers import filesystem from glance_store import exceptions @@ -67,7 +65,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_file_size = 10 expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) self.store.FILESYSTEM_STORE_METADATA = in_metadata return self.store.add(expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -77,7 +75,7 @@ class TestStore(base.StoreBaseTest, # First add an image... image_id = str(uuid.uuid4()) file_contents = b"chunk00000remainder" - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, multihash, _ = self.store.add( image_id, image_file, len(file_contents), self.hash_algo) @@ -103,7 +101,7 @@ class TestStore(base.StoreBaseTest, # First add an image... image_id = str(uuid.uuid4()) file_contents = b"chunk00000remainder" - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, multihash, _ = self.store.add( image_id, image_file, len(file_contents), self.hash_algo) @@ -160,7 +158,7 @@ class TestStore(base.StoreBaseTest, expected_multihash = hashlib.sha256(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (self.test_dir, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, multihash, _ = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -254,7 +252,7 @@ class TestStore(base.StoreBaseTest, group='glance_store') self.store.configure() - image_file = six.BytesIO(content) + image_file = io.BytesIO(content) image_id = str(uuid.uuid4()) with mock.patch.object(builtins, 'open') as popen: self.store.add(image_id, image_file, size, self.hash_algo) @@ -273,7 +271,7 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) file_size = units.Ki # 1K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) self.store.add(image_id, image_file, file_size, self.hash_algo, verifier=verifier) @@ -310,7 +308,7 @@ class TestStore(base.StoreBaseTest, group="glance_store") expected_file_size = 10 expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, multihash, metadata = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -326,11 +324,11 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) location, size, checksum, multihash, _ = self.store.add( image_id, image_file, file_size, self.hash_algo) - image_file = six.BytesIO(b"nevergonnamakeit") + image_file = io.BytesIO(b"nevergonnamakeit") self.assertRaises(exceptions.Duplicate, self.store.add, image_id, image_file, 0, self.hash_algo) @@ -341,7 +339,7 @@ class TestStore(base.StoreBaseTest, file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size path = os.path.join(self.test_dir, image_id) - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) with mock.patch.object(builtins, 'open') as popen: e = IOError() @@ -392,7 +390,7 @@ class TestStore(base.StoreBaseTest, file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size path = os.path.join(self.test_dir, image_id) - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) def fake_Error(size): raise AttributeError() @@ -413,7 +411,7 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, multihash, _ = self.store.add( image_id, image_file, file_size, self.hash_algo) @@ -445,7 +443,7 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, multihash, _ = self.store.add( image_id, image_file, file_size, self.hash_algo) @@ -611,7 +609,7 @@ class TestStore(base.StoreBaseTest, expected_multihash = hashlib.sha256(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (store_map[1], expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, multihash, _ = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -659,7 +657,7 @@ class TestStore(base.StoreBaseTest, expected_multihash = hashlib.sha256(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (store_map[1], expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, multihash, _ = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -709,7 +707,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_file_size = 5 * units.Ki # 5K expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) self.assertRaises(exceptions.StorageFull, self.store.add, @@ -770,7 +768,7 @@ class TestStore(base.StoreBaseTest, expected_multihash = hashlib.sha256(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (store, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, multihash, _ = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) @@ -813,7 +811,7 @@ class TestStore(base.StoreBaseTest, expected_multihash = hashlib.sha256(expected_file_contents).hexdigest() expected_location = "file://%s/%s" % (store, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, multihash, _ = self.store.add( expected_image_id, image_file, expected_file_size, self.hash_algo) diff --git a/glance_store/tests/unit/test_multistore_cinder.py b/glance_store/tests/unit/test_multistore_cinder.py index 9161275b..1907efa3 100644 --- a/glance_store/tests/unit/test_multistore_cinder.py +++ b/glance_store/tests/unit/test_multistore_cinder.py @@ -72,10 +72,10 @@ class TestMultiCinderStore(base.MultiStoreBaseTest, self.store.READ_CHUNKSIZE = 4096 self.store.WRITE_CHUNKSIZE = 4096 - fake_sc = [{u'endpoints': [{u'publicURL': u'http://foo/public_url'}], - u'endpoints_links': [], - u'name': u'cinder', - u'type': u'volumev3'}] + fake_sc = [{'endpoints': [{'publicURL': 'http://foo/public_url'}], + 'endpoints_links': [], + 'name': 'cinder', + 'type': 'volumev3'}] self.context = mock.MagicMock(service_catalog=fake_sc, user_id='fake_user', auth_token='fake_token', diff --git a/glance_store/tests/unit/test_multistore_filesystem.py b/glance_store/tests/unit/test_multistore_filesystem.py index 5f8d4ea1..9de576e7 100644 --- a/glance_store/tests/unit/test_multistore_filesystem.py +++ b/glance_store/tests/unit/test_multistore_filesystem.py @@ -15,7 +15,9 @@ """Tests the filesystem backend store""" +import builtins import errno +import io import json import os import stat @@ -26,10 +28,6 @@ import fixtures from oslo_config import cfg from oslo_utils.secretutils import md5 from oslo_utils import units -import six -from six.moves import builtins -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range import glance_store as store from glance_store._drivers import filesystem @@ -91,7 +89,7 @@ class TestMultiStore(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_file_size = 10 expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) self.store.FILESYSTEM_STORE_METADATA = in_metadata return self.store.add(expected_image_id, image_file, expected_file_size) @@ -105,12 +103,12 @@ class TestMultiStore(base.MultiStoreBaseTest, # First add an image... image_id = str(uuid.uuid4()) file_contents = b"chunk00000remainder" - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, metadata = self.store.add( image_id, image_file, len(file_contents)) # Check metadata contains 'file1' as a store - self.assertEqual(u"file1", metadata['store']) + self.assertEqual("file1", metadata['store']) # Now read it back... uri = "file:///%s/%s" % (self.test_dir, image_id) @@ -134,13 +132,13 @@ class TestMultiStore(base.MultiStoreBaseTest, # First add an image... image_id = str(uuid.uuid4()) file_contents = b"chunk00000remainder" - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, metadata = self.store.add(image_id, image_file, len(file_contents)) # Check metadata contains 'file1' as a store - self.assertEqual(u"file1", metadata['store']) + self.assertEqual("file1", metadata['store']) # Now read it back... uri = "file:///%s/%s" % (self.test_dir, image_id) @@ -193,7 +191,7 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (self.test_dir, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, metadata = self.store.add(expected_image_id, image_file, @@ -202,7 +200,7 @@ class TestMultiStore(base.MultiStoreBaseTest, self.assertEqual(expected_location, loc) self.assertEqual(expected_file_size, size) self.assertEqual(expected_checksum, checksum) - self.assertEqual(u"file1", metadata['store']) + self.assertEqual("file1", metadata['store']) uri = "file:///%s/%s" % (self.test_dir, expected_image_id) loc = location.get_location_from_uri_and_backend( @@ -234,7 +232,7 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (self.test_dir, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, metadata = self.store.add(expected_image_id, image_file, @@ -243,7 +241,7 @@ class TestMultiStore(base.MultiStoreBaseTest, self.assertEqual(expected_location, loc) self.assertEqual(expected_file_size, size) self.assertEqual(expected_checksum, checksum) - self.assertEqual(u"file2", metadata['store']) + self.assertEqual("file2", metadata['store']) uri = "file:///%s/%s" % (self.test_dir, expected_image_id) loc = location.get_location_from_uri_and_backend( @@ -263,20 +261,20 @@ class TestMultiStore(base.MultiStoreBaseTest, in_metadata = [{'id': 'abcdefg', 'mountpoint': '/xyz/images'}] location, size, checksum, metadata = self._store_image(in_metadata) - self.assertEqual({'store': u'file1'}, metadata) + self.assertEqual({'store': 'file1'}, metadata) def test_add_check_metadata_list_with_invalid_mountpoint_locations(self): in_metadata = [{'id': 'abcdefg', 'mountpoint': '/xyz/images'}, {'id': 'xyz1234', 'mountpoint': '/pqr/images'}] location, size, checksum, metadata = self._store_image(in_metadata) - self.assertEqual({'store': u'file1'}, metadata) + self.assertEqual({'store': 'file1'}, metadata) def test_add_check_metadata_list_with_valid_mountpoint_locations(self): in_metadata = [{'id': 'abcdefg', 'mountpoint': '/tmp'}, {'id': 'xyz1234', 'mountpoint': '/xyz'}] location, size, checksum, metadata = self._store_image(in_metadata) self.assertEqual(in_metadata[0], metadata) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) def test_add_check_metadata_bad_nosuch_file(self): expected_image_id = str(uuid.uuid4()) @@ -287,13 +285,13 @@ class TestMultiStore(base.MultiStoreBaseTest, group="file1") expected_file_size = 10 expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, metadata = self.store.add(expected_image_id, image_file, expected_file_size) - self.assertEqual({'store': u'file1'}, metadata) + self.assertEqual({'store': 'file1'}, metadata) def test_add_already_existing(self): """ @@ -304,14 +302,14 @@ class TestMultiStore(base.MultiStoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) location, size, checksum, metadata = self.store.add(image_id, image_file, file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) - image_file = six.BytesIO(b"nevergonnamakeit") + image_file = io.BytesIO(b"nevergonnamakeit") self.assertRaises(exceptions.Duplicate, self.store.add, image_id, image_file, 0) @@ -322,7 +320,7 @@ class TestMultiStore(base.MultiStoreBaseTest, file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size path = os.path.join(self.test_dir, image_id) - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) with mock.patch.object(builtins, 'open') as popen: e = IOError() @@ -370,7 +368,7 @@ class TestMultiStore(base.MultiStoreBaseTest, file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size path = os.path.join(self.test_dir, image_id) - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) def fake_Error(size): raise AttributeError() @@ -389,12 +387,12 @@ class TestMultiStore(base.MultiStoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, metadata = self.store.add(image_id, image_file, file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) # Now check that we can delete it uri = "file:///%s/%s" % (self.test_dir, image_id) @@ -418,12 +416,12 @@ class TestMultiStore(base.MultiStoreBaseTest, image_id = str(uuid.uuid4()) file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) loc, size, checksum, metadata = self.store.add(image_id, image_file, file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) uri = "file:///%s/%s" % (self.test_dir, image_id) loc = location.get_location_from_uri_and_backend(uri, "file1", @@ -589,12 +587,12 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (store_map[1], expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, metadata = self.store.add(expected_image_id, image_file, expected_file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) self.assertEqual(expected_location, loc) self.assertEqual(expected_file_size, size) @@ -637,12 +635,12 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (store_map[1], expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) loc, size, checksum, metadata = self.store.add(expected_image_id, image_file, expected_file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) self.assertEqual(expected_location, loc) self.assertEqual(expected_file_size, size) @@ -689,7 +687,7 @@ class TestMultiStore(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_file_size = 5 * units.Ki # 5K expected_file_contents = b"*" * expected_file_size - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) self.assertRaises(exceptions.StorageFull, self.store.add, expected_image_id, image_file, @@ -749,12 +747,12 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (store, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, metadata = self.store.add(expected_image_id, image_file, expected_file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) self.assertEqual(expected_location, location) self.assertEqual(expected_file_size, size) @@ -794,12 +792,12 @@ class TestMultiStore(base.MultiStoreBaseTest, usedforsecurity=False).hexdigest() expected_location = "file://%s/%s" % (store, expected_image_id) - image_file = six.BytesIO(expected_file_contents) + image_file = io.BytesIO(expected_file_contents) location, size, checksum, metadata = self.store.add(expected_image_id, image_file, expected_file_size) - self.assertEqual(u"file1", metadata["store"]) + self.assertEqual("file1", metadata["store"]) self.assertEqual(expected_location, location) self.assertEqual(expected_file_size, size) diff --git a/glance_store/tests/unit/test_multistore_rbd.py b/glance_store/tests/unit/test_multistore_rbd.py index 822c1b5e..4113e6c4 100644 --- a/glance_store/tests/unit/test_multistore_rbd.py +++ b/glance_store/tests/unit/test_multistore_rbd.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +import io from unittest import mock from oslo_config import cfg from oslo_utils import units -import six import glance_store as store from glance_store._drivers import rbd as rbd_store @@ -222,7 +222,7 @@ class TestMultiStore(base.MultiStoreBaseTest, self.conf) # Provide enough data to get more than one chunk iteration. self.data_len = 3 * units.Ki - self.data_iter = six.BytesIO(b'*' * self.data_len) + self.data_iter = io.BytesIO(b'*' * self.data_len) def test_location_url_prefix_is_set(self): expected_url_prefix = "rbd://" @@ -253,7 +253,7 @@ class TestMultiStore(base.MultiStoreBaseTest, self.conf) # Provide enough data to get more than one chunk iteration. self.data_len = 3 * units.Ki - self.data_iter = six.BytesIO(b'*' * self.data_len) + self.data_iter = io.BytesIO(b'*' * self.data_len) self.store.chunk_size = units.Ki with mock.patch.object(rbd_store.rbd.Image, 'resize') as resize: with mock.patch.object(rbd_store.rbd.Image, 'write') as write: diff --git a/glance_store/tests/unit/test_multistore_s3.py b/glance_store/tests/unit/test_multistore_s3.py index 2485e4a9..60c5e803 100644 --- a/glance_store/tests/unit/test_multistore_s3.py +++ b/glance_store/tests/unit/test_multistore_s3.py @@ -16,6 +16,7 @@ """Tests the Multiple S3 backend store""" import hashlib +import io from unittest import mock import uuid @@ -26,7 +27,6 @@ from botocore import stub from oslo_config import cfg from oslo_utils.secretutils import md5 from oslo_utils import units -import six import glance_store as store from glance_store._drivers import s3 @@ -137,7 +137,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, """Test a "normal" retrieval of an image in chunks.""" bucket, key = 'glance', FAKE_UUID fixture_object = { - 'Body': six.BytesIO(b"*" * FIVE_KB), + 'Body': io.BytesIO(b"*" * FIVE_KB), 'ContentLength': FIVE_KB } fake_s3_client = botocore.session.get_session().create_client('s3') @@ -220,7 +220,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -273,7 +273,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -327,7 +327,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, 'http://s3-region2.com', S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -369,7 +369,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_s3_size = FIVE_KB expected_s3_contents = b"*" * expected_s3_size - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') verifier = mock.MagicMock(name='mock_verifier') @@ -401,7 +401,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -483,7 +483,7 @@ class TestMultiS3Store(base.MultiStoreBaseTest, """Tests that adding an image with an existing identifier raises an appropriate exception """ - image_s3 = six.BytesIO(b"never_gonna_make_it") + image_s3 = io.BytesIO(b"never_gonna_make_it") fake_s3_client = botocore.session.get_session().create_client('s3') diff --git a/glance_store/tests/unit/test_multistore_vmware.py b/glance_store/tests/unit/test_multistore_vmware.py index 4a5df7a6..1fc9c0bc 100644 --- a/glance_store/tests/unit/test_multistore_vmware.py +++ b/glance_store/tests/unit/test_multistore_vmware.py @@ -16,6 +16,7 @@ """Tests the Multiple VMware Datastore backend store""" import hashlib +import io from unittest import mock import uuid @@ -26,7 +27,6 @@ from oslo_vmware import api from oslo_vmware import exceptions as vmware_exceptions from oslo_vmware.objects import datacenter as oslo_datacenter from oslo_vmware.objects import datastore as oslo_datastore -import six import glance_store as store import glance_store._drivers.vmware_datastore as vm_store @@ -130,7 +130,7 @@ class TestMultiStore(base.MultiStoreBaseTest, self.store.configure() def _mock_http_connection(self): - return mock.patch('six.moves.http_client.HTTPConnection') + return mock.patch('http.client.HTTPConnection') def test_location_url_prefix_is_set(self): expected_url_prefix = "vsphere://127.0.0.1/openstack_glance" @@ -181,7 +181,7 @@ class TestMultiStore(base.MultiStoreBaseTest, fake_size.__get__ = mock.Mock(return_value=expected_size) expected_cookie = 'vmware_soap_session=fake-uuid' fake_cookie.return_value = expected_cookie - expected_headers = {'Content-Length': six.text_type(expected_size), + expected_headers = {'Content-Length': str(expected_size), 'Cookie': expected_cookie} with mock.patch('hashlib.md5') as md5: md5.return_value = hash_code @@ -190,7 +190,7 @@ class TestMultiStore(base.MultiStoreBaseTest, VMWARE_DS['vmware_store_image_dir'], expected_image_id, VMWARE_DS['vmware_datastores']) - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, metadata = self.store.add( @@ -227,7 +227,7 @@ class TestMultiStore(base.MultiStoreBaseTest, VMWARE_DS['vmware_store_image_dir'], expected_image_id, VMWARE_DS['vmware_datastores']) - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, metadata = self.store.add( @@ -247,7 +247,7 @@ class TestMultiStore(base.MultiStoreBaseTest, image_id = str(uuid.uuid4()) size = FIVE_KB contents = b"*" * size - image = six.BytesIO(contents) + image = io.BytesIO(contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, multihash, metadata = self.store.add( @@ -264,7 +264,7 @@ class TestMultiStore(base.MultiStoreBaseTest, image_id = str(uuid.uuid4()) size = FIVE_KB contents = b"*" * size - image = six.BytesIO(contents) + image = io.BytesIO(contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, multihash, metadata = self.store.add( @@ -330,7 +330,7 @@ class TestMultiStore(base.MultiStoreBaseTest, def test_reader_full(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) expected_checksum = secretutils.md5(content, usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(content).hexdigest() @@ -343,7 +343,7 @@ class TestMultiStore(base.MultiStoreBaseTest, def test_reader_partial(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) expected_checksum = secretutils.md5(b'X', usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(b'X').hexdigest() @@ -356,7 +356,7 @@ class TestMultiStore(base.MultiStoreBaseTest, def test_reader_with_verifier(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) verifier = mock.MagicMock(name='mock_verifier') reader = vm_store._Reader(image, self.hash_algo, verifier) reader.read() @@ -413,7 +413,7 @@ class TestMultiStore(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response(status_code=401) @@ -428,7 +428,7 @@ class TestMultiStore(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with self._mock_http_connection() as HttpConn: HttpConn.return_value = utils.fake_response(status_code=500, @@ -470,7 +470,7 @@ class TestMultiStore(base.MultiStoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with mock.patch('requests.Session.request') as HttpConn: HttpConn.request.side_effect = IOError diff --git a/glance_store/tests/unit/test_rbd_store.py b/glance_store/tests/unit/test_rbd_store.py index cbd34acd..c1c3f056 100644 --- a/glance_store/tests/unit/test_rbd_store.py +++ b/glance_store/tests/unit/test_rbd_store.py @@ -14,11 +14,11 @@ # under the License. import hashlib +import io from unittest import mock from oslo_utils.secretutils import md5 from oslo_utils import units -import six from glance_store._drivers import rbd as rbd_store from glance_store import exceptions @@ -315,7 +315,7 @@ class TestStore(base.StoreBaseTest, self.conf) # Provide enough data to get more than one chunk iteration. self.data_len = 3 * units.Ki - self.data_iter = six.BytesIO(b'*' * self.data_len) + self.data_iter = io.BytesIO(b'*' * self.data_len) self.hash_algo = 'sha256' def test_thin_provisioning_is_disabled_by_default(self): @@ -409,7 +409,7 @@ class TestStore(base.StoreBaseTest, image_id = 'fake_image_id' file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) with mock.patch.object(rbd_store.rbd.Image, 'write'): self.store.add(image_id, image_file, file_size, self.hash_algo, @@ -422,7 +422,7 @@ class TestStore(base.StoreBaseTest, image_id = 'fake_image_id' file_size = 5 * units.Ki # 5K file_contents = b"*" * file_size - image_file = six.BytesIO(file_contents) + image_file = io.BytesIO(file_contents) expected_checksum = md5(file_contents, usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(file_contents).hexdigest() @@ -496,7 +496,7 @@ class TestStore(base.StoreBaseTest, self.store.configure() image_id = 'fake_image_id' - image_file = six.BytesIO(content) + image_file = io.BytesIO(content) expected_checksum = md5(content, usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(content).hexdigest() diff --git a/glance_store/tests/unit/test_s3_store.py b/glance_store/tests/unit/test_s3_store.py index 8a5f0465..7fa7a135 100644 --- a/glance_store/tests/unit/test_s3_store.py +++ b/glance_store/tests/unit/test_s3_store.py @@ -16,6 +16,7 @@ """Tests the S3 backend store""" import hashlib +import io from unittest import mock import uuid @@ -25,7 +26,6 @@ from botocore import exceptions as boto_exceptions from botocore import stub from oslo_utils.secretutils import md5 from oslo_utils import units -import six from glance_store._drivers import s3 from glance_store import capabilities @@ -89,7 +89,7 @@ class TestStore(base.StoreBaseTest, """Test a "normal" retrieval of an image in chunks.""" bucket, key = 'glance', FAKE_UUID fixture_object = { - 'Body': six.BytesIO(b"*" * FIVE_KB), + 'Body': io.BytesIO(b"*" * FIVE_KB), 'ContentLength': FIVE_KB } fake_s3_client = botocore.session.get_session().create_client('s3') @@ -169,7 +169,7 @@ class TestStore(base.StoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -221,7 +221,7 @@ class TestStore(base.StoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -262,7 +262,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_s3_size = FIVE_KB expected_s3_contents = b"*" * expected_s3_size - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') verifier = mock.MagicMock(name='mock_verifier') @@ -294,7 +294,7 @@ class TestStore(base.StoreBaseTest, S3_CONF['s3_store_host'], S3_CONF['s3_store_bucket'], expected_image_id) - image_s3 = six.BytesIO(expected_s3_contents) + image_s3 = io.BytesIO(expected_s3_contents) fake_s3_client = botocore.session.get_session().create_client('s3') @@ -375,7 +375,7 @@ class TestStore(base.StoreBaseTest, """Tests that adding an image with an existing identifier raises an appropriate exception """ - image_s3 = six.BytesIO(b"never_gonna_make_it") + image_s3 = io.BytesIO(b"never_gonna_make_it") fake_s3_client = botocore.session.get_session().create_client('s3') diff --git a/glance_store/tests/unit/test_swift_store.py b/glance_store/tests/unit/test_swift_store.py index 73649239..eb571387 100644 --- a/glance_store/tests/unit/test_swift_store.py +++ b/glance_store/tests/unit/test_swift_store.py @@ -20,6 +20,9 @@ from unittest import mock import fixtures import hashlib +import http.client +import importlib +import io import tempfile import uuid @@ -28,11 +31,6 @@ from oslo_utils import encodeutils from oslo_utils.secretutils import md5 from oslo_utils import units import requests_mock -import six -from six import moves -from six.moves import http_client -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range import swiftclient from glance_store._drivers.swift import buffered @@ -92,15 +90,15 @@ class SwiftTests(object): }, } fixture_objects = { - 'glance/%s' % FAKE_UUID: six.BytesIO(b"*" * FIVE_KB), - 'glance/%s' % FAKE_UUID2: six.BytesIO(b"*" * FIVE_KB), - 'glance/%s' % FAKE_UUID3: six.BytesIO(), + 'glance/%s' % FAKE_UUID: io.BytesIO(b"*" * FIVE_KB), + 'glance/%s' % FAKE_UUID2: io.BytesIO(b"*" * FIVE_KB), + 'glance/%s' % FAKE_UUID3: io.BytesIO(), } def fake_head_container(url, token, container, **kwargs): if container not in fixture_containers: msg = "No container %s found" % container - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) return fixture_container_headers @@ -132,7 +130,7 @@ class SwiftTests(object): fixture_objects[fixture_key] = None return etag if hasattr(contents, 'read'): - fixture_object = six.BytesIO() + fixture_object = io.BytesIO() read_len = 0 chunk = contents.read(CHUNKSIZE) checksum = md5(usedforsecurity=False) @@ -143,7 +141,7 @@ class SwiftTests(object): chunk = contents.read(CHUNKSIZE) etag = checksum.hexdigest() else: - fixture_object = six.BytesIO(contents) + fixture_object = io.BytesIO(contents) read_len = len(contents) etag = md5(fixture_object.getvalue(), usedforsecurity=False).hexdigest() @@ -151,7 +149,7 @@ class SwiftTests(object): msg = ('Image size:%d exceeds Swift max:%d' % (read_len, MAX_SWIFT_OBJECT_SIZE)) raise swiftclient.ClientException( - msg, http_status=http_client.REQUEST_ENTITY_TOO_LARGE) + msg, http_status=http.client.REQUEST_ENTITY_TOO_LARGE) fixture_objects[fixture_key] = fixture_object fixture_headers[fixture_key] = { 'content-length': read_len, @@ -161,14 +159,14 @@ class SwiftTests(object): msg = ("Object PUT failed - Object with key %s already exists" % fixture_key) raise swiftclient.ClientException( - msg, http_status=http_client.CONFLICT) + msg, http_status=http.client.CONFLICT) def fake_get_object(conn, container, name, **kwargs): # GET returns the tuple (list of headers, file object) fixture_key = "%s/%s" % (container, name) if fixture_key not in fixture_headers: msg = "Object GET failed" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) byte_range = None @@ -185,7 +183,7 @@ class SwiftTests(object): chunk_keys = sorted([k for k in fixture_headers.keys() if k.startswith(fixture_key) and k != fixture_key]) - result = six.BytesIO() + result = io.BytesIO() for key in chunk_keys: result.write(fixture_objects[key].getvalue()) else: @@ -193,7 +191,7 @@ class SwiftTests(object): if byte_range is not None: start = int(byte_range.split('=')[1].strip('-')) - result = six.BytesIO(result.getvalue()[start:]) + result = io.BytesIO(result.getvalue()[start:]) fixture_headers[fixture_key]['content-length'] = len( result.getvalue()) @@ -206,7 +204,7 @@ class SwiftTests(object): return fixture_headers[fixture_key] except KeyError: msg = "Object HEAD failed - Object does not exist" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) def fake_delete_object(url, token, container, name, **kwargs): @@ -214,7 +212,7 @@ class SwiftTests(object): fixture_key = "%s/%s" % (container, name) if fixture_key not in fixture_headers: msg = "Object DELETE failed - Object does not exist" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) else: del fixture_headers[fixture_key] @@ -342,7 +340,7 @@ class SwiftTests(object): (image_swift, image_size) = self.store.get(loc, context=ctxt) resp_full = b''.join([chunk for chunk in image_swift.wrapped]) resp_half = resp_full[:len(resp_full) // 2] - resp_half = six.BytesIO(resp_half) + resp_half = io.BytesIO(resp_half) manager = self.store.get_manager(loc.store_location, ctxt) image_swift.wrapped = swift.swift_retry_iter(resp_half, image_size, @@ -418,7 +416,7 @@ class SwiftTests(object): mock.Mock(return_value=False)) def test_add(self): """Test that we can add an image via the swift backend.""" - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -431,7 +429,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = "swift+https://tenant%%3Auser1:key@localhost:8080/glance/%s" expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -460,7 +458,7 @@ class SwiftTests(object): conf = copy.deepcopy(SWIFT_CONF) conf['default_swift_reference'] = 'store_2' self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -468,7 +466,7 @@ class SwiftTests(object): expected_swift_size = FIVE_KB expected_swift_contents = b"*" * expected_swift_size expected_image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 loc = 'swift+config://store_2/glance/%s' @@ -484,7 +482,7 @@ class SwiftTests(object): conf = copy.deepcopy(SWIFT_CONF) conf['default_swift_reference'] = 'store_2' self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -492,7 +490,7 @@ class SwiftTests(object): def fake_put_object_entity_too_large(*args, **kwargs): msg = "Test Out of Quota" raise swiftclient.ClientException( - msg, http_status=http_client.REQUEST_ENTITY_TOO_LARGE) + msg, http_status=http.client.REQUEST_ENTITY_TOO_LARGE) self.useFixture(fixtures.MockPatch( 'swiftclient.client.put_object', fake_put_object_entity_too_large)) @@ -500,7 +498,7 @@ class SwiftTests(object): expected_swift_size = FIVE_KB expected_swift_contents = b"*" * expected_swift_size expected_image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) self.assertRaises(exceptions.StorageFull, self.store.add, expected_image_id, image_swift, @@ -516,7 +514,7 @@ class SwiftTests(object): expected_container = 'container_' + expected_image_id loc = 'swift+https://some_endpoint/%s/%s' expected_location = loc % (expected_container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -577,13 +575,13 @@ class SwiftTests(object): expected_multihash = \ hashlib.sha256(expected_swift_contents).hexdigest() - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 conf['default_swift_reference'] = variation self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -615,13 +613,13 @@ class SwiftTests(object): conf['swift_store_create_container_on_put'] = False conf['swift_store_container'] = 'noexist' self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -656,7 +654,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/noexist/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -665,7 +663,7 @@ class SwiftTests(object): conf['swift_store_create_container_on_put'] = True conf['swift_store_container'] = 'noexist' self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -704,7 +702,7 @@ class SwiftTests(object): container = 'randomname_' + expected_image_id[:2] loc = 'swift+config://ref1/%s/%s' expected_location = loc % (container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -714,7 +712,7 @@ class SwiftTests(object): conf['swift_store_container'] = 'randomname' conf['swift_store_multiple_containers_seed'] = 2 self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) @@ -750,7 +748,7 @@ class SwiftTests(object): conf['swift_store_container'] = 'randomname' conf['swift_store_multiple_containers_seed'] = 2 self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() expected_image_id = str(uuid.uuid4()) @@ -759,7 +757,7 @@ class SwiftTests(object): self.store = Store(self.conf) self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -787,7 +785,7 @@ class SwiftTests(object): base_byte = b"12345678" swift_contents = base_byte * (swift_size // 8) image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(swift_contents) + image_swift = io.BytesIO(swift_contents) self.store = Store(self.conf) self.store.configure() @@ -834,7 +832,7 @@ class SwiftTests(object): base_byte = b"12345678" swift_contents = base_byte * (swift_size // 8) image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(swift_contents) + image_swift = io.BytesIO(swift_contents) self.store = Store(self.conf) self.store.configure() @@ -873,7 +871,7 @@ class SwiftTests(object): expected_container = 'container_' + expected_image_id loc = 'swift+https://some_endpoint/%s/%s' expected_location = loc % (expected_container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -925,7 +923,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/glance/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -980,7 +978,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/glance/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -1027,7 +1025,7 @@ class SwiftTests(object): """ self.store = Store(self.conf) self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") self.assertRaises(exceptions.Duplicate, self.store.add, FAKE_UUID, image_swift, 0, HASH_ALGO) @@ -1074,7 +1072,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -1093,7 +1091,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf) self.store.configure() @@ -1114,7 +1112,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf) self.store.configure() @@ -1134,7 +1132,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) # mock client because v3 uses it to receive auth_info self.mock_keystone_client() self.store = Store(self.conf) @@ -1153,7 +1151,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf) self.store.configure() @@ -1192,7 +1190,7 @@ class SwiftTests(object): conf = copy.deepcopy(SWIFT_CONF) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf) self.store.configure() @@ -1847,7 +1845,7 @@ class TestMultiTenantStoreContext(base.StoreBaseTest): store = Store(self.conf) store.configure() content = b'Some data' - pseudo_file = six.BytesIO(content) + pseudo_file = io.BytesIO(content) store.add('123', pseudo_file, len(content), HASH_ALGO, context=self.ctx) self.assertEqual(b'0123', @@ -1864,7 +1862,7 @@ class TestCreatingLocations(base.StoreBaseTest): conf = copy.deepcopy(SWIFT_CONF) self.store = Store(self.conf) self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) self.addCleanup(self.conf.reset) service_catalog = [ @@ -1894,7 +1892,7 @@ class TestCreatingLocations(base.StoreBaseTest): conf.update({'swift_store_config_file': self.swift_config_file}) conf['default_swift_reference'] = 'ref1' self.config(**conf) - moves.reload_module(swift) + importlib.reload(swift) store = swift.SingleTenantStore(self.conf) store.configure() @@ -2107,7 +2105,7 @@ class TestBufferedReader(base.StoreBaseTest): super(TestBufferedReader, self).setUp() self.config(swift_upload_buffer_dir=self.test_dir) s = b'1234567890' - self.infile = six.BytesIO(s) + self.infile = io.BytesIO(s) self.infile.seek(0) self.checksum = md5(usedforsecurity=False) @@ -2286,7 +2284,7 @@ class TestBufferedReader(base.StoreBaseTest): # simulate testing where there is less in the buffer than a # full segment s = b'12' - infile = six.BytesIO(s) + infile = io.BytesIO(s) infile.seek(0) total = 7 checksum = md5(usedforsecurity=False) diff --git a/glance_store/tests/unit/test_swift_store_multibackend.py b/glance_store/tests/unit/test_swift_store_multibackend.py index dba5bda4..10b5c467 100644 --- a/glance_store/tests/unit/test_swift_store_multibackend.py +++ b/glance_store/tests/unit/test_swift_store_multibackend.py @@ -20,6 +20,9 @@ from unittest import mock import fixtures import hashlib +import http.client +import importlib +import io import tempfile import uuid @@ -28,11 +31,6 @@ from oslo_utils import encodeutils from oslo_utils.secretutils import md5 from oslo_utils import units import requests_mock -import six -from six import moves -from six.moves import http_client -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range import swiftclient from glance_store._drivers.swift import connection_manager as manager @@ -84,14 +82,14 @@ class SwiftTests(object): 'glance/%s' % FAKE_UUID2: {'x-static-large-object': 'true', }, } fixture_objects = { - 'glance/%s' % FAKE_UUID: six.BytesIO(b"*" * FIVE_KB), - 'glance/%s' % FAKE_UUID2: six.BytesIO(b"*" * FIVE_KB), + 'glance/%s' % FAKE_UUID: io.BytesIO(b"*" * FIVE_KB), + 'glance/%s' % FAKE_UUID2: io.BytesIO(b"*" * FIVE_KB), } def fake_head_container(url, token, container, **kwargs): if container not in fixture_containers: msg = "No container %s found" % container - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) return fixture_container_headers @@ -123,7 +121,7 @@ class SwiftTests(object): fixture_objects[fixture_key] = None return etag if hasattr(contents, 'read'): - fixture_object = six.BytesIO() + fixture_object = io.BytesIO() read_len = 0 chunk = contents.read(CHUNKSIZE) checksum = md5(usedforsecurity=False) @@ -134,7 +132,7 @@ class SwiftTests(object): chunk = contents.read(CHUNKSIZE) etag = checksum.hexdigest() else: - fixture_object = six.BytesIO(contents) + fixture_object = io.BytesIO(contents) read_len = len(contents) etag = md5(fixture_object.getvalue(), usedforsecurity=False).hexdigest() @@ -142,7 +140,7 @@ class SwiftTests(object): msg = ('Image size:%d exceeds Swift max:%d' % (read_len, MAX_SWIFT_OBJECT_SIZE)) raise swiftclient.ClientException( - msg, http_status=http_client.REQUEST_ENTITY_TOO_LARGE) + msg, http_status=http.client.REQUEST_ENTITY_TOO_LARGE) fixture_objects[fixture_key] = fixture_object fixture_headers[fixture_key] = { 'content-length': read_len, @@ -152,14 +150,14 @@ class SwiftTests(object): msg = ("Object PUT failed - Object with key %s already exists" % fixture_key) raise swiftclient.ClientException( - msg, http_status=http_client.CONFLICT) + msg, http_status=http.client.CONFLICT) def fake_get_object(conn, container, name, **kwargs): # GET returns the tuple (list of headers, file object) fixture_key = "%s/%s" % (container, name) if fixture_key not in fixture_headers: msg = "Object GET failed" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) byte_range = None @@ -176,7 +174,7 @@ class SwiftTests(object): chunk_keys = sorted([k for k in fixture_headers.keys() if k.startswith(fixture_key) and k != fixture_key]) - result = six.BytesIO() + result = io.BytesIO() for key in chunk_keys: result.write(fixture_objects[key].getvalue()) else: @@ -184,7 +182,7 @@ class SwiftTests(object): if byte_range is not None: start = int(byte_range.split('=')[1].strip('-')) - result = six.BytesIO(result.getvalue()[start:]) + result = io.BytesIO(result.getvalue()[start:]) fixture_headers[fixture_key]['content-length'] = len( result.getvalue()) @@ -197,7 +195,7 @@ class SwiftTests(object): return fixture_headers[fixture_key] except KeyError: msg = "Object HEAD failed - Object does not exist" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) def fake_delete_object(url, token, container, name, **kwargs): @@ -205,7 +203,7 @@ class SwiftTests(object): fixture_key = "%s/%s" % (container, name) if fixture_key not in fixture_headers: msg = "Object DELETE failed - Object does not exist" - status = http_client.NOT_FOUND + status = http.client.NOT_FOUND raise swiftclient.ClientException(msg, http_status=status) else: del fixture_headers[fixture_key] @@ -317,7 +315,7 @@ class SwiftTests(object): (image_swift, image_size) = self.store.get(loc, context=ctxt) resp_full = b''.join([chunk for chunk in image_swift.wrapped]) resp_half = resp_full[:len(resp_full) // 2] - resp_half = six.BytesIO(resp_half) + resp_half = io.BytesIO(resp_half) manager = self.store.get_manager(loc.store_location, ctxt) image_swift.wrapped = swift.swift_retry_iter(resp_half, image_size, @@ -393,7 +391,7 @@ class SwiftTests(object): mock.Mock(return_value=False)) def test_add(self): """Test that we can add an image via the swift backend.""" - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -404,7 +402,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = "swift+https://tenant%%3Auser1:key@localhost:8080/glance/%s" expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -433,7 +431,7 @@ class SwiftTests(object): conf = copy.deepcopy(SWIFT_CONF) conf['default_swift_reference'] = 'store_2' self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -441,7 +439,7 @@ class SwiftTests(object): expected_swift_size = FIVE_KB expected_swift_contents = b"*" * expected_swift_size expected_image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 loc = 'swift+config://store_2/glance/%s' @@ -464,7 +462,7 @@ class SwiftTests(object): expected_container = 'container_' + expected_image_id loc = 'swift+https://some_endpoint/%s/%s' expected_location = loc % (expected_container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -526,13 +524,13 @@ class SwiftTests(object): expected_checksum = \ md5(expected_swift_contents, usedforsecurity=False).hexdigest() - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 conf['default_swift_reference'] = variation self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -565,13 +563,13 @@ class SwiftTests(object): conf['swift_store_create_container_on_put'] = False conf['swift_store_container'] = 'noexist' self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend='swift1') self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -604,7 +602,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/noexist/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -613,7 +611,7 @@ class SwiftTests(object): conf['swift_store_create_container_on_put'] = True conf['swift_store_container'] = 'noexist' self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -652,7 +650,7 @@ class SwiftTests(object): container = 'randomname_' + expected_image_id[:2] loc = 'swift+config://ref1/%s/%s' expected_location = loc % (container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -662,7 +660,7 @@ class SwiftTests(object): conf['swift_store_container'] = 'randomname' conf['swift_store_multiple_containers_seed'] = 2 self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") @@ -700,7 +698,7 @@ class SwiftTests(object): conf['swift_store_container'] = 'randomname' conf['swift_store_multiple_containers_seed'] = 2 self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() expected_image_id = str(uuid.uuid4()) @@ -709,7 +707,7 @@ class SwiftTests(object): self.store = Store(self.conf, backend="swift1") self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -737,7 +735,7 @@ class SwiftTests(object): base_byte = b"12345678" swift_contents = base_byte * (swift_size // 8) image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(swift_contents) + image_swift = io.BytesIO(swift_contents) self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -784,7 +782,7 @@ class SwiftTests(object): base_byte = b"12345678" swift_contents = base_byte * (swift_size // 8) image_id = str(uuid.uuid4()) - image_swift = six.BytesIO(swift_contents) + image_swift = io.BytesIO(swift_contents) self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -823,7 +821,7 @@ class SwiftTests(object): expected_container = 'container_' + expected_image_id loc = 'swift+https://some_endpoint/%s/%s' expected_location = loc % (expected_container, expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -876,7 +874,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/glance/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -931,7 +929,7 @@ class SwiftTests(object): expected_image_id = str(uuid.uuid4()) loc = 'swift+config://ref1/glance/%s' expected_location = loc % (expected_image_id) - image_swift = six.BytesIO(expected_swift_contents) + image_swift = io.BytesIO(expected_swift_contents) global SWIFT_PUT_OBJECT_CALLS SWIFT_PUT_OBJECT_CALLS = 0 @@ -986,7 +984,7 @@ class SwiftTests(object): """ self.store = Store(self.conf, backend="swift1") self.store.configure() - image_swift = six.BytesIO(b"nevergonnamakeit") + image_swift = io.BytesIO(b"nevergonnamakeit") self.assertRaises(exceptions.Duplicate, self.store.add, FAKE_UUID, image_swift, 0) @@ -1033,7 +1031,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -1053,7 +1051,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -1075,7 +1073,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -1096,7 +1094,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) # mock client because v3 uses it to receive auth_info self.mock_keystone_client() self.store = Store(self.conf, backend="swift1") @@ -1116,7 +1114,7 @@ class SwiftTests(object): """ conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -1155,7 +1153,7 @@ class SwiftTests(object): conf = copy.deepcopy(SWIFT_CONF) self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) self.store = Store(self.conf, backend="swift1") self.store.configure() @@ -1896,7 +1894,7 @@ class TestMultiTenantStoreContext(base.MultiStoreBaseTest): store = Store(self.conf, backend="swift1") store.configure() content = b'Some data' - pseudo_file = six.BytesIO(content) + pseudo_file = io.BytesIO(content) store.add('123', pseudo_file, len(content), context=self.ctx) self.assertEqual(b'0123', @@ -1939,7 +1937,7 @@ class TestCreatingLocations(base.MultiStoreBaseTest): self.store.configure() self.register_store_backend_schemes(self.store, 'swift', 'swift1') - moves.reload_module(swift) + importlib.reload(swift) self.addCleanup(self.conf.reset) service_catalog = [ @@ -1969,7 +1967,7 @@ class TestCreatingLocations(base.MultiStoreBaseTest): conf.update({'swift_store_config_file': self.swift_config_file}) conf['default_swift_reference'] = 'ref1' self.config(group="swift1", **conf) - moves.reload_module(swift) + importlib.reload(swift) store = swift.SingleTenantStore(self.conf, backend="swift1") store.configure() diff --git a/glance_store/tests/unit/test_vmware_store.py b/glance_store/tests/unit/test_vmware_store.py index c74aab8b..ca0bf5eb 100644 --- a/glance_store/tests/unit/test_vmware_store.py +++ b/glance_store/tests/unit/test_vmware_store.py @@ -16,6 +16,7 @@ """Tests the VMware Datastore backend store""" import hashlib +import io from unittest import mock import uuid @@ -25,7 +26,6 @@ from oslo_vmware import api from oslo_vmware import exceptions as vmware_exceptions from oslo_vmware.objects import datacenter as oslo_datacenter from oslo_vmware.objects import datastore as oslo_datastore -import six import glance_store._drivers.vmware_datastore as vm_store from glance_store import backend @@ -105,7 +105,7 @@ class TestStore(base.StoreBaseTest, self.hash_algo = 'sha256' def _mock_http_connection(self): - return mock.patch('six.moves.http_client.HTTPConnection') + return mock.patch('http.client.HTTPConnection') @mock.patch('oslo_vmware.api.VMwareAPISession') def test_get(self, mock_api_session): @@ -153,7 +153,7 @@ class TestStore(base.StoreBaseTest, fake_size.__get__ = mock.Mock(return_value=expected_size) expected_cookie = 'vmware_soap_session=fake-uuid' fake_cookie.return_value = expected_cookie - expected_headers = {'Content-Length': six.text_type(expected_size), + expected_headers = {'Content-Length': str(expected_size), 'Cookie': expected_cookie} with mock.patch('hashlib.md5') as md5: with mock.patch('hashlib.new') as fake_new: @@ -164,7 +164,7 @@ class TestStore(base.StoreBaseTest, VMWARE_DS['vmware_store_image_dir'], expected_image_id, VMWARE_DS['vmware_datastores']) - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, multihash, _ = self.store.add( @@ -205,7 +205,7 @@ class TestStore(base.StoreBaseTest, VMWARE_DS['vmware_store_image_dir'], expected_image_id, VMWARE_DS['vmware_datastores']) - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() location, size, checksum, multihash, _ = self.store.add( @@ -224,7 +224,7 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) size = FIVE_KB contents = b"*" * size - image = six.BytesIO(contents) + image = io.BytesIO(contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() self.store.add(image_id, image, size, self.hash_algo, @@ -240,7 +240,7 @@ class TestStore(base.StoreBaseTest, image_id = str(uuid.uuid4()) size = FIVE_KB contents = b"*" * size - image = six.BytesIO(contents) + image = io.BytesIO(contents) with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response() self.store.add(image_id, image, 0, self.hash_algo, @@ -303,7 +303,7 @@ class TestStore(base.StoreBaseTest, def test_reader_full(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) expected_checksum = secretutils.md5(content, usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(content).hexdigest() @@ -316,7 +316,7 @@ class TestStore(base.StoreBaseTest, def test_reader_partial(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) expected_checksum = secretutils.md5(b'X', usedforsecurity=False).hexdigest() expected_multihash = hashlib.sha256(b'X').hexdigest() @@ -329,7 +329,7 @@ class TestStore(base.StoreBaseTest, def test_reader_with_verifier(self): content = b'XXX' - image = six.BytesIO(content) + image = io.BytesIO(content) verifier = mock.MagicMock(name='mock_verifier') reader = vm_store._Reader(image, self.hash_algo, verifier) reader.read() @@ -414,7 +414,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with mock.patch('requests.Session.request') as HttpConn: HttpConn.return_value = utils.fake_response(status_code=401) @@ -430,7 +430,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with self._mock_http_connection() as HttpConn: HttpConn.return_value = utils.fake_response(status_code=500, @@ -473,7 +473,7 @@ class TestStore(base.StoreBaseTest, expected_image_id = str(uuid.uuid4()) expected_size = FIVE_KB expected_contents = b"*" * expected_size - image = six.BytesIO(expected_contents) + image = io.BytesIO(expected_contents) self.session = mock.Mock() with mock.patch('requests.Session.request') as HttpConn: HttpConn.request.side_effect = IOError diff --git a/glance_store/tests/utils.py b/glance_store/tests/utils.py index 5180bdde..eb971727 100644 --- a/glance_store/tests/utils.py +++ b/glance_store/tests/utils.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import six -from six.moves import urllib +import io +import urllib.parse from oslo_utils import units import requests @@ -45,7 +45,7 @@ def sort_url_by_qs_keys(url): class FakeHTTPResponse(object): def __init__(self, status=200, headers=None, data=None, *args, **kwargs): data = data or 'I am a teapot, short and stout\n' - self.data = six.StringIO(data) + self.data = io.StringIO(data) self.read = self.data.read self.status = status self.headers = headers or {'content-length': len(data)} diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index b64031dc..56170cef 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -56,8 +56,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'Glance_store Release Notes' -copyright = u'2015, Openstack Foundation' +project = 'Glance_store Release Notes' +copyright = '2015, Openstack Foundation' # Release notes are unversioned, so we don't need to set version or release version = '' @@ -206,8 +206,8 @@ latex_elements = { latex_documents = [ ('index', 'GlanceStoreReleaseNotes.tex', - u'Glance_store Release Notes Documentation', - u'Glance_store Developers', + 'Glance_store Release Notes Documentation', + 'Glance_store Developers', 'manual'), ] @@ -239,8 +239,8 @@ latex_documents = [ man_pages = [ ('index', 'glancestorereleasenotes', - u'Glance_store Release Notes Documentation', - [u'Glance_store Developers'], + 'Glance_store Release Notes Documentation', + ['Glance_store Developers'], 1) ] @@ -256,8 +256,8 @@ man_pages = [ texinfo_documents = [ ('index', 'GlanceStoreReleaseNotes', - u'Glance_store Release Notes Documentation', - u'Glance_store Developers', + 'Glance_store Release Notes Documentation', + 'Glance_store Developers', 'GlanceStoreReleaseNotes', 'One line description of project.', 'Miscellaneous'), diff --git a/requirements.txt b/requirements.txt index f14c59a3..ffd4fd71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ oslo.utils>=4.7.0 # Apache-2.0 oslo.concurrency>=3.26.0 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0 eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT -six>=1.11.0 # MIT jsonschema>=3.2.0 # MIT keystoneauth1>=3.4.0 # Apache-2.0 diff --git a/tools/colorizer.py b/tools/colorizer.py index d205eb0b..d26df6f5 100644 --- a/tools/colorizer.py +++ b/tools/colorizer.py @@ -42,7 +42,6 @@ """Display a subunit stream through a colorized unittest test runner.""" import heapq -import six import subunit import sys import unittest @@ -277,7 +276,7 @@ class SubunitTestResult(testtools.TestResult): self.stopTestRun() def stopTestRun(self): - for cls in list(six.iterkeys(self.results)): + for cls in self.results: self.writeTestCase(cls) self.stream.writeln() self.writeSlowTests()