Merge "libvirt: sync get_available_resources and get_host_stats"
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"hypervisor": {
|
||||
"cpu_info": "?",
|
||||
"current_workload": 0,
|
||||
"disk_available_least": null,
|
||||
"disk_available_least": 0,
|
||||
"free_disk_gb": 1028,
|
||||
"free_ram_mb": 7680,
|
||||
"hypervisor_hostname": "fake-mini",
|
||||
@@ -21,4 +21,4 @@
|
||||
"vcpus": 1,
|
||||
"vcpus_used": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="1">
|
||||
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="0" local_gb="1028" free_ram_mb="7680" id="1">
|
||||
<service host="807e1a43ceb740138eea32969c3e9fe5" id="2"/>
|
||||
</hypervisor>
|
||||
</hypervisor>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"hypervisor": {
|
||||
"cpu_info": "?",
|
||||
"current_workload": 0,
|
||||
"disk_available_least": null,
|
||||
"disk_available_least": 0,
|
||||
"free_disk_gb": 1028,
|
||||
"free_ram_mb": 7680,
|
||||
"hypervisor_hostname": "fake-mini",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="None" local_gb="1028" free_ram_mb="7680" id="%(hypervisor_id)s">
|
||||
<hypervisor vcpus_used="0" hypervisor_type="fake" local_gb_used="0" hypervisor_hostname="fake-mini" memory_mb_used="512" memory_mb="8192" current_workload="0" vcpus="1" cpu_info="?" running_vms="0" free_disk_gb="1028" hypervisor_version="1" disk_available_least="0" local_gb="1028" free_ram_mb="7680" id="%(hypervisor_id)s">
|
||||
<service host="%(host_name)s" id="2"/>
|
||||
</hypervisor>
|
||||
|
||||
@@ -4418,6 +4418,9 @@ class HostStateTestCase(test.TestCase):
|
||||
def get_cpu_info(self):
|
||||
return HostStateTestCase.cpu_info
|
||||
|
||||
def get_disk_over_committed_size_total(self):
|
||||
return 0
|
||||
|
||||
def get_local_gb_info(self):
|
||||
return {'total': 100, 'used': 20, 'free': 80}
|
||||
|
||||
@@ -4450,22 +4453,22 @@ class HostStateTestCase(test.TestCase):
|
||||
hs = libvirt_driver.HostState(self.FakeConnection())
|
||||
stats = hs._stats
|
||||
self.assertEquals(stats["vcpus"], 1)
|
||||
self.assertEquals(stats["memory_mb"], 497)
|
||||
self.assertEquals(stats["local_gb"], 100)
|
||||
self.assertEquals(stats["vcpus_used"], 0)
|
||||
self.assertEquals(stats["cpu_info"],
|
||||
self.assertEquals(stats["memory_mb_used"], 88)
|
||||
self.assertEquals(stats["local_gb_used"], 20)
|
||||
self.assertEquals(stats["hypervisor_type"], 'QEMU')
|
||||
self.assertEquals(stats["hypervisor_version"], 13091)
|
||||
self.assertEquals(stats["hypervisor_hostname"], 'compute1')
|
||||
self.assertEquals(jsonutils.loads(stats["cpu_info"]),
|
||||
{"vendor": "Intel", "model": "pentium", "arch": "i686",
|
||||
"features": ["ssse3", "monitor", "pni", "sse2", "sse",
|
||||
"fxsr", "clflush", "pse36", "pat", "cmov",
|
||||
"mca", "pge", "mtrr", "sep", "apic"],
|
||||
"topology": {"cores": "1", "threads": "1", "sockets": "1"}
|
||||
})
|
||||
self.assertEquals(stats["disk_total"], 100)
|
||||
self.assertEquals(stats["disk_used"], 20)
|
||||
self.assertEquals(stats["disk_available"], 80)
|
||||
self.assertEquals(stats["host_memory_total"], 497)
|
||||
self.assertEquals(stats["host_memory_free"], 409)
|
||||
self.assertEquals(stats["hypervisor_type"], 'QEMU')
|
||||
self.assertEquals(stats["hypervisor_version"], 13091)
|
||||
self.assertEquals(stats["hypervisor_hostname"], 'compute1')
|
||||
self.assertEquals(stats["disk_available_least"], 80)
|
||||
|
||||
|
||||
class NWFilterFakes:
|
||||
|
||||
@@ -567,16 +567,23 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||
lambda *a: None, lambda *a: None)
|
||||
|
||||
@catch_notimplementederror
|
||||
def _check_host_status_fields(self, host_status):
|
||||
self.assertIn('disk_total', host_status)
|
||||
self.assertIn('disk_used', host_status)
|
||||
self.assertIn('host_memory_total', host_status)
|
||||
self.assertIn('host_memory_free', host_status)
|
||||
def _check_available_resouce_fields(self, host_status):
|
||||
keys = ['vcpus', 'memory_mb', 'local_gb', 'vcpus_used',
|
||||
'memory_mb_used', 'hypervisor_type', 'hypervisor_version',
|
||||
'hypervisor_hostname', 'cpu_info', 'disk_available_least']
|
||||
for key in keys:
|
||||
self.assertIn(key, host_status)
|
||||
|
||||
@catch_notimplementederror
|
||||
def test_get_host_stats(self):
|
||||
host_status = self.connection.get_host_stats()
|
||||
self._check_host_status_fields(host_status)
|
||||
self._check_available_resouce_fields(host_status)
|
||||
|
||||
@catch_notimplementederror
|
||||
def test_get_available_resource(self):
|
||||
available_resource = self.connection.get_available_resource(
|
||||
'myhostname')
|
||||
self._check_available_resouce_fields(available_resource)
|
||||
|
||||
@catch_notimplementederror
|
||||
def test_set_host_enabled(self):
|
||||
@@ -682,6 +689,7 @@ class AbstractDriverTestCase(_VirtDriverTestCase, test.TestCase):
|
||||
class FakeConnectionTestCase(_VirtDriverTestCase, test.TestCase):
|
||||
def setUp(self):
|
||||
self.driver_module = 'nova.virt.fake.FakeDriver'
|
||||
fake.set_nodes(['myhostname'])
|
||||
super(FakeConnectionTestCase, self).setUp()
|
||||
|
||||
|
||||
|
||||
+11
-14
@@ -90,21 +90,17 @@ class FakeDriver(driver.ComputeDriver):
|
||||
super(FakeDriver, self).__init__(virtapi)
|
||||
self.instances = {}
|
||||
self.host_status_base = {
|
||||
'host_name-description': 'Fake Host',
|
||||
'host_hostname': CONF.host,
|
||||
'host_memory_total': 8000000000,
|
||||
'host_memory_overhead': 10000000,
|
||||
'host_memory_free': 7900000000,
|
||||
'host_memory_free_computed': 7900000000,
|
||||
'host_other_config': {},
|
||||
'host_ip_address': '192.168.1.109',
|
||||
'host_cpu_info': {},
|
||||
'disk_available': 500000000000,
|
||||
'disk_total': 600000000000,
|
||||
'disk_used': 100000000000,
|
||||
'host_uuid': 'cedb9b39-9388-41df-8891-c5c9a0c0fe5f',
|
||||
'host_name_label': 'fake-host',
|
||||
'vcpus': 100000,
|
||||
'memory_mb': 8000000000,
|
||||
'local_gb': 600000000000,
|
||||
'vcpus_used': 0,
|
||||
'memory_mb_used': 0,
|
||||
'local_gb_used': 100000000000,
|
||||
'hypervisor_type': 'fake',
|
||||
'hypervisor_version': '1.0',
|
||||
'hypervisor_hostname': CONF.host,
|
||||
'cpu_info': {},
|
||||
'disk_available_least': 500000000000,
|
||||
}
|
||||
self._mounts = {}
|
||||
self._interfaces = {}
|
||||
@@ -354,6 +350,7 @@ class FakeDriver(driver.ComputeDriver):
|
||||
'hypervisor_type': 'fake',
|
||||
'hypervisor_version': '1.0',
|
||||
'hypervisor_hostname': nodename,
|
||||
'disk_available_least': 0,
|
||||
'cpu_info': '?'}
|
||||
return dic
|
||||
|
||||
|
||||
+26
-38
@@ -3090,36 +3090,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
:returns: dictionary describing resources
|
||||
|
||||
"""
|
||||
|
||||
def _get_disk_available_least():
|
||||
"""Return total real disk available least size.
|
||||
|
||||
The size of available disk, when block_migration command given
|
||||
disk_over_commit param is FALSE.
|
||||
|
||||
The size that deducted real instance disk size from the total size
|
||||
of the virtual disk of all instances.
|
||||
|
||||
"""
|
||||
disk_free_gb = disk_info_dict['free']
|
||||
disk_over_committed = self.get_disk_over_committed_size_total()
|
||||
# Disk available least size
|
||||
available_least = disk_free_gb * (1024 ** 3) - disk_over_committed
|
||||
return (available_least / (1024 ** 3))
|
||||
|
||||
disk_info_dict = self.get_local_gb_info()
|
||||
dic = {'vcpus': self.get_vcpu_total(),
|
||||
'memory_mb': self.get_memory_mb_total(),
|
||||
'local_gb': disk_info_dict['total'],
|
||||
'vcpus_used': self.get_vcpu_used(),
|
||||
'memory_mb_used': self.get_memory_mb_used(),
|
||||
'local_gb_used': disk_info_dict['used'],
|
||||
'hypervisor_type': self.get_hypervisor_type(),
|
||||
'hypervisor_version': self.get_hypervisor_version(),
|
||||
'hypervisor_hostname': self.get_hypervisor_hostname(),
|
||||
'cpu_info': self.get_cpu_info(),
|
||||
'disk_available_least': _get_disk_available_least()}
|
||||
return dic
|
||||
return self.host_state.get_host_stats(refresh=True)
|
||||
|
||||
def check_instance_shared_storage_local(self, context, instance):
|
||||
dirpath = libvirt_utils.get_instance_path(instance)
|
||||
@@ -4125,21 +4096,38 @@ class HostState(object):
|
||||
|
||||
def update_status(self):
|
||||
"""Retrieve status info from libvirt."""
|
||||
def _get_disk_available_least():
|
||||
"""Return total real disk available least size.
|
||||
|
||||
The size of available disk, when block_migration command given
|
||||
disk_over_commit param is FALSE.
|
||||
|
||||
The size that deducted real instance disk size from the total size
|
||||
of the virtual disk of all instances.
|
||||
|
||||
"""
|
||||
disk_free_gb = disk_info_dict['free']
|
||||
disk_over_committed = (self.driver.
|
||||
get_disk_over_committed_size_total())
|
||||
# Disk available least size
|
||||
available_least = disk_free_gb * (1024 ** 3) - disk_over_committed
|
||||
return (available_least / (1024 ** 3))
|
||||
|
||||
LOG.debug(_("Updating host stats"))
|
||||
disk_info_dict = self.driver.get_local_gb_info()
|
||||
data = {}
|
||||
data["vcpus"] = self.driver.get_vcpu_total()
|
||||
data["memory_mb"] = self.driver.get_memory_mb_total()
|
||||
data["local_gb"] = disk_info_dict['total']
|
||||
data["vcpus_used"] = self.driver.get_vcpu_used()
|
||||
data["cpu_info"] = jsonutils.loads(self.driver.get_cpu_info())
|
||||
disk_info_dict = self.driver.get_local_gb_info()
|
||||
data["disk_total"] = disk_info_dict['total']
|
||||
data["disk_used"] = disk_info_dict['used']
|
||||
data["disk_available"] = disk_info_dict['free']
|
||||
data["host_memory_total"] = self.driver.get_memory_mb_total()
|
||||
data["host_memory_free"] = (data["host_memory_total"] -
|
||||
self.driver.get_memory_mb_used())
|
||||
data["memory_mb_used"] = self.driver.get_memory_mb_used()
|
||||
data["local_gb_used"] = disk_info_dict['used']
|
||||
data["hypervisor_type"] = self.driver.get_hypervisor_type()
|
||||
data["hypervisor_version"] = self.driver.get_hypervisor_version()
|
||||
data["hypervisor_hostname"] = self.driver.get_hypervisor_hostname()
|
||||
data["cpu_info"] = self.driver.get_cpu_info()
|
||||
data['disk_available_least'] = _get_disk_available_least()
|
||||
|
||||
data["supported_instances"] = \
|
||||
self.driver.get_instance_capabilities()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user