From 6831f27976ffbc1d9ec77c9b68b04559406f14b6 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Wed, 19 Aug 2015 16:52:33 +0800 Subject: [PATCH] Use version convert methods from oslo.utils oslo.utils provides version convert methods in versionutils[1], so it is redundant to have them in Cinder. [1]https://github.com/openstack/oslo.utils/blob/master/oslo_utils/versionutils.py Closes-Bug: #1487273 Change-Id: Ic8ba775bc067759319829a1bcbde2660ddeb921e --- cinder/objects/backup.py | 4 ++-- cinder/objects/snapshot.py | 4 ++-- cinder/objects/volume.py | 4 ++-- cinder/tests/unit/test_utils.py | 16 ---------------- cinder/utils.py | 26 -------------------------- 5 files changed, 6 insertions(+), 48 deletions(-) diff --git a/cinder/objects/backup.py b/cinder/objects/backup.py index 2ba3cd1a1..c773f08fd 100644 --- a/cinder/objects/backup.py +++ b/cinder/objects/backup.py @@ -18,6 +18,7 @@ import binascii from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils +from oslo_utils import versionutils from oslo_versionedobjects import fields import six @@ -26,7 +27,6 @@ from cinder import exception from cinder.i18n import _ from cinder import objects from cinder.objects import base -from cinder import utils CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -76,7 +76,7 @@ class Backup(base.CinderPersistentObject, base.CinderObject, def obj_make_compatible(self, primitive, target_version): """Make an object representation compatible with a target version.""" super(Backup, self).obj_make_compatible(primitive, target_version) - target_version = utils.convert_version_to_tuple(target_version) + target_version = versionutils.convert_version_to_tuple(target_version) @staticmethod def _from_db_object(context, backup, db_backup): diff --git a/cinder/objects/snapshot.py b/cinder/objects/snapshot.py index 49ca08944..a4d19f415 100644 --- a/cinder/objects/snapshot.py +++ b/cinder/objects/snapshot.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from oslo_utils import versionutils from oslo_versionedobjects import fields from cinder import db @@ -21,7 +22,6 @@ from cinder import exception from cinder.i18n import _ from cinder import objects from cinder.objects import base -from cinder import utils CONF = cfg.CONF # NOTE(thangp): OPTIONAL_FIELDS are fields that would be lazy-loaded. They are @@ -99,7 +99,7 @@ class Snapshot(base.CinderPersistentObject, base.CinderObject, def obj_make_compatible(self, primitive, target_version): """Make an object representation compatible with a target version.""" super(Snapshot, self).obj_make_compatible(primitive, target_version) - target_version = utils.convert_version_to_tuple(target_version) + target_version = versionutils.convert_version_to_tuple(target_version) @staticmethod def _from_db_object(context, snapshot, db_snapshot, expected_attrs=None): diff --git a/cinder/objects/volume.py b/cinder/objects/volume.py index a4d999e82..46c3d8d8f 100644 --- a/cinder/objects/volume.py +++ b/cinder/objects/volume.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from oslo_utils import versionutils from oslo_versionedobjects import fields from cinder import db @@ -21,7 +22,6 @@ from cinder import exception from cinder.i18n import _ from cinder import objects from cinder.objects import base -from cinder import utils CONF = cfg.CONF OPTIONAL_FIELDS = [] @@ -97,7 +97,7 @@ class Volume(base.CinderPersistentObject, base.CinderObject, def obj_make_compatible(self, primitive, target_version): """Make an object representation compatible with a target version.""" super(Volume, self).obj_make_compatible(primitive, target_version) - target_version = utils.convert_version_to_tuple(target_version) + target_version = versionutils.convert_version_to_tuple(target_version) @staticmethod def _from_db_object(context, volume, db_volume): diff --git a/cinder/tests/unit/test_utils.py b/cinder/tests/unit/test_utils.py index d7988c7af..8ac4d4fb4 100644 --- a/cinder/tests/unit/test_utils.py +++ b/cinder/tests/unit/test_utils.py @@ -1506,22 +1506,6 @@ class TestRetryDecorator(test.TestCase): self.assertFalse(mock_sleep.called) -class VersionTestCase(test.TestCase): - def test_convert_version_to_int(self): - self.assertEqual(6002000, utils.convert_version_to_int('6.2.0')) - self.assertEqual(6004003, utils.convert_version_to_int((6, 4, 3))) - self.assertEqual(5, utils.convert_version_to_int((5, ))) - self.assertRaises(exception.CinderException, - utils.convert_version_to_int, '5a.6b') - - def test_convert_version_to_string(self): - self.assertEqual('6.7.0', utils.convert_version_to_str(6007000)) - self.assertEqual('4', utils.convert_version_to_str(4)) - - def test_convert_version_to_tuple(self): - self.assertEqual((6, 7, 0), utils.convert_version_to_tuple('6.7.0')) - - class LogTracingTestCase(test.TestCase): def test_utils_setup_tracing(self): diff --git a/cinder/utils.py b/cinder/utils.py index bde22e835..7eb6ec648 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -833,32 +833,6 @@ def retry(exceptions, interval=1, retries=3, backoff_rate=2, return _decorator -def convert_version_to_int(version): - try: - if isinstance(version, six.string_types): - version = convert_version_to_tuple(version) - if isinstance(version, tuple): - return six.moves.reduce(lambda x, y: (x * 1000) + y, version) - except Exception: - msg = _("Version %s is invalid.") % version - raise exception.CinderException(msg) - - -def convert_version_to_str(version_int): - version_numbers = [] - factor = 1000 - while version_int != 0: - version_number = version_int - (version_int // factor * factor) - version_numbers.insert(0, six.text_type(version_number)) - version_int = version_int // factor - - return '.'.join(map(str, version_numbers)) - - -def convert_version_to_tuple(version_str): - return tuple(int(part) for part in version_str.split('.')) - - def convert_str(text): """Convert to native string. -- 2.45.2