commit a78a851817d239642b45b210a0401b2e2377cb4a Author: xuanyandong Date: Wed Oct 7 17:07:41 2020 +0800 Remove six of dir cinder/image/* Replace the following items with Python 3 style code. - six.add_metaclass - six.text_type - six.string_types - six.moves - six.reraise Depends-on: https://review.opendev.org/757655 Implements: blueprint six-removal Change-Id: I1f1728b6c98826f8702a1479cf53e05dc270a670 diff --git a/cinder/image/accelerator.py b/cinder/image/accelerator.py index a471fb5..771f330 100644 --- a/cinder/image/accelerator.py +++ b/cinder/image/accelerator.py @@ -16,7 +16,6 @@ import abc from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils -import six from cinder import exception from cinder.i18n import _ @@ -34,8 +33,7 @@ _ACCEL_PATH_PREFERENCE_ORDER_LIST = [ ] -@six.add_metaclass(abc.ABCMeta) -class AccelBase(object): +class AccelBase(object, metaclass=abc.ABCMeta): def __init__(self): return diff --git a/cinder/image/cache.py b/cinder/image/cache.py index 164a4e4..0abfe6f 100644 --- a/cinder/image/cache.py +++ b/cinder/image/cache.py @@ -16,7 +16,6 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import timeutils from pytz import timezone -import six from cinder import objects from cinder import rpc @@ -94,7 +93,7 @@ class ImageVolumeCache(object): # we just need to parse it into one. If it is an actual datetime # we want to just grab it as a UTC naive datetime. image_updated_at = image_meta['updated_at'] - if isinstance(image_updated_at, six.string_types): + if isinstance(image_updated_at, str): image_updated_at = timeutils.parse_strtime(image_updated_at) else: image_updated_at = image_updated_at.astimezone(timezone('UTC')) @@ -222,13 +221,13 @@ class ImageVolumeCache(object): LOG.debug('Image-volume cache entry image_update_at = %(entry_utc)s, ' 'requested image updated_at = %(image_utc)s.', - {'entry_utc': six.text_type(cache_updated_utc), - 'image_utc': six.text_type(image_updated_utc)}) + {'entry_utc': str(cache_updated_utc), + 'image_utc': str(image_updated_utc)}) return image_updated_utc != cache_updated_utc def _entry_to_str(self, cache_entry): - return six.text_type({ + return str({ 'id': cache_entry['id'], 'image_id': cache_entry['image_id'], 'volume_id': cache_entry['volume_id'], diff --git a/cinder/image/glance.py b/cinder/image/glance.py index f2a6648..37ba416 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -23,6 +23,7 @@ import shutil import sys import textwrap import time +import urllib import glanceclient.exc from keystoneauth1.loading import session as ks_session @@ -30,9 +31,6 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import timeutils -import six -from six.moves import range -from six.moves import urllib from cinder import exception from cinder.i18n import _ @@ -547,13 +545,13 @@ def _convert_timestamps_to_datetimes(image_meta): # NOTE(bcwaldon): used to store non-string data in glance metadata def _json_loads(properties, attr): prop = properties[attr] - if isinstance(prop, six.string_types): + if isinstance(prop, str): properties[attr] = jsonutils.loads(prop) def _json_dumps(properties, attr): prop = properties[attr] - if not isinstance(prop, six.string_types): + if not isinstance(prop, str): properties[attr] = jsonutils.dumps(prop) @@ -621,14 +619,14 @@ def _reraise_translated_image_exception(image_id): """Transform the exception for the image but keep its traceback intact.""" _exc_type, exc_value, exc_trace = sys.exc_info() new_exc = _translate_image_exception(image_id, exc_value) - six.reraise(type(new_exc), new_exc, exc_trace) + raise new_exc.with_traceback(exc_trace) def _reraise_translated_exception(): """Transform the exception but keep its traceback intact.""" _exc_type, exc_value, exc_trace = sys.exc_info() new_exc = _translate_plain_exception(exc_value) - six.reraise(type(new_exc), new_exc, exc_trace) + raise new_exc.with_traceback(exc_trace) def _translate_image_exception(image_id, exc_value): diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index 237c4dc..db55a48 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -43,7 +43,6 @@ from oslo_utils import imageutils from oslo_utils import timeutils from oslo_utils import units import psutil -import six from cinder import exception from cinder.i18n import _ @@ -480,8 +479,7 @@ def verify_glance_image_signature(context, image_service, image_id, path): message = _('Failed to verify signature for ' 'image: %(image)s due to ' 'error: %(error)s ') % {'image': image_id, - 'error': - six.text_type(ex)} + 'error': ex} LOG.error(message) raise exception.ImageSignatureVerificationException( reason=message)