Stop using six library

Since we've dropped support for Python 2.7, it's time to look at
the bright future that Python 3.x will bring and stop forcing
compatibility with older versions.
This patch removes the six library from requirements, not
looking back.

Change-Id: Ib546f16965475c32b2f8caabd560e2c7d382ac5a
changes/69/696669/9
Riccardo Pittau 3 years ago
parent 67f5a6bf5c
commit 78c121a5d7
  1. 2
      ironic/api/controllers/v1/allocation.py
  2. 2
      ironic/api/controllers/v1/chassis.py
  3. 2
      ironic/api/controllers/v1/deploy_template.py
  4. 3
      ironic/api/controllers/v1/driver.py
  5. 3
      ironic/api/controllers/v1/event.py
  6. 2
      ironic/api/controllers/v1/node.py
  7. 2
      ironic/api/controllers/v1/port.py
  8. 2
      ironic/api/controllers/v1/portgroup.py
  9. 3
      ironic/api/controllers/v1/ramdisk.py
  10. 7
      ironic/api/controllers/v1/types.py
  11. 7
      ironic/api/controllers/v1/utils.py
  12. 3
      ironic/api/controllers/v1/volume.py
  13. 5
      ironic/api/controllers/v1/volume_connector.py
  14. 5
      ironic/api/controllers/v1/volume_target.py
  15. 5
      ironic/api/hooks.py
  16. 7
      ironic/api/middleware/parsable_error.py
  17. 3
      ironic/common/exception.py
  18. 9
      ironic/common/fsm.py
  19. 8
      ironic/common/glance_service/image_service.py
  20. 7
      ironic/common/glance_service/service_utils.py
  21. 16
      ironic/common/image_service.py
  22. 11
      ironic/common/keystone.py
  23. 19
      ironic/common/swift.py
  24. 20
      ironic/common/utils.py
  25. 3
      ironic/conductor/base_manager.py
  26. 2
      ironic/conductor/manager.py
  27. 6
      ironic/conductor/task_manager.py
  28. 3
      ironic/conductor/utils.py
  29. 4
      ironic/db/api.py
  30. 2
      ironic/db/sqlalchemy/models.py
  31. 4
      ironic/dhcp/base.py
  32. 14
      ironic/drivers/base.py
  33. 5
      ironic/drivers/hardware_type.py
  34. 3
      ironic/drivers/modules/agent.py
  35. 3
      ironic/drivers/modules/agent_client.py
  36. 5
      ironic/drivers/modules/ansible/deploy.py
  37. 2
      ironic/drivers/modules/ansible/playbooks/callback_plugins/ironic_log.py
  38. 3
      ironic/drivers/modules/deploy_utils.py
  39. 6
      ironic/drivers/modules/ibmc/utils.py
  40. 2
      ironic/drivers/modules/ilo/boot.py
  41. 10
      ironic/drivers/modules/ilo/common.py
  42. 6
      ironic/drivers/modules/ilo/firmware_processor.py
  43. 6
      ironic/drivers/modules/ilo/management.py
  44. 7
      ironic/drivers/modules/image_cache.py
  45. 5
      ironic/drivers/modules/ipmitool.py
  46. 2
      ironic/drivers/modules/irmc/boot.py
  47. 5
      ironic/drivers/modules/irmc/common.py
  48. 3
      ironic/drivers/modules/irmc/raid.py
  49. 5
      ironic/drivers/modules/iscsi_deploy.py
  50. 2
      ironic/drivers/modules/redfish/boot.py
  51. 7
      ironic/drivers/modules/redfish/utils.py
  52. 4
      ironic/drivers/modules/snmp.py
  53. 3
      ironic/drivers/utils.py
  54. 3
      ironic/objects/fields.py
  55. 3
      ironic/objects/node.py
  56. 3
      ironic/tests/unit/api/base.py
  57. 3
      ironic/tests/unit/api/controllers/test_base.py
  58. 7
      ironic/tests/unit/api/controllers/v1/test_allocation.py
  59. 7
      ironic/tests/unit/api/controllers/v1/test_chassis.py
  60. 2
      ironic/tests/unit/api/controllers/v1/test_conductor.py
  61. 7
      ironic/tests/unit/api/controllers/v1/test_deploy_template.py
  62. 2
      ironic/tests/unit/api/controllers/v1/test_driver.py
  63. 3
      ironic/tests/unit/api/controllers/v1/test_event.py
  64. 11
      ironic/tests/unit/api/controllers/v1/test_node.py
  65. 7
      ironic/tests/unit/api/controllers/v1/test_port.py
  66. 7
      ironic/tests/unit/api/controllers/v1/test_portgroup.py
  67. 3
      ironic/tests/unit/api/controllers/v1/test_ramdisk.py
  68. 7
      ironic/tests/unit/api/controllers/v1/test_types.py
  69. 3
      ironic/tests/unit/api/controllers/v1/test_utils.py
  70. 2
      ironic/tests/unit/api/controllers/v1/test_volume.py
  71. 7
      ironic/tests/unit/api/controllers/v1/test_volume_connector.py
  72. 7
      ironic/tests/unit/api/controllers/v1/test_volume_target.py
  73. 3
      ironic/tests/unit/api/test_acl.py
  74. 5
      ironic/tests/unit/api/test_hooks.py
  75. 3
      ironic/tests/unit/api/test_middleware.py
  76. 2
      ironic/tests/unit/api/test_root.py
  77. 2
      ironic/tests/unit/common/test_cinder.py
  78. 46
      ironic/tests/unit/common/test_image_service.py
  79. 56
      ironic/tests/unit/common/test_images.py
  80. 15
      ironic/tests/unit/common/test_pxe_utils.py
  81. 7
      ironic/tests/unit/common/test_release_mappings.py
  82. 4
      ironic/tests/unit/common/test_states.py
  83. 21
      ironic/tests/unit/common/test_swift.py
  84. 11
      ironic/tests/unit/conductor/test_manager.py
  85. 5
      ironic/tests/unit/db/test_chassis.py
  86. 9
      ironic/tests/unit/db/test_deploy_templates.py
  87. 5
      ironic/tests/unit/db/test_nodes.py
  88. 9
      ironic/tests/unit/db/test_portgroups.py
  89. 11
      ironic/tests/unit/db/test_ports.py
  90. 7
      ironic/tests/unit/db/test_volume_connectors.py
  91. 7
      ironic/tests/unit/db/test_volume_targets.py
  92. 3
      ironic/tests/unit/dhcp/test_factory.py
  93. 15
      ironic/tests/unit/drivers/modules/ansible/test_deploy.py
  94. 18
      ironic/tests/unit/drivers/modules/ilo/test_boot.py
  95. 25
      ironic/tests/unit/drivers/modules/ilo/test_common.py
  96. 6
      ironic/tests/unit/drivers/modules/ilo/test_console.py
  97. 13
      ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py
  98. 3
      ironic/tests/unit/drivers/modules/ilo/test_inspect.py
  99. 10
      ironic/tests/unit/drivers/modules/irmc/test_boot.py
  100. 5
      ironic/tests/unit/drivers/modules/test_agent_client.py
  101. Some files were not shown because too many files have changed in this diff Show More

@ -11,11 +11,11 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_utils import uuidutils
import pecan
from six.moves import http_client
from webob import exc as webob_exc
import wsme
from wsme import types as wtypes

@ -14,11 +14,11 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_utils import uuidutils
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes

@ -12,6 +12,7 @@
import collections
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_log import log
@ -19,7 +20,6 @@ from oslo_utils import strutils
from oslo_utils import uuidutils
import pecan
from pecan import rest
from six.moves import http_client
from webob import exc as webob_exc
import wsme
from wsme import types as wtypes

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
from ironic_lib import metrics_utils
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes

@ -10,10 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_log import log
import pecan
from six.moves import http_client
from ironic import api
from ironic.api.controllers.v1 import collection

@ -14,6 +14,7 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
import jsonschema
@ -22,7 +23,6 @@ from oslo_utils import strutils
from oslo_utils import uuidutils
import pecan
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes

@ -14,12 +14,12 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_log import log
from oslo_utils import uuidutils
from pecan import rest
from six.moves import http_client
import wsme
from wsme import types as wtypes

@ -11,11 +11,11 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_utils import uuidutils
import pecan
from six.moves import http_client
import wsme
from wsme import types as wtypes

@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
from oslo_config import cfg
from oslo_log import log
from pecan import rest
from six.moves import http_client
from wsme import types as wtypes
from ironic import api

@ -21,7 +21,6 @@ import json
from oslo_log import log
from oslo_utils import strutils
from oslo_utils import uuidutils
import six
import wsme
from wsme import types as wtypes
@ -121,7 +120,7 @@ class BooleanType(wtypes.UserType):
return strutils.bool_from_string(value, strict=True)
except ValueError as e:
# raise Invalid to return 400 (BadRequest) in the API
raise exception.Invalid(six.text_type(e))
raise exception.Invalid(str(e))
@staticmethod
def frombasetype(value):
@ -138,7 +137,7 @@ class JsonType(wtypes.UserType):
def __str__(self):
# These are the json serializable native types
return ' | '.join(map(str, (wtypes.text, six.integer_types, float,
return ' | '.join(map(str, (wtypes.text, int, float,
BooleanType, list, dict, None)))
@staticmethod
@ -170,7 +169,7 @@ class ListType(wtypes.UserType):
same order
"""
items = []
for v in six.text_type(value).split(','):
for v in str(value).split(','):
v_norm = v.strip().lower()
if v_norm and v_norm not in items:
items.append(v_norm)

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
import inspect
import re
@ -23,8 +24,6 @@ import os_traits
from oslo_config import cfg
from oslo_utils import uuidutils
from pecan import rest
import six
from six.moves import http_client
from webob import static
import wsme
@ -103,7 +102,7 @@ def validate_trait(trait, error_prefix=_('Invalid trait')):
'A custom trait must start with the prefix CUSTOM_ and use '
'the following characters: A-Z, 0-9 and _') %
{'error_prefix': error_prefix})
if not isinstance(trait, six.string_types):
if not isinstance(trait, str):
raise error
if len(trait) > 255 or len(trait) < 1:
@ -422,7 +421,7 @@ def vendor_passthru(ident, method, topic, data=None, driver_passthru=False):
# Attach the return value to the response object
if response.get('attach'):
if isinstance(return_value, six.text_type):
if isinstance(return_value, str):
# If unicode, convert to bytes
return_value = return_value.encode('utf-8')
file_ = wsme.types.File(content=return_value)

@ -12,9 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
import pecan
from pecan import rest
from six.moves import http_client
import wsme
from ironic import api

@ -13,12 +13,11 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_utils import uuidutils
from pecan import rest
import six
from six.moves import http_client
import wsme
from wsme import types as wtypes
@ -417,7 +416,7 @@ class VolumeConnectorsController(rest.RestController):
for value in values:
if not uuidutils.is_uuid_like(value):
message = _("Expected a UUID for node_uuid, but received "
"%(uuid)s.") % {'uuid': six.text_type(value)}
"%(uuid)s.") % {'uuid': str(value)}
raise exception.InvalidUUID(message=message)
rpc_connector = objects.VolumeConnector.get_by_uuid(context,

@ -13,12 +13,11 @@
# under the License.
import datetime
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_utils import uuidutils
from pecan import rest
import six
from six.moves import http_client
import wsme
from wsme import types as wtypes
@ -429,7 +428,7 @@ class VolumeTargetsController(rest.RestController):
for value in values:
if not uuidutils.is_uuid_like(value):
message = _("Expected a UUID for node_uuid, but received "
"%(uuid)s.") % {'uuid': six.text_type(value)}
"%(uuid)s.") % {'uuid': str(value)}
raise exception.InvalidUUID(message=message)
rpc_target = objects.VolumeTarget.get_by_uuid(context, target_uuid)

@ -14,13 +14,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from http import client as http_client
import re
from oslo_config import cfg
from oslo_log import log
from pecan import hooks
import six
from six.moves import http_client
from ironic.common import context
from ironic.common import policy
@ -48,7 +47,7 @@ def policy_deprecation_check():
}
policy_rules = enforcer.file_rules.values()
for rule in policy_rules:
str_rule = six.text_type(rule)
str_rule = str(rule)
for deprecated, replacement in substitution_dict.items():
if re.search(r'\b%s\b' % deprecated, str_rule):
LOG.warning(

@ -23,7 +23,6 @@ Based on pecan.middleware.errordocument
import json
from oslo_log import log
import six
from ironic.common.i18n import _
@ -69,11 +68,9 @@ class ParsableErrorMiddleware(object):
app_iter = self.app(environ, replacement_start_response)
if (state['status_code'] // 100) not in (2, 3):
if six.PY3:
app_iter = [i.decode('utf-8') for i in app_iter]
app_iter = [i.decode('utf-8') for i in app_iter]
body = [json.dumps({'error_message': '\n'.join(app_iter)})]
if six.PY3:
body = [item.encode('utf-8') for item in body]
body = [item.encode('utf-8') for item in body]
state['headers'].append(('Content-Type', 'application/json'))
state['headers'].append(('Content-Length', str(len(body[0]))))
else:

@ -16,9 +16,10 @@
"""Ironic specific exceptions list."""
from http import client as http_client
from ironic_lib.exception import IronicException
from oslo_log import log as logging
from six.moves import http_client
from ironic.common.i18n import _

@ -12,9 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
from automaton import exceptions as automaton_exceptions
from automaton import machines
import six
"""State machine modelling.
@ -31,7 +32,7 @@ from ironic.common.i18n import _
def _translate_excp(func):
"""Decorator to translate automaton exceptions into ironic exceptions."""
@six.wraps(func)
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
@ -39,9 +40,9 @@ def _translate_excp(func):
automaton_exceptions.NotInitialized,
automaton_exceptions.FrozenMachine,
automaton_exceptions.NotFound) as e:
raise excp.InvalidState(six.text_type(e))
raise excp.InvalidState(str(e))
except automaton_exceptions.Duplicate as e:
raise excp.Duplicate(six.text_type(e))
raise excp.Duplicate(str(e))
return wrapper

@ -14,18 +14,18 @@
# under the License.
import collections
import functools
import os
import re
import sys
import time
from urllib import parse as urlparse
from glanceclient import client
from glanceclient import exc as glance_exc
from oslo_log import log
from oslo_utils import uuidutils
import sendfile
import six
from six.moves.urllib import parse as urlparse
from swiftclient import utils as swift_utils
from ironic.common import exception
@ -56,7 +56,7 @@ def _translate_image_exception(image_id, exc_value):
def check_image_service(func):
"""Creates a glance client if doesn't exists and calls the function."""
@six.wraps(func)
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
"""Wrapper around methods calls.
@ -153,7 +153,7 @@ class GlanceImageService(object):
exc_type, exc_value, exc_trace = sys.exc_info()
new_exc = _translate_image_exception(
args[0], exc_value)
six.reraise(type(new_exc), new_exc, exc_trace)
raise type(new_exc)(new_exc).with_traceback(exc_trace)
@check_image_service
def show(self, image_href):

@ -19,7 +19,6 @@ import copy
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from ironic.common import exception
@ -70,7 +69,7 @@ def _convert(metadata):
for attr in _CONVERT_PROPS:
if attr in properties:
prop = properties[attr]
if isinstance(prop, six.string_types):
if isinstance(prop, str):
properties[attr] = jsonutils.loads(prop)
return metadata
@ -83,7 +82,7 @@ def parse_image_id(image_href):
:raises InvalidImageRef: when input image href is invalid
"""
image_href = six.text_type(image_href)
image_href = str(image_href)
if uuidutils.is_uuid_like(image_href):
image_id = image_href
elif image_href.startswith('glance://'):
@ -130,7 +129,7 @@ def is_image_active(image):
def is_glance_image(image_href):
if not isinstance(image_href, six.string_types):
if not isinstance(image_href, str):
return False
return (image_href.startswith('glance://')
or uuidutils.is_uuid_like(image_href))

@ -17,16 +17,15 @@
import abc
import datetime
from http import client as http_client
import os
import shutil
from urllib import parse as urlparse
from oslo_log import log
from oslo_utils import uuidutils
import requests
import sendfile
import six
from six.moves import http_client
import six.moves.urllib.parse as urlparse
from ironic.common import exception
from ironic.common.glance_service import image_service
@ -45,8 +44,7 @@ LOG = log.getLogger(__name__)
GlanceImageService = image_service.GlanceImageService
@six.add_metaclass(abc.ABCMeta)
class BaseImageService(object):
class BaseImageService(object, metaclass=abc.ABCMeta):
"""Provides retrieval of disk images."""
@abc.abstractmethod
@ -103,7 +101,7 @@ class HttpImageService(BaseImageService):
"HEAD request.") % response.status_code)
except requests.RequestException as e:
raise exception.ImageRefValidationFailed(image_href=output_url,
reason=six.text_type(e))
reason=str(e))
return response
def download(self, image_href, image_file):
@ -128,7 +126,7 @@ class HttpImageService(BaseImageService):
shutil.copyfileobj(input_img, image_file, IMAGE_CHUNK_SIZE)
except (requests.RequestException, IOError) as e:
raise exception.ImageDownloadFailed(image_href=image_href,
reason=six.text_type(e))
reason=str(e))
def show(self, image_href):
"""Get dictionary of image properties.
@ -228,7 +226,7 @@ class FileImageService(BaseImageService):
offset += nbytes_out
except Exception as e:
raise exception.ImageDownloadFailed(image_href=image_href,
reason=six.text_type(e))
reason=str(e))
def show(self, image_href):
"""Get dictionary of image properties.
@ -272,7 +270,7 @@ def get_image_service(image_href, client=None, context=None):
scheme = urlparse.urlparse(image_href).scheme.lower()
if not scheme:
if uuidutils.is_uuid_like(six.text_type(image_href)):
if uuidutils.is_uuid_like(str(image_href)):
cls = GlanceImageService
else:
raise exception.ImageRefValidationFailed(

@ -14,12 +14,13 @@
"""Central place for handling Keystone authorization and service lookup."""
import functools
from keystoneauth1 import exceptions as kaexception
from keystoneauth1 import loading as kaloading
from keystoneauth1 import service_token
from keystoneauth1 import token_endpoint
from oslo_log import log as logging
import six
from ironic.common import exception
from ironic.conf import CONF
@ -30,7 +31,7 @@ LOG = logging.getLogger(__name__)
def ks_exceptions(f):
"""Wraps keystoneclient functions and centralizes exception handling."""
@six.wraps(f)
@functools.wraps(f)
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
@ -43,11 +44,11 @@ def ks_exceptions(f):
raise exception.KeystoneUnauthorized()
except (kaexception.NoMatchingPlugin,
kaexception.MissingRequiredOptions) as e:
raise exception.ConfigInvalid(six.text_type(e))
raise exception.ConfigInvalid(str(e))
except Exception as e:
LOG.exception('Keystone request failed: %(msg)s',
{'msg': six.text_type(e)})
raise exception.KeystoneFailure(six.text_type(e))
{'msg': str(e)})
raise exception.KeystoneFailure(str(e))
return wrapper

@ -14,9 +14,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from six.moves import http_client
from six.moves.urllib import parse
from http import client as http_client
from urllib import parse as urlparse
from swiftclient import client as swift_client
from swiftclient import exceptions as swift_exceptions
from swiftclient import utils as swift_utils
@ -69,7 +69,7 @@ class SwiftAPI(object):
params['timeout'] = session.timeout
if session.verify is False:
params['insecure'] = True
elif isinstance(session.verify, six.string_types):
elif isinstance(session.verify, str):
params['cacert'] = session.verify
if session.cert:
# NOTE(pas-ha) although setting cert as path to single file
@ -129,17 +129,14 @@ class SwiftAPI(object):
raise exception.SwiftOperationError(operation=operation,
error=e)
parse_result = parse.urlparse(self.connection.url)
parse_result = urlparse.urlparse(self.connection.url)
swift_object_path = '/'.join((parse_result.path, container, obj))
temp_url_key = account_info['x-account-meta-temp-url-key']
url_path = swift_utils.generate_temp_url(swift_object_path, timeout,
temp_url_key, 'GET')
return parse.urlunparse((parse_result.scheme,
parse_result.netloc,
url_path,
None,
None,
None))
return urlparse.urlunparse(
(parse_result.scheme, parse_result.netloc, url_path,
None, None, None))
def delete_object(self, container, obj):
"""Deletes the given Swift object.

@ -35,7 +35,6 @@ from oslo_utils import fileutils
from oslo_utils import netutils
from oslo_utils import timeutils
import pytz
import six
from ironic.common import exception
from ironic.common.i18n import _
@ -92,7 +91,7 @@ def is_valid_datapath_id(datapath_id):
"""
m = "^[0-9a-f]{16}$"
return (isinstance(datapath_id, six.string_types)
return (isinstance(datapath_id, str)
and re.match(m, datapath_id.lower()))
@ -114,7 +113,7 @@ def is_valid_logical_name(hostname):
ALPHA / DIGIT / "-" / "." / "_" / "~"
"""
if not isinstance(hostname, six.string_types) or len(hostname) > 255:
if not isinstance(hostname, str) or len(hostname) > 255:
return False
return _is_valid_logical_name_re.match(hostname) is not None
@ -136,7 +135,7 @@ def is_hostname_safe(hostname):
:param hostname: The hostname to be validated.
:returns: True if valid. False if not.
"""
if not isinstance(hostname, six.string_types) or len(hostname) > 255:
if not isinstance(hostname, str) or len(hostname) > 255:
return False
return _is_hostname_safe_re.match(hostname) is not None
@ -153,7 +152,7 @@ def is_valid_no_proxy(no_proxy):
(with optional :port).
:returns: True if no_proxy is valid, False otherwise.
"""
if not isinstance(no_proxy, six.string_types):
if not isinstance(no_proxy, str):
return False
hostname_re = re.compile('(?!-)[A-Z\\d-]{1,63}(?<!-)$', re.IGNORECASE)
for hostname in no_proxy.split(','):
@ -219,8 +218,7 @@ def _get_hash_object(hash_algo_name):
:raises: InvalidParameterValue, on unsupported or invalid input.
:returns: a hash object based on the given named algorithm.
"""
algorithms = (hashlib.algorithms_guaranteed if six.PY3
else hashlib.algorithms)
algorithms = hashlib.algorithms_guaranteed
if hash_algo_name not in algorithms:
msg = (_("Unsupported/Invalid hash name '%s' provided.")
% hash_algo_name)
@ -242,7 +240,7 @@ def file_has_content(path, content, hash_algo='md5'):
file_hash_hex = fileutils.compute_file_checksum(path, algorithm=hash_algo)
ref_hash = _get_hash_object(hash_algo)
encoded_content = (content.encode(encoding='utf-8')
if isinstance(content, six.string_types) else content)
if isinstance(content, str) else content)
ref_hash.update(encoded_content)
return file_hash_hex == ref_hash.hexdigest()
@ -294,7 +292,7 @@ def safe_rstrip(value, chars=None):
:return: Stripped value.
"""
if not isinstance(value, six.string_types):
if not isinstance(value, str):
LOG.warning("Failed to remove trailing character. Returning "
"original object. Supplied object is not a string: "
"%s,", value)
@ -515,7 +513,7 @@ def parse_instance_info_capabilities(node):
raise exception.InvalidParameterValue(error_msg)
capabilities = node.instance_info.get('capabilities', {})
if isinstance(capabilities, six.string_types):
if isinstance(capabilities, str):
try:
capabilities = jsonutils.loads(capabilities)
except (ValueError, TypeError):
@ -528,7 +526,7 @@ def parse_instance_info_capabilities(node):
def validate_conductor_group(conductor_group):
if not isinstance(conductor_group, six.string_types):
if not isinstance(conductor_group, str):
raise exception.InvalidConductorGroup(group=conductor_group)
if not re.match(r'^[a-zA-Z0-9_\-\.]*$', conductor_group):
raise exception.InvalidConductorGroup(group=conductor_group)

@ -24,7 +24,6 @@ from oslo_db import exception as db_exception
from oslo_log import log
from oslo_utils import excutils
from oslo_utils import versionutils
import six
from ironic.common import context as ironic_context
from ironic.common import driver_factory
@ -471,7 +470,7 @@ class BaseConductorManager(object):
fsm.
"""
if isinstance(provision_state, six.string_types):
if isinstance(provision_state, str):
provision_state = {provision_state}
node_iter = self.iter_nodes(filters=filters,

@ -42,6 +42,7 @@ notifying Neutron of a change, etc.
import collections
import datetime
import queue
import tempfile
import eventlet
@ -54,7 +55,6 @@ import oslo_messaging as messaging
from oslo_utils import excutils
from oslo_utils import uuidutils
from oslo_utils import versionutils
from six.moves import queue
from ironic.common import driver_factory
from ironic.common import exception

@ -101,6 +101,7 @@ raised in the background thread.):
"""
import copy
import functools
import futurist
from oslo_config import cfg
@ -108,7 +109,6 @@ from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import timeutils
import retrying
import six
from ironic.common import driver_factory
from ironic.common import exception
@ -131,7 +131,7 @@ def require_exclusive_lock(f):
as the first parameter after "self".
"""
@six.wraps(f)
@functools.wraps(f)
def wrapper(*args, **kwargs):
# NOTE(dtantsur): this code could be written simpler, but then unit
# testing decorated functions is pretty hard, as we usually pass a Mock
@ -378,7 +378,7 @@ class TaskManager(object):
if exc is not None:
msg = _("Async execution of %(method)s failed with error: "
"%(error)s") % {'method': method,
'error': six.text_type(exc)}
'error': str(exc)}
node.last_error = msg
try:
node.save()

@ -23,7 +23,6 @@ from oslo_serialization import jsonutils
from oslo_service import loopingcall
from oslo_utils import excutils
from oslo_utils import timeutils
import six
from ironic.common import boot_devices
from ironic.common import exception
@ -731,7 +730,7 @@ def validate_instance_info_traits(node):
instance_traits = node.instance_info['traits']
if not isinstance(instance_traits, list):
invalid()
if not all(isinstance(t, six.string_types) for t in instance_traits):
if not all(isinstance(t, str) for t in instance_traits):
invalid()
node_traits = node.traits.get_trait_names()

@ -21,7 +21,6 @@ import abc
from oslo_config import cfg
from oslo_db import api as db_api
import six
_BACKEND_MAPPING = {'sqlalchemy': 'ironic.db.sqlalchemy.api'}
@ -34,8 +33,7 @@ def get_instance():
return IMPL
@six.add_metaclass(abc.ABCMeta)
class Connection(object):
class Connection(object, metaclass=abc.ABCMeta):
"""Base class for storage system connections."""
@abc.abstractmethod

@ -19,11 +19,11 @@ SQLAlchemy models for baremetal data.
"""
from os import path
from urllib import parse as urlparse
from oslo_db import options as db_options
from oslo_db.sqlalchemy import models
from oslo_db.sqlalchemy import types as db_types
import six.moves.urllib.parse as urlparse
from sqlalchemy import Boolean, Column, DateTime, false, Index
from sqlalchemy import ForeignKey, Integer
from sqlalchemy import schema, String, Text

@ -20,13 +20,11 @@ Abstract base class for dhcp providers.
import abc
from oslo_log import log as logging
import six
LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class BaseDHCP(object):
class BaseDHCP(object, metaclass=abc.ABCMeta):
"""Base class for DHCP provider APIs."""
@abc.abstractmethod

@ -20,13 +20,13 @@ Abstract base classes for drivers.
import abc
import collections
import copy
import functools
import inspect
import json
import os
from oslo_log import log as logging
from oslo_utils import excutils
import six
from ironic.common import exception
from ironic.common.i18n import _
@ -189,8 +189,7 @@ ALL_INTERFACES = set(BareDriver().all_interfaces)
"""Constant holding all known interfaces."""
@six.add_metaclass(abc.ABCMeta)
class BaseInterface(object):
class BaseInterface(object, metaclass=abc.ABCMeta):
"""A base interface implementing common functions for Driver Interfaces."""
supported = True
@ -747,7 +746,7 @@ def _passthru(http_methods, method=None, async_call=True,
passthru_logmessage = 'vendor_passthru failed with method %s'
@six.wraps(func)
@functools.wraps(func)
def passthru_handler(*args, **kwargs):
try:
return func(*args, **kwargs)
@ -1138,7 +1137,7 @@ def cache_bios_settings(func):
:param func: Function or method to wrap.
"""
@six.wraps(func)
@functools.wraps(func)
def wrapped(self, task, *args, **kwargs):
result = func(self, task, *args, **kwargs)
self.cache_bios_settings(task)
@ -1545,8 +1544,7 @@ class NetworkInterface(BaseInterface):
return False
@six.add_metaclass(abc.ABCMeta)
class StorageInterface(BaseInterface):
class StorageInterface(BaseInterface, metaclass=abc.ABCMeta):
"""Base class for storage interfaces."""
interface_type = 'storage'
@ -1609,7 +1607,7 @@ def _validate_argsinfo(argsinfo):
has_description = False
for (key, value) in info.items():
if key == 'description':
if not isinstance(value, six.string_types):
if not isinstance(value, str):
raise exception.InvalidParameterValue(
_('For argument "%(arg)s", "description" must be a '
'string value instead of "%(value)s".') %

@ -18,8 +18,6 @@ Abstract base class for all hardware types.
import abc
import six
from ironic.common import exception
from ironic.drivers import base as driver_base
from ironic.drivers.modules.network import noop as noop_net
@ -27,8 +25,7 @@ from ironic.drivers.modules import noop
from ironic.drivers.modules.storage import noop as noop_storage
@six.add_metaclass(abc.ABCMeta)
class AbstractHardwareType(object):
class AbstractHardwareType(object, metaclass=abc.ABCMeta):
"""Abstract base class for all hardware types.
Hardware type is a family of hardware supporting the same set of interfaces

@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from urllib import parse as urlparse
from ironic_lib import metrics_utils
from ironic_lib import utils as il_utils
from oslo_log import log
from oslo_utils import excutils
from oslo_utils import units
import six.moves.urllib_parse as urlparse
from ironic.common import dhcp_factory
from ironic.common import exception

@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from http import client as http_client
from ironic_lib import metrics_utils
from oslo_log import log
from oslo_serialization import jsonutils
import requests
import retrying
from six.moves import http_client
from ironic.common import exception
from ironic.common.i18n import _

@ -18,6 +18,7 @@ Ansible deploy interface
import json
import os
import shlex
from urllib import parse as urlparse
from ironic_lib import metrics_utils
from ironic_lib import utils as irlib_utils
@ -26,8 +27,6 @@ from oslo_log import log
from oslo_utils import strutils
from oslo_utils import units
import retrying
import six
import six.moves.urllib.parse as urlparse
import yaml
from ironic.common import dhcp_factory
@ -242,7 +241,7 @@ def _parse_root_device_hints(node):
root_device_hints = {}
advanced = {}
for hint, value in parsed_hints.items():
if isinstance(value, six.string_types):
if isinstance(value, str):
if value.startswith('== '):
root_device_hints[hint] = int(value[3:])
elif value.startswith('s== '):

@ -11,13 +11,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import configparser
import os
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import strutils
import pbr.version
from six.moves import configparser
CONF = cfg.CONF

@ -29,7 +29,6 @@ from oslo_utils import excutils
from oslo_utils import fileutils
from oslo_utils import netutils
from oslo_utils import strutils
import six
from ironic.common import exception
from ironic.common import faults
@ -126,7 +125,7 @@ def get_ironic_api_url():
raise exception.InvalidParameterValue(_(
"Couldn't get the URL of the Ironic API service from the "
"configuration file or keystone catalog. Keystone error: "
"%s") % six.text_type(e))
"%s") % str(e))
# NOTE: we should strip '/' from the end because it might be used in
# hardcoded ramdisk script
ironic_api = ironic_api.rstrip('/')

@ -14,6 +14,7 @@
iBMC Driver common utils
"""
import functools
import os
from oslo_log import log
@ -21,7 +22,6 @@ from oslo_utils import importutils
from oslo_utils import netutils
from oslo_utils import strutils
import retrying
import six
from ironic.common import exception
from ironic.common.i18n import _
@ -90,7 +90,7 @@ def parse_driver_info(node):
# Check if verify_ca is a Boolean or a file/directory in the file-system
verify_ca = driver_info.get('ibmc_verify_ca', True)
if isinstance(verify_ca, six.string_types):
if isinstance(verify_ca, str):
if not os.path.exists(verify_ca):
try:
verify_ca = strutils.bool_from_string(verify_ca, strict=True)
@ -138,7 +138,7 @@ def handle_ibmc_exception(action):
retry_on_exception=should_retry,
stop_max_attempt_number=CONF.ibmc.connection_attempts,
wait_fixed=CONF.ibmc.connection_retry_interval * 1000)
@six.wraps(f)
@functools.wraps(f)
def wrapper(*args, **kwargs):
# NOTE(dtantsur): this code could be written simpler, but then unit
# testing decorated functions is pretty hard, as we usually pass a

@ -17,13 +17,13 @@ Boot Interface for iLO drivers and its supporting methods.
import os
import tempfile
from urllib import parse as urlparse
from ironic_lib import metrics_utils
from ironic_lib import utils as ironic_utils
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
import six.moves.urllib.parse as urlparse
from ironic.common import boot_devices
from ironic.common import exception