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
from cinder.i18n import _
from cinder import objects
from cinder.objects import base
-from cinder import utils
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
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):
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
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
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):
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
from cinder.i18n import _
from cinder import objects
from cinder.objects import base
-from cinder import utils
CONF = cfg.CONF
OPTIONAL_FIELDS = []
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):
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):
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.