diff --git a/oslo_versionedobjects/_utils.py b/oslo_versionedobjects/_utils.py index f00005e..4d70dcd 100644 --- a/oslo_versionedobjects/_utils.py +++ b/oslo_versionedobjects/_utils.py @@ -17,17 +17,6 @@ """Utilities and helper functions.""" -import functools -import logging - -import six - -from oslo_versionedobjects._i18n import _ -from oslo_versionedobjects import exception - -LOG = logging.getLogger(__name__) - - # ISO 8601 extended time format with microseconds _ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S' @@ -38,29 +27,3 @@ def isotime(at): tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC' st += ('Z' if tz == 'UTC' else tz) return st - - -def convert_version_to_int(version): - try: - if isinstance(version, six.string_types): - version = convert_version_to_tuple(version) - if isinstance(version, tuple): - return functools.reduce(lambda x, y: (x * 1000) + y, version) - except Exception: - msg = _("Provided version %s is invalid.") % version - raise exception.VersionedObjectsException(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, str(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('.')) diff --git a/oslo_versionedobjects/base.py b/oslo_versionedobjects/base.py index 942cd21..617ed49 100644 --- a/oslo_versionedobjects/base.py +++ b/oslo_versionedobjects/base.py @@ -23,10 +23,10 @@ import warnings import oslo_messaging as messaging from oslo_utils import encodeutils from oslo_utils import excutils +from oslo_utils import versionutils as vutils import six from oslo_versionedobjects._i18n import _, _LE -from oslo_versionedobjects import _utils as utils from oslo_versionedobjects import exception from oslo_versionedobjects import fields as obj_fields from oslo_versionedobjects.openstack.common import versionutils @@ -527,8 +527,8 @@ class VersionedObject(object): """ if target_version is None: target_version = self.VERSION - if (utils.convert_version_to_tuple(target_version) > - utils.convert_version_to_tuple(self.VERSION)): + if (vutils.convert_version_to_tuple(target_version) > + vutils.convert_version_to_tuple(self.VERSION)): raise exception.InvalidTargetVersion(version=target_version) primitive = dict() for name, field in self.fields.items(): @@ -1114,10 +1114,10 @@ def _get_subobject_version(tgt_version, relationships, backport_func): version :returns: The version we need to convert the subobject to """ - tgt = utils.convert_version_to_tuple(tgt_version) + tgt = vutils.convert_version_to_tuple(tgt_version) for index, versions in enumerate(relationships): parent, child = versions - parent = utils.convert_version_to_tuple(parent) + parent = vutils.convert_version_to_tuple(parent) if tgt < parent: if index == 0: # We're backporting to a version of the parent that did diff --git a/oslo_versionedobjects/fixture.py b/oslo_versionedobjects/fixture.py index bef5657..254aa91 100644 --- a/oslo_versionedobjects/fixture.py +++ b/oslo_versionedobjects/fixture.py @@ -25,10 +25,10 @@ import hashlib import inspect import logging import mock +from oslo_utils import versionutils as vutils import six import fixtures -from oslo_versionedobjects import _utils as utils from oslo_versionedobjects import base from oslo_versionedobjects import fields @@ -238,7 +238,7 @@ class ObjectVersionChecker(object): return expected, actual def _test_object_compatibility(self, obj_class): - version = utils.convert_version_to_tuple(obj_class.VERSION) + version = vutils.convert_version_to_tuple(obj_class.VERSION) for n in range(version[1] + 1): test_version = '%d.%d' % (version[0], n) LOG.info('testing obj: %s version: %s' % @@ -261,8 +261,8 @@ class ObjectVersionChecker(object): last_my_version = (0, 0) last_child_version = (0, 0) for my_version, child_version in versions: - _my_version = utils.convert_version_to_tuple(my_version) - _ch_version = utils.convert_version_to_tuple(child_version) + _my_version = vutils.convert_version_to_tuple(my_version) + _ch_version = vutils.convert_version_to_tuple(child_version) assert (last_my_version < _my_version and last_child_version <= _ch_version), \ ('Object %s relationship ' diff --git a/oslo_versionedobjects/tests/test_utils.py b/oslo_versionedobjects/tests/test_utils.py deleted file mode 100755 index 7e4dad7..0000000 --- a/oslo_versionedobjects/tests/test_utils.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2011 Justin Santa Barbara -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_config import cfg - -from oslo_versionedobjects import _utils as utils -from oslo_versionedobjects import exception -from oslo_versionedobjects import test - -CONF = cfg.CONF - - -class VersionTestCase(test.TestCase): - def test_convert_version_to_int(self): - self.assertEqual(utils.convert_version_to_int('6.2.0'), 6002000) - self.assertEqual(utils.convert_version_to_int((6, 4, 3)), 6004003) - self.assertEqual(utils.convert_version_to_int((5, )), 5) - self.assertRaises(exception.VersionedObjectsException, - utils.convert_version_to_int, '5a.6b') - - def test_convert_version_to_string(self): - self.assertEqual(utils.convert_version_to_str(6007000), '6.7.0') - self.assertEqual(utils.convert_version_to_str(4), '4') - - def test_convert_version_to_tuple(self): - self.assertEqual(utils.convert_version_to_tuple('6.7.0'), (6, 7, 0))