xenapi:populating hypervisor version in host state
This will be used in the scheduler to compare it to the image properties. Pulled out conversion of version string into integer to utils. Partially implements blueprint xen-support-for-hypervisor-versions Change-Id: Ib2eb91f6f18af6d39f9381daeff7ba9a24b4785a
This commit is contained in:
54
nova/tests/virt/xenapi/test_driver.py
Normal file
54
nova/tests/virt/xenapi/test_driver.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2013 Rackspace Hosting
|
||||
#
|
||||
# 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 nova.tests.virt.xenapi import stubs
|
||||
from nova.virt import fake
|
||||
from nova.virt.xenapi import XenAPIDriver
|
||||
|
||||
|
||||
class XenAPIDriverTestCase(stubs.XenAPITestBase):
|
||||
"""Unit tests for Driver operations."""
|
||||
|
||||
def host_stats(self, refresh=True):
|
||||
return {'host_memory_total': 3 * 1024 * 1024,
|
||||
'host_memory_free_computed': 2 * 1024 * 1024,
|
||||
'disk_total': 4 * 1024 * 1024 * 1024,
|
||||
'disk_used': 5 * 1024 * 1024 * 1024,
|
||||
'host_hostname': 'somename',
|
||||
'host_cpu_info': {'cpu_count': 50}}
|
||||
|
||||
def test_available_resource(self):
|
||||
self.flags(xenapi_connection_url='test_url',
|
||||
xenapi_connection_password='test_pass')
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
|
||||
driver = XenAPIDriver(fake.FakeVirtAPI(), False)
|
||||
driver._session.product_version = (6, 8, 2)
|
||||
|
||||
self.stubs.Set(driver, 'get_host_stats', self.host_stats)
|
||||
|
||||
resources = driver.get_available_resource(None)
|
||||
self.assertEqual(6008002, resources['hypervisor_version'])
|
||||
self.assertEqual(0, resources['vcpus'])
|
||||
self.assertEqual(3, resources['memory_mb'])
|
||||
self.assertEqual(4, resources['local_gb'])
|
||||
self.assertEqual(0, resources['vcpus_used'])
|
||||
self.assertEqual(3 - 2, resources['memory_mb_used'])
|
||||
self.assertEqual(5, resources['local_gb_used'])
|
||||
self.assertEqual('xen', resources['hypervisor_type'])
|
||||
self.assertEqual('somename', resources['hypervisor_hostname'])
|
||||
self.assertEqual(50, resources['cpu_info'])
|
||||
@@ -1131,3 +1131,7 @@ def is_none_string(val):
|
||||
return False
|
||||
|
||||
return val.lower() == 'none'
|
||||
|
||||
|
||||
def convert_version_to_int(version):
|
||||
return version[0] * 1000000 + version[1] * 1000 + version[2]
|
||||
|
||||
@@ -391,18 +391,15 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
conf.driver_cache = cache_mode
|
||||
|
||||
def has_min_version(self, lv_ver=None, hv_ver=None, hv_type=None):
|
||||
def _munge_version(ver):
|
||||
return ver[0] * 1000000 + ver[1] * 1000 + ver[2]
|
||||
|
||||
try:
|
||||
if lv_ver is not None:
|
||||
libvirt_version = self._conn.getLibVersion()
|
||||
if libvirt_version < _munge_version(lv_ver):
|
||||
if libvirt_version < utils.convert_version_to_int(lv_ver):
|
||||
return False
|
||||
|
||||
if hv_ver is not None:
|
||||
hypervisor_version = self._conn.getVersion()
|
||||
if hypervisor_version < _munge_version(hv_ver):
|
||||
if hypervisor_version < utils.convert_version_to_int(hv_ver):
|
||||
return False
|
||||
|
||||
if hv_type is not None:
|
||||
|
||||
@@ -49,6 +49,7 @@ from oslo.config import cfg
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.openstack.common import log as logging
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
from nova.virt.xenapi import host
|
||||
from nova.virt.xenapi import pool
|
||||
@@ -397,6 +398,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
free_ram_mb = host_stats['host_memory_free_computed'] / (1024 * 1024)
|
||||
total_disk_gb = host_stats['disk_total'] / (1024 * 1024 * 1024)
|
||||
used_disk_gb = host_stats['disk_used'] / (1024 * 1024 * 1024)
|
||||
hyper_ver = utils.convert_version_to_int(self._session.product_version)
|
||||
|
||||
dic = {'vcpus': 0,
|
||||
'memory_mb': total_ram_mb,
|
||||
@@ -405,7 +407,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||
'memory_mb_used': total_ram_mb - free_ram_mb,
|
||||
'local_gb_used': used_disk_gb,
|
||||
'hypervisor_type': 'xen',
|
||||
'hypervisor_version': 0,
|
||||
'hypervisor_version': hyper_ver,
|
||||
'hypervisor_hostname': host_stats['host_hostname'],
|
||||
'cpu_info': host_stats['host_cpu_info']['cpu_count']}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user