Merge "Use version convert methods from oslo.utils"
This commit is contained in:
commit
b1cdd9e49f
@ -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__)
|
||||
@ -87,7 +87,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):
|
||||
|
@ -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):
|
||||
|
@ -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 = ['metadata', 'admin_metadata',
|
||||
@ -137,7 +137,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, expected_attrs=None):
|
||||
|
@ -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):
|
||||
|
@ -845,32 +845,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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user