From 8f50a9fd28bce8e78ad191566bad287af18f12a1 Mon Sep 17 00:00:00 2001 From: Simon Dodsley Date: Fri, 4 Mar 2022 14:27:21 -0500 Subject: [PATCH] Replace distutils with packaging in 3rd party drivers PEP632 defines the deprecation of `distutils` from Python 3.10 and complete removal from Python 3.12. This patch preempts any future issues and follows the long standing recommendation to replace distutils with setuptools (packaging in the case of version string checking) Change-Id: Ie455f3f32a0681d2d7eb54344f9186d09d3de80f --- cinder/volume/drivers/ceph/rbd_iscsi.py | 7 +++-- .../drivers/dell_emc/powerflex/utils.py | 4 +-- cinder/volume/drivers/dell_emc/unity/utils.py | 4 +-- .../drivers/ibm/ibm_storage/ds8k_helper.py | 26 +++++++++---------- cinder/volume/drivers/pure.py | 4 +-- cinder/volume/drivers/rsd.py | 8 +++--- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/cinder/volume/drivers/ceph/rbd_iscsi.py b/cinder/volume/drivers/ceph/rbd_iscsi.py index 0fb56f530e7..fd642cf619b 100644 --- a/cinder/volume/drivers/ceph/rbd_iscsi.py +++ b/cinder/volume/drivers/ceph/rbd_iscsi.py @@ -11,11 +11,10 @@ # under the License. """RADOS Block Device iSCSI Driver""" -from distutils import version - from oslo_config import cfg from oslo_log import log as logging from oslo_utils import netutils +from packaging import version from cinder import exception from cinder.i18n import _ @@ -93,8 +92,8 @@ class RBDISCSIDriver(rbd.RBDDriver): def _create_client(self): client_version = rbd_iscsi_client.version - if (version.StrictVersion(client_version) < - version.StrictVersion(MIN_CLIENT_VERSION)): + if (version.parse(client_version) < + version.parse(MIN_CLIENT_VERSION)): ex_msg = (_('Invalid rbd_iscsi_client version found (%(found)s). ' 'Version %(min)s or greater required. Run "pip' ' install --upgrade rbd-iscsi-client" to upgrade' diff --git a/cinder/volume/drivers/dell_emc/powerflex/utils.py b/cinder/volume/drivers/dell_emc/powerflex/utils.py index 641bf43ba6c..3aae71ab039 100644 --- a/cinder/volume/drivers/dell_emc/powerflex/utils.py +++ b/cinder/volume/drivers/dell_emc/powerflex/utils.py @@ -14,17 +14,17 @@ # under the License. import base64 import binascii -from distutils import version import math from oslo_log import log as logging from oslo_utils import units +from packaging import version LOG = logging.getLogger(__name__) def version_gte(ver1, ver2): - return version.LooseVersion(ver1) >= version.LooseVersion(ver2) + return version.parse(ver1) >= version.parse(ver2) def convert_kb_to_gib(size): diff --git a/cinder/volume/drivers/dell_emc/unity/utils.py b/cinder/volume/drivers/dell_emc/unity/utils.py index 0213e92522c..68a88e2eb20 100644 --- a/cinder/volume/drivers/dell_emc/unity/utils.py +++ b/cinder/volume/drivers/dell_emc/unity/utils.py @@ -14,13 +14,13 @@ # under the License. import contextlib -from distutils import version import fnmatch import functools import json from oslo_log import log as logging from oslo_utils import units +from packaging import version import six from cinder import coordination @@ -359,7 +359,7 @@ def match_any(full, patterns): def is_before_4_1(ver): - return version.LooseVersion(ver) < version.LooseVersion('4.1') + return version.parse(ver) < version.parse('4.1') def lock_if(condition, lock_name): diff --git a/cinder/volume/drivers/ibm/ibm_storage/ds8k_helper.py b/cinder/volume/drivers/ibm/ibm_storage/ds8k_helper.py index 7a2c443ef05..3ff16084e29 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/ds8k_helper.py +++ b/cinder/volume/drivers/ibm/ibm_storage/ds8k_helper.py @@ -15,13 +15,13 @@ # import collections import copy -import distutils.version as dist_version # pylint: disable=E0611 import math import os import string import eventlet from oslo_log import log as logging +import packaging.version as dist_version # pylint: disable=E0611 import six from cinder import coordination @@ -226,8 +226,8 @@ class DS8KCommonHelper(object): % self.INVALID_STORAGE_VERSION)) rest_ver = self.backend['rest_version'][0:2] if ('87' == rest_ver and - dist_version.LooseVersion(self.backend['rest_version']) < - dist_version.LooseVersion(self.VALID_REST_VERSION_87_51_MIN)): + dist_version.parse(self.backend['rest_version']) < + dist_version.parse(self.VALID_REST_VERSION_87_51_MIN)): raise exception.VolumeDriverException( message=(_("REST version %(invalid)s is lower than " "%(valid)s, please upgrade it in DS8K.") @@ -242,12 +242,12 @@ class DS8KCommonHelper(object): valid_rest_version = None rest_ver = self.backend['rest_version'][0:2] if ('87' == rest_ver and - dist_version.LooseVersion(self.backend['rest_version']) < - dist_version.LooseVersion(self.REST_VERSION_87_51_MIN_PPRC_CG)): + dist_version.parse(self.backend['rest_version']) < + dist_version.parse(self.REST_VERSION_87_51_MIN_PPRC_CG)): valid_rest_version = self.REST_VERSION_87_51_MIN_PPRC_CG elif ('88' == rest_ver and - dist_version.LooseVersion(self.backend['rest_version']) < - dist_version.LooseVersion(self.REST_VERSION_88_20_MIN_PPRC_CG)): + dist_version.parse(self.backend['rest_version']) < + dist_version.parse(self.REST_VERSION_88_20_MIN_PPRC_CG)): valid_rest_version = self.REST_VERSION_88_20_MIN_PPRC_CG if valid_rest_version: @@ -1092,17 +1092,17 @@ class DS8KECKDHelper(DS8KCommonHelper): "please upgrade the CCL.") % self.INVALID_STORAGE_VERSION)) # DS8K supports ECKD ESE volume from 8.1 - if (dist_version.LooseVersion(self.backend['storage_version']) < - dist_version.LooseVersion(self.MIN_VALID_STORAGE_VERSION)): + if (dist_version.parse(self.backend['storage_version']) < + dist_version.parse(self.MIN_VALID_STORAGE_VERSION)): self._disable_thin_provision = True rest_ver = self.backend['rest_version'][0:2] if (('87' == rest_ver and - dist_version.LooseVersion(self.backend['rest_version']) < - dist_version.LooseVersion(self.VALID_REST_VERSION_87_51_MIN)) or + dist_version.parse(self.backend['rest_version']) < + dist_version.parse(self.VALID_REST_VERSION_87_51_MIN)) or ('88' == rest_ver and - dist_version.LooseVersion(self.backend['rest_version']) < - dist_version.LooseVersion(self.VALID_REST_VERSION_88_20_MIN))): + dist_version.parse(self.backend['rest_version']) < + dist_version.parse(self.VALID_REST_VERSION_88_20_MIN))): raise exception.VolumeDriverException( message=(_("REST version %(invalid)s is lower than " "%(valid)s, please upgrade it in DS8K.") diff --git a/cinder/volume/drivers/pure.py b/cinder/volume/drivers/pure.py index c4c815e760f..da0109d4f73 100644 --- a/cinder/volume/drivers/pure.py +++ b/cinder/volume/drivers/pure.py @@ -17,7 +17,6 @@ This driver requires Purity version 4.0.0 or later. """ -from distutils import version import functools import ipaddress import math @@ -30,6 +29,7 @@ from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import strutils from oslo_utils import units +from packaging import version try: from purestorage import purestorage except ImportError: @@ -355,7 +355,7 @@ class PureBaseVolumeDriver(san.SanDriver): ) array_info = self._array.get() - if version.LooseVersion(array_info["version"]) < version.LooseVersion( + if version.parse(array_info["version"]) < version.parse( '5.3.0' ): msg = _("FlashArray Purity version less than 5.3.0 unsupported." diff --git a/cinder/volume/drivers/rsd.py b/cinder/volume/drivers/rsd.py index e0e1013dd05..a50e2f00a36 100644 --- a/cinder/volume/drivers/rsd.py +++ b/cinder/volume/drivers/rsd.py @@ -12,12 +12,12 @@ """Driver for RackScale Design.""" -from distutils import version import json from oslo_config import cfg from oslo_log import log as logging from oslo_utils import units +from packaging import version try: from rsd_lib import RSDLib from sushy import exceptions as sushy_exceptions @@ -80,15 +80,15 @@ class RSDClient(object): raise exception.VolumeBackendAPIException( data=_("initialize: Cannot connect to RSD PODM.")) - rsd_api_version = version.LooseVersion(rsdlib._rsd_api_version) - if rsd_api_version < version.LooseVersion("2.4.0"): + rsd_api_version = version.parse(rsdlib._rsd_api_version) + if rsd_api_version < version.parse("2.4.0"): raise exception.VolumeBackendAPIException( data=(_("initialize: Unsupported rsd_api version: " "%(current)s < %(expected)s.") % {'current': rsdlib._rsd_api_version, 'expected': "2.4.0"})) - if rsdlib._redfish_version < version.LooseVersion("1.1.0"): + if version.parse(rsdlib._redfish_version) < version.parse("1.1.0"): raise exception.VolumeBackendAPIException( data=(_("initialize: Unsupported rsd_lib version: " "%(current)s < %(expected)s.")