Use version convert methods from oslo_utils.versionutils

oslo_utils provide version convert methods in versionutis[1],
so don't need maintain them in nova.

[1]https://github.com/openstack/oslo.utils/blob/master/oslo_utils/versionutils.py

Change-Id: Icbc65ab372379812326265263c2a0b1b20999189
This commit is contained in:
ChangBo Guo(gcb) 2015-07-18 14:31:03 +08:00
parent 0140dbe389
commit 26635e7c49
29 changed files with 108 additions and 136 deletions

View File

@ -22,6 +22,7 @@ import traceback
import netaddr
from oslo_log import log as logging
import oslo_messaging as messaging
from oslo_utils import versionutils
from oslo_versionedobjects import base as ovoo_base
from oslo_versionedobjects import exception as ovoo_exc
import six
@ -47,11 +48,11 @@ class NovaObjectRegistry(ovoo_base.VersionedObjectRegistry):
# NOTE(danms): This is called when an object is registered,
# and is responsible for maintaining nova.objects.$OBJECT
# as the highest-versioned implementation of a given object.
version = utils.convert_version_to_tuple(cls.VERSION)
version = versionutils.convert_version_to_tuple(cls.VERSION)
if not hasattr(objects, cls.obj_name()):
setattr(objects, cls.obj_name(), cls)
else:
cur_version = utils.convert_version_to_tuple(
cur_version = versionutils.convert_version_to_tuple(
getattr(objects, cls.obj_name()).VERSION)
if version >= cur_version:
setattr(objects, cls.obj_name(), cls)

View File

@ -14,6 +14,7 @@
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import versionutils
import six
from nova import db
@ -22,7 +23,6 @@ from nova import objects
from nova.objects import base
from nova.objects import fields
from nova.objects import pci_device_pool
from nova import utils
CONF = cfg.CONF
CONF.import_opt('cpu_allocation_ratio', 'nova.compute.resource_tracker')
@ -86,7 +86,7 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
def obj_make_compatible(self, primitive, target_version):
super(ComputeNode, 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)
if target_version < (1, 14):
if 'ram_allocation_ratio' in primitive:
del primitive['ram_allocation_ratio']

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_utils import timeutils
from oslo_utils import versionutils
from nova import db
from nova import exception
@ -70,7 +71,7 @@ class FixedIP(obj_base.NovaPersistentObject, obj_base.NovaObject,
def obj_make_compatible(self, primitive, target_version):
super(FixedIP, 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)
if target_version < (1, 4) and 'default_route' in primitive:
del primitive['default_route']

View File

@ -13,10 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import versionutils
from nova.compute import hv_type
from nova.objects import base
from nova.objects import fields
from nova import utils
@base.NovaObjectRegistry.register
@ -45,7 +46,7 @@ class HVSpec(base.NovaObject):
def obj_make_compatible(self, primitive, target_version):
super(HVSpec, 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)
if (target_version < (1, 1) and 'hv_type' in primitive and
hv_type.VIRTUOZZO == primitive['hv_type']):
primitive['hv_type'] = hv_type.PARALLELS

View File

@ -14,6 +14,8 @@
import copy
from oslo_utils import versionutils
from nova import exception
from nova import objects
from nova.objects import base
@ -141,7 +143,7 @@ class ImageMetaProps(base.NovaObject):
def obj_make_compatible(self, primitive, target_version):
super(ImageMetaProps, 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)
if target_version < (1, 7):
primitive.pop('img_config_drive', None)
if target_version < (1, 5):

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova.compute import utils as compute_utils
from nova import db
@ -20,7 +21,6 @@ from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
LAZY_LOAD_FIELDS = ['hosts']
@ -58,7 +58,7 @@ class InstanceGroup(base.NovaPersistentObject, base.NovaObject,
}
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 7):
# NOTE(danms): Before 1.7, we had an always-empty
# metadetails property

View File

@ -11,11 +11,11 @@
# under the License.
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova import db
from nova.objects import base
from nova.objects import fields
from nova import utils
# TODO(berrange): Remove NovaObjectDictCompat
@ -47,7 +47,7 @@ class InstancePCIRequest(base.NovaObject,
return self.is_new
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'request_id' in primitive:
del primitive['request_id']
@ -66,7 +66,7 @@ class InstancePCIRequests(base.NovaObject,
}
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'requests' in primitive:
for index, request in enumerate(self.requests):
request.obj_make_compatible(

View File

@ -12,12 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import versionutils
from nova import db
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
KEYPAIR_TYPE_SSH = 'ssh'
KEYPAIR_TYPE_X509 = 'x509'
@ -44,7 +45,7 @@ class KeyPair(base.NovaPersistentObject, base.NovaObject,
def obj_make_compatible(self, primitive, target_version):
super(KeyPair, 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)
if target_version < (1, 2) and 'type' in primitive:
del primitive['type']

View File

@ -12,12 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import versionutils
from nova import db
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
def determine_migration_type(migration):
@ -67,7 +68,7 @@ class Migration(base.NovaPersistentObject, base.NovaObject,
def obj_make_compatible(self, primitive, target_version):
super(Migration, 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)
if target_version < (1, 2):
if 'migration_type' in primitive:
del primitive['migration_type']

View File

@ -11,6 +11,7 @@
# under the License.
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.objects import base
from nova.objects import fields
@ -47,7 +48,7 @@ class MonitorMetric(base.NovaObject):
def obj_make_compatible(self, primitive, target_version):
super(MonitorMetric, 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)
if target_version < (1, 1) and 'numa_nodes_values' in primitive:
del primitive['numa_membw_values']

View File

@ -14,6 +14,7 @@
import netaddr
from oslo_config import cfg
from oslo_utils import versionutils
from nova import db
from nova import exception
@ -21,7 +22,6 @@ from nova.i18n import _
from nova import objects
from nova.objects import base as obj_base
from nova.objects import fields
from nova import utils
network_opts = [
cfg.BoolOpt('share_dhcp_address',
@ -102,7 +102,7 @@ class Network(obj_base.NovaPersistentObject, obj_base.NovaObject,
'or integral prefix') % netmask)
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 2):
if 'mtu' in primitive:
del primitive['mtu']

View File

@ -17,13 +17,13 @@ import copy
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova import db
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
LOG = logging.getLogger(__name__)
@ -110,7 +110,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
}
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 2) and 'request_id' in primitive:
del primitive['request_id']

View File

@ -16,12 +16,12 @@
import copy
from oslo_serialization import jsonutils
from oslo_utils import versionutils
import six
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
@base.NovaObjectRegistry.register
@ -39,7 +39,7 @@ class PciDevicePool(base.NovaObject):
}
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'numa_node' in primitive:
del primitive['numa_node']

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from oslo_utils import versionutils
from nova import availability_zones
from nova import db
@ -21,7 +22,6 @@ from nova.i18n import _LW
from nova import objects
from nova.objects import base
from nova.objects import fields
from nova import utils
LOG = logging.getLogger(__name__)
@ -122,7 +122,7 @@ class Service(base.NovaPersistentObject, base.NovaObject,
version_manifest):
super(Service, self).obj_make_compatible_from_manifest(
primitive, target_version, version_manifest)
_target_version = utils.convert_version_to_tuple(target_version)
_target_version = versionutils.convert_version_to_tuple(target_version)
if _target_version < (1, 16) and 'version' in primitive:
del primitive['version']
if _target_version < (1, 14) and 'forced_down' in primitive:

View File

@ -17,12 +17,12 @@
from distutils import versionpredicate
from oslo_log import log as logging
from oslo_utils import versionutils
from nova.compute import arch
from nova.compute import hv_type
from nova.compute import vm_mode
from nova.scheduler import filters
from nova import utils
LOG = logging.getLogger(__name__)
@ -78,7 +78,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter):
return True
img_prop_predicate = versionpredicate.VersionPredicate(
'image_prop (%s)' % version_required)
hyper_ver_str = utils.convert_version_to_str(hyper_version)
hyper_ver_str = versionutils.convert_version_to_str(hyper_version)
return img_prop_predicate.satisfied_by(hyper_ver_str)
for supp_inst in supp_instances:

View File

@ -15,11 +15,11 @@
import mock
from oslo_config import cfg
from oslo_utils import versionutils
from nova.conductor import manager as conductor_manager
from nova import db
from nova.tests.functional.api_sample_tests import test_servers
from nova import utils
CONF = cfg.CONF
CONF.import_opt('osapi_compute_extension',
@ -72,8 +72,8 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase):
report_count=1,
updated_at='foo',
hypervisor_type='bar',
hypervisor_version=utils.convert_version_to_int(
'1.0'),
hypervisor_version=(
versionutils.convert_version_to_int('1.0')),
disabled=False)
return {'compute_node': [service]}
self.stubs.Set(db, "service_get_by_compute_host", fake_get_compute)

View File

@ -23,6 +23,7 @@ import fixtures
import mock
from oslo_log import log
from oslo_utils import timeutils
from oslo_utils import versionutils
from oslo_versionedobjects import base as ovo_base
from oslo_versionedobjects import exception as ovo_exc
from oslo_versionedobjects import fixture
@ -1307,7 +1308,7 @@ class TestObjectVersions(test.NoDBTestCase):
for obj_name in obj_classes:
versions = ovo_base.obj_tree_get_versions(obj_name)
obj_class = obj_classes[obj_name][0]
version = utils.convert_version_to_tuple(obj_class.VERSION)
version = versionutils.convert_version_to_tuple(obj_class.VERSION)
for n in range(version[1]):
test_version = '%d.%d' % (version[0], n)
LOG.info('testing obj: %s version: %s' %

View File

@ -10,13 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import versionutils
from nova.compute import arch
from nova.compute import hv_type
from nova.compute import vm_mode
from nova.scheduler.filters import image_props_filter
from nova import test
from nova.tests.unit.scheduler import fakes
from nova import utils
class TestImagePropsFilter(test.NoDBTestCase):
@ -32,7 +33,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
'hypervisor_version_requires': '>=6.0,<6.2'
}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -44,7 +45,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
'hypervisor_type': hv_type.QEMU,
'vm_mode': vm_mode.HVM}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -57,7 +58,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
'vm_mode': vm_mode.HVM,
'hypervisor_version_requires': '>=6.2'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'enabled': True,
'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
@ -69,7 +70,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
img_props = {'properties': {'architecture': arch.X86_64,
'vm_mode': vm_mode.HVM}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -80,7 +81,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
img_props = {'properties': {'architecture': arch.X86_64,
'vm_mode': vm_mode.HVM}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.XEN, vm_mode.XEN)],
'hypervisor_version': hypervisor_version}
@ -89,7 +90,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
def test_image_properties_filter_passes_without_inst_props(self):
filter_properties = {'request_spec': {}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -101,7 +102,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
'hypervisor_type': hv_type.KVM,
'vm_mode': vm_mode.HVM}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'enabled': True,
'hypervisor_version': hypervisor_version}
host = fakes.FakeHostState('host1', 'node1', capabilities)
@ -136,7 +137,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
# if an old image has 'pv' for a vm_mode it should be treated as xen
img_props = {'properties': {'vm_mode': 'pv'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.XEN, vm_mode.XEN)],
'hypervisor_version': hypervisor_version}
@ -147,7 +148,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
# if an old image has 'hv' for a vm_mode it should be treated as xen
img_props = {'properties': {'vm_mode': 'hv'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.X86_64, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -158,7 +159,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
# if an old image has 'x86_32' for arch it should be treated as i686
img_props = {'properties': {'architecture': 'x86_32'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.I686, hv_type.KVM, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -169,7 +170,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
# if an old image has 'xapi' for hv_type it should be treated as xen
img_props = {'properties': {'hypervisor_type': 'xapi'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.I686, hv_type.XEN, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}
@ -181,7 +182,7 @@ class TestImagePropsFilter(test.NoDBTestCase):
# treated as hvm
img_props = {'properties': {'vm_mode': 'baremetal'}}
filter_properties = {'request_spec': {'image': img_props}}
hypervisor_version = utils.convert_version_to_int('6.0.0')
hypervisor_version = versionutils.convert_version_to_int('6.0.0')
capabilities = {'supported_instances':
[(arch.I686, hv_type.BAREMETAL, vm_mode.HVM)],
'hypervisor_version': hypervisor_version}

View File

@ -22,6 +22,7 @@ import datetime
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import versionutils
import six
import nova
@ -37,7 +38,6 @@ from nova import test
from nova.tests.unit import fake_instance
from nova.tests.unit import matchers
from nova.tests.unit.scheduler import fakes
from nova import utils
CONF = cfg.CONF
CONF.import_opt('scheduler_tracks_instance_changes',
@ -811,7 +811,7 @@ class HostStateTestCase(test.NoDBTestCase):
'io_workload': '42',
}
hyper_ver_int = utils.convert_version_to_int('6.0.0')
hyper_ver_int = versionutils.convert_version_to_int('6.0.0')
compute = objects.ComputeNode(
stats=stats, memory_mb=1, free_disk_gb=0, local_gb=0,
local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
@ -852,7 +852,7 @@ class HostStateTestCase(test.NoDBTestCase):
'io_workload': '42',
}
hyper_ver_int = utils.convert_version_to_int('6.0.0')
hyper_ver_int = versionutils.convert_version_to_int('6.0.0')
compute = objects.ComputeNode(
stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0,
local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
@ -884,7 +884,7 @@ class HostStateTestCase(test.NoDBTestCase):
'io_workload': '42',
}
hyper_ver_int = utils.convert_version_to_int('6.0.0')
hyper_ver_int = versionutils.convert_version_to_int('6.0.0')
compute = objects.ComputeNode(
stats=stats, memory_mb=0, free_disk_gb=0, local_gb=0,
local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0,
@ -1038,7 +1038,7 @@ class HostStateTestCase(test.NoDBTestCase):
source='source2',
timestamp=_ts_now),
]
hyper_ver_int = utils.convert_version_to_int('6.0.0')
hyper_ver_int = versionutils.convert_version_to_int('6.0.0')
compute = objects.ComputeNode(
metrics=jsonutils.dumps(metrics),
memory_mb=0, free_disk_gb=0, local_gb=0,

View File

@ -1211,22 +1211,6 @@ class GetImageMetadataFromVolumeTestCase(test.NoDBTestCase):
self.assertNotEqual({}, properties)
class VersionTestCase(test.NoDBTestCase):
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.NovaException,
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))
class ConstantTimeCompareTestCase(test.NoDBTestCase):
def test_constant_time_compare(self):
self.assertTrue(utils.constant_time_compare("abcd1234", "abcd1234"))

View File

@ -45,6 +45,7 @@ from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import units
from oslo_utils import uuidutils
from oslo_utils import versionutils
import six
from six.moves import builtins
from six.moves import range
@ -647,7 +648,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
"dummyhost")
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.NEXT_MIN_LIBVIRT_VERSION) - 1)
@mock.patch.object(libvirt_driver.LOG, 'warning')
def test_next_min_version_deprecation_warning(self, mock_warning,
@ -666,7 +667,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertTrue(version_arg_found)
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.NEXT_MIN_LIBVIRT_VERSION))
@mock.patch.object(libvirt_driver.LOG, 'warning')
def test_next_min_version_ok(self, mock_warning, mock_get_libversion):
@ -684,10 +685,10 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertFalse(version_arg_found)
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_KVM_S390_VERSION) - 1)
@mock.patch.object(fakelibvirt.Connection, 'getVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_S390_VERSION))
@mock.patch.object(arch, "from_host", return_value=arch.S390X)
def test_min_version_s390_old_libvirt(self, mock_arch,
@ -698,10 +699,10 @@ class LibvirtConnTestCase(test.NoDBTestCase):
"dummyhost")
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_KVM_S390_VERSION))
@mock.patch.object(fakelibvirt.Connection, 'getVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_S390_VERSION) - 1)
@mock.patch.object(arch, "from_host", return_value=arch.S390X)
def test_min_version_s390_old_qemu(self, mock_arch,
@ -712,10 +713,10 @@ class LibvirtConnTestCase(test.NoDBTestCase):
"dummyhost")
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_KVM_S390_VERSION))
@mock.patch.object(fakelibvirt.Connection, 'getVersion',
return_value=utils.convert_version_to_int(
return_value=versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_S390_VERSION))
@mock.patch.object(arch, "from_host", return_value=arch.S390X)
def test_min_version_s390_ok(self, mock_arch,
@ -1574,9 +1575,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION) - 1,
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION),
host.HV_DRIVER_QEMU,
arch.X86_64,
@ -1587,9 +1588,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.BAD_LIBVIRT_NUMA_VERSIONS[0]),
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION),
host.HV_DRIVER_QEMU,
arch.X86_64,
@ -1614,9 +1615,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION),
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION) - 1,
host.HV_DRIVER_QEMU,
arch.X86_64,
@ -1627,9 +1628,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION),
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION),
host.HV_DRIVER_QEMU,
arch.PPC64,
@ -1640,9 +1641,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='xen', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION),
utils.convert_version_to_int((4, 5, 0)),
versionutils.convert_version_to_int((4, 5, 0)),
'XEN',
arch.X86_64,
exception.NUMATopologyUnsupported,
@ -1652,9 +1653,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_HUGEPAGE_VERSION) - 1,
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION),
host.HV_DRIVER_QEMU,
arch.X86_64,
@ -1665,9 +1666,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
self._test_get_guest_config_numa_unsupported(
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_HUGEPAGE_VERSION),
utils.convert_version_to_int(
versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION) - 1,
host.HV_DRIVER_QEMU,
arch.X86_64,
@ -9988,9 +9989,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
def test_get_host_numa_topology_no_mempages(self, mock_lib_version,
mock_version, mock_type):
self.flags(virt_type='kvm', group='libvirt')
mock_lib_version.return_value = utils.convert_version_to_int(
mock_lib_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_HUGEPAGE_VERSION) - 1
mock_version.return_value = utils.convert_version_to_int(
mock_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION)
mock_type.return_value = host.HV_DRIVER_QEMU
self._test_get_host_numa_topology(mempages=False)
@ -10019,9 +10020,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='kvm', group='libvirt')
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
mock_lib_version.return_value = utils.convert_version_to_int(
mock_lib_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION) - 1
mock_version.return_value = utils.convert_version_to_int(
mock_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION)
mock_type.return_value = host.HV_DRIVER_QEMU
self.assertIsNone(drvr._get_host_numa_topology())
@ -10034,9 +10035,9 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(virt_type='xen', group='libvirt')
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
mock_lib_version.return_value = utils.convert_version_to_int(
mock_lib_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_LIBVIRT_NUMA_VERSION)
mock_version.return_value = utils.convert_version_to_int(
mock_version.return_value = versionutils.convert_version_to_int(
libvirt_driver.MIN_QEMU_NUMA_HUGEPAGE_VERSION)
mock_type.return_value = host.HV_DRIVER_XEN
self.assertIsNone(drvr._get_host_numa_topology())

View File

@ -1212,32 +1212,6 @@ def is_none_string(val):
return val.lower() == 'none'
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 = _("Hypervisor version %s is invalid.") % version
raise exception.NovaException(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 six.moves.reduce(lambda x, y: "%s.%s" % (x, y), version_numbers)
def convert_version_to_tuple(version_str):
return tuple(int(part) for part in version_str.split('.'))
def is_neutron():
global _IS_NEUTRON

View File

@ -29,6 +29,7 @@ import contextlib
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.compute import arch
from nova.compute import hv_type
@ -39,7 +40,6 @@ from nova.console import type as ctype
from nova import db
from nova import exception
from nova.i18n import _LW
from nova import utils
from nova.virt import diagnostics
from nova.virt import driver
from nova.virt import hardware
@ -145,7 +145,7 @@ class FakeDriver(driver.ComputeDriver):
local_gb=self.local_gb)
self.host_status_base = {
'hypervisor_type': 'fake',
'hypervisor_version': utils.convert_version_to_int('1.0'),
'hypervisor_version': versionutils.convert_version_to_int('1.0'),
'hypervisor_hostname': CONF.host,
'cpu_info': {},
'disk_available_least': 0,

View File

@ -42,6 +42,7 @@ from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import importutils
from oslo_utils import units
from oslo_utils import versionutils
import six
from nova import context as nova_context
@ -561,13 +562,14 @@ class Host(object):
try:
if lv_ver is not None:
libvirt_version = conn.getLibVersion()
if op(libvirt_version, utils.convert_version_to_int(lv_ver)):
if op(libvirt_version,
versionutils.convert_version_to_int(lv_ver)):
return False
if hv_ver is not None:
hypervisor_version = conn.getVersion()
if op(hypervisor_version,
utils.convert_version_to_int(hv_ver)):
versionutils.convert_version_to_int(hv_ver)):
return False
if hv_type is not None:

View File

@ -25,6 +25,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
from oslo_utils import versionutils as v_utils
from oslo_vmware import api
from oslo_vmware import exceptions as vexc
from oslo_vmware import pbm
@ -34,7 +35,6 @@ from oslo_vmware import vim_util
from nova.compute import task_states
from nova.compute import vm_states
from nova import exception
from nova import utils
from nova.i18n import _, _LI, _LE, _LW
from nova import objects
from nova.virt import driver
@ -193,10 +193,10 @@ class VMwareVCDriver(driver.ComputeDriver):
self._register_openstack_extension()
def _check_min_version(self):
min_version = utils.convert_version_to_int(constants.MIN_VC_VERSION)
min_version = v_utils.convert_version_to_int(constants.MIN_VC_VERSION)
vc_version = vim_util.get_vc_version(self._session)
LOG.info(_LI("VMware vCenter version: %s"), vc_version)
if min_version > utils.convert_version_to_int(vc_version):
if min_version > v_utils.convert_version_to_int(vc_version):
# TODO(garyk): enforce this from M
LOG.warning(_LW('Running Nova with a VMware vCenter version less '
'than %(version)s is deprecated. The required '

View File

@ -18,12 +18,12 @@ Management class for host-related functions (start, reboot, etc).
"""
from oslo_utils import units
from oslo_utils import versionutils
from nova.compute import arch
from nova.compute import hv_type
from nova.compute import vm_mode
from nova import exception
from nova import utils
from nova.virt.vmwareapi import ds_util
from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
@ -76,7 +76,7 @@ class VCState(object):
data["host_memory_total"] = stats['mem']['total']
data["host_memory_free"] = stats['mem']['free']
data["hypervisor_type"] = about_info.name
data["hypervisor_version"] = utils.convert_version_to_int(
data["hypervisor_version"] = versionutils.convert_version_to_int(
str(about_info.version))
data["hypervisor_hostname"] = self._host_name
data["supported_instances"] = [

View File

@ -17,12 +17,12 @@
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import versionutils
from oslo_vmware import vim_util
from nova import exception
from nova.i18n import _, _LW
from nova.network import model
from nova import utils
from nova.virt.vmwareapi import constants
from nova.virt.vmwareapi import network_util
from nova.virt.vmwareapi import vm_util
@ -105,9 +105,9 @@ def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
def _check_ovs_supported_version(session):
# The port type 'ovs' is only support by the VC version 5.5 onwards
min_version = utils.convert_version_to_int(
min_version = versionutils.convert_version_to_int(
constants.MIN_VC_OVS_VERSION)
vc_version = utils.convert_version_to_int(
vc_version = versionutils.convert_version_to_int(
vim_util.get_vc_version(session))
if vc_version < min_version:
LOG.warning(_LW('VMware vCenter version less than %(version)s '

View File

@ -39,7 +39,6 @@ from nova import context
from nova import exception
from nova.i18n import _, _LE, _LW
from nova import objects
from nova import utils
from nova import version
from nova.virt.xenapi.client import objects as cli_objects
from nova.virt.xenapi import pool
@ -174,7 +173,8 @@ class XenAPISession(object):
product_version_str = software_version.get('platform_version',
'0.0.0')
product_brand = software_version.get('product_brand')
product_version = utils.convert_version_to_tuple(product_version_str)
product_version = versionutils.convert_version_to_tuple(
product_version_str)
return product_version, product_brand

View File

@ -29,12 +29,12 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import units
from oslo_utils import versionutils
import six
import six.moves.urllib.parse as urlparse
from nova.i18n import _, _LE, _LW
from nova import objects
from nova import utils
from nova.virt import driver
from nova.virt.xenapi.client import session
from nova.virt.xenapi import host
@ -446,7 +446,8 @@ class XenAPIDriver(driver.ComputeDriver):
total_disk_gb = host_stats['disk_total'] / units.Gi
used_disk_gb = host_stats['disk_used'] / units.Gi
allocated_disk_gb = host_stats['disk_allocated'] / units.Gi
hyper_ver = utils.convert_version_to_int(self._session.product_version)
hyper_ver = versionutils.convert_version_to_int(
self._session.product_version)
dic = {'vcpus': host_stats['host_cpu_info']['cpu_count'],
'memory_mb': total_ram_mb,
'local_gb': total_disk_gb,