]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use version convert methods from oslo.utils
authorChangBo Guo(gcb) <eric.guo@easystack.cn>
Wed, 19 Aug 2015 08:52:33 +0000 (16:52 +0800)
committerChangBo Guo(gcb) <eric.guo@easystack.cn>
Thu, 27 Aug 2015 02:16:13 +0000 (10:16 +0800)
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
cinder/objects/snapshot.py
cinder/objects/volume.py
cinder/tests/unit/test_utils.py
cinder/utils.py

index 2ba3cd1a1cb009561d680cedb385b66bd4e96191..c773f08fddaa501a1c29ba5cc0ad5ed8aadaa697 100644 (file)
@@ -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):
index 49ca08944d2b03ca8f2cbeb95dc1db939cc72b31..a4d19f41511a3c8c74c35cda281b6800d997f5f8 100644 (file)
@@ -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):
index a4d999e82a8b888ad339aa74db7f2a2cb1a2efe6..46c3d8d8f3f5dfe8853664fdd775f9e129d2d2e2 100644 (file)
@@ -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):
index d7988c7afc00977eefe7f5dbbc3cf05c49014ba6..8ac4d4fb4c768a20940dca8e6a69238d1dffe268 100644 (file)
@@ -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):
index bde22e8357d9416d809d730b45f52e8956b89ff2..7eb6ec648e2bf388a8ccf0e50be4de9dc9607b43 100644 (file)
@@ -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.