Browse Source

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
changes/68/756468/4
xuanyandong 12 months ago
parent
commit
a78a851817
  1. 4
      cinder/image/accelerator.py
  2. 9
      cinder/image/cache.py
  3. 12
      cinder/image/glance.py
  4. 4
      cinder/image/image_utils.py

4
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

9
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'],

12
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):

4
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)

Loading…
Cancel
Save