def test_stat_consumption_from_compute_node_rescue_unshelving(self): stats = { 'num_instances': '5', 'num_proj_12345': '3', 'num_proj_23456': '1', 'num_vm_%s' % vm_states.BUILDING: '2', 'num_vm_%s' % vm_states.SUSPENDED: '1', 'num_task_%s' % task_states.UNSHELVING: '1', 'num_task_%s' % task_states.RESCUING: '2', 'num_os_type_linux': '4', 'num_os_type_windoze': '1', 'io_workload': '42', } hyper_ver_int = utils.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, disk_available_least=None, updated_at=None, host_ip='127.0.0.1', hypervisor_type='htype', hypervisor_hostname='hostname', cpu_info='cpu_info', supported_hv_specs=[], hypervisor_version=hyper_ver_int, numa_topology=None, pci_device_pools=None, metrics=None) host = host_manager.HostState("fakehost", "fakenode") host.update_from_compute_node(compute) self.assertEqual(5, host.num_instances) self.assertEqual(42, host.num_io_ops) self.assertEqual(10, len(host.stats)) self.assertEqual([], host.pci_stats.pools) self.assertEqual(hyper_ver_int, host.hypervisor_version)
def test_resources_consumption_from_compute_node(self): metrics = [ dict(name='res1', value=1.0, source='source1', timestamp=None), dict(name='res2', value="string2", source='source2', timestamp=None), ] hyper_ver_int = utils.convert_version_to_int('6.0.0') compute = objects.ComputeNode( metrics=jsonutils.dumps(metrics), memory_mb=0, free_disk_gb=0, local_gb=0, local_gb_used=0, free_ram_mb=0, vcpus=0, vcpus_used=0, disk_available_least=None, updated_at=None, host_ip='127.0.0.1', hypervisor_type='htype', hypervisor_hostname='hostname', cpu_info='cpu_info', supported_hv_specs=[], hypervisor_version=hyper_ver_int, numa_topology=fakes.NUMA_TOPOLOGY._to_json(), stats=None, pci_device_pools=None) host = host_manager.HostState("fakehost", "fakenode") host.update_from_compute_node(compute) self.assertEqual(len(host.metrics), 2) self.assertEqual(set(['res1', 'res2']), set(host.metrics.keys())) self.assertEqual(1.0, host.metrics['res1'].value) self.assertEqual('source1', host.metrics['res1'].source) self.assertEqual('string2', host.metrics['res2'].value) self.assertEqual('source2', host.metrics['res2'].source) self.assertIsInstance(host.numa_topology, six.string_types)
def update_status(self): """Update the current state of the cluster.""" capacity, freespace = _get_ds_capacity_and_freespace(self._session, self._cluster, self._datastore_regex) # Get cpu, memory stats from the cluster stats = vm_util.get_stats_from_cluster(self._session, self._cluster) about_info = self._session._call_method(vim_util, "get_about_info") data = {} data["vcpus"] = stats['vcpus'] data["disk_total"] = capacity / units.Gi data["disk_available"] = freespace / units.Gi data["disk_used"] = data["disk_total"] - data["disk_available"] 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( str(about_info.version)) data["hypervisor_hostname"] = self._host_name data["supported_instances"] = [ (arch.I686, hv_type.VMWARE, vm_mode.HVM), (arch.X86_64, hv_type.VMWARE, vm_mode.HVM)] self._stats = data return data
def __init__(self, virtapi, read_only=False): super(FakeDriver, self).__init__(virtapi) self.instances = {} self.resources = Resources(vcpus=self.vcpus, memory_mb=self.memory_mb, local_gb=self.local_gb) self.host_status_base = { 'hypervisor_type': 'fake', 'hypervisor_version': utils.convert_version_to_int('1.0'), 'hypervisor_hostname': CONF.host, 'cpu_info': {}, 'disk_available_least': 0, 'supported_instances': jsonutils.dumps([(arch.X86_64, hv_type.FAKE, vm_mode.HVM)]), 'numa_topology': None, } self._mounts = {} self._interfaces = {} if not _FAKE_NODES: set_nodes([CONF.host])
def update_status(self): """Update the current state of the cluster.""" capacity, freespace = _get_ds_capacity_and_freespace( self._session, self._cluster, self._datastore_regex) # Get cpu, memory stats from the cluster stats = vm_util.get_stats_from_cluster(self._session, self._cluster) about_info = self._session._call_method(vim_util, "get_about_info") data = {} data["vcpus"] = stats['vcpus'] data["disk_total"] = capacity / units.Gi data["disk_available"] = freespace / units.Gi data["disk_used"] = data["disk_total"] - data["disk_available"] 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( str(about_info.version)) data["hypervisor_hostname"] = self._host_name data["supported_instances"] = [ (arch.I686, hv_type.VMWARE, vm_mode.HVM), (arch.X86_64, hv_type.VMWARE, vm_mode.HVM) ] self._stats = data return data
def test_image_properties_filter_passes_without_inst_props(self): filter_properties = {'request_spec': {}} hypervisor_version = utils.convert_version_to_int('6.0.0') capabilities = {'supported_instances': [(arch.X86_64, hv_type.KVM, vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_image_properties_filter_fails_partial_inst_props(self): 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') capabilities = {'supported_instances': [(arch.X86_64, hv_type.XEN, vm_mode.XEN)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def test_image_properties_filter_xen_hv_type_compat(self): # 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') capabilities = {'supported_instances': [(arch.I686, hv_type.XEN, vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def test_image_properties_filter_fails_without_host_props(self): img_props = {'properties': {'architecture': arch.X86_64, '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') capabilities = {'enabled': True, 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def test_image_properties_filter_baremetal_vmmode_compat(self): # if an old image has 'baremetal' for vmmode it should be # 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') capabilities = {'supported_instances': [(arch.I686, hv_type.BAREMETAL, vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
def fake_get_compute(context, host): service = dict(host=host, binary='patron-compute', topic='compute', report_count=1, updated_at='foo', hypervisor_type='bar', hypervisor_version=utils.convert_version_to_int( '1.0'), disabled=False) return {'compute_node': [service]}
def fake_get_compute(context, host): service = dict( host=host, binary="patron-compute", topic="compute", report_count=1, updated_at="foo", hypervisor_type="bar", hypervisor_version=utils.convert_version_to_int("1.0"), disabled=False, ) return {"compute_node": [service]}
def test_image_properties_filter_fails_different_hyper_version(self): img_props = {'properties': {'architecture': arch.X86_64, 'hypervisor_type': hv_type.KVM, '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') capabilities = {'enabled': True, 'supported_instances': [(arch.X86_64, hv_type.KVM, vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
def _version_check(self, lv_ver=None, hv_ver=None, hv_type=None, op=operator.lt): conn = self.get_connection() try: if lv_ver is not None: libvirt_version = conn.getLibVersion() if op(libvirt_version, utils.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)): return False if hv_type is not None: hypervisor_type = conn.getType() if hypervisor_type != hv_type: return False return True except Exception: return False
def test_stat_consumption_from_compute_node(self): stats = { 'num_instances': '5', 'num_proj_12345': '3', 'num_proj_23456': '1', 'num_vm_%s' % vm_states.BUILDING: '2', 'num_vm_%s' % vm_states.SUSPENDED: '1', 'num_task_%s' % task_states.RESIZE_MIGRATING: '1', 'num_task_%s' % task_states.MIGRATING: '2', 'num_os_type_linux': '4', 'num_os_type_windoze': '1', 'io_workload': '42', } hyper_ver_int = utils.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, disk_available_least=None, updated_at=None, host_ip='127.0.0.1', hypervisor_type='htype', hypervisor_hostname='hostname', cpu_info='cpu_info', supported_hv_specs=[], hypervisor_version=hyper_ver_int, numa_topology=None, pci_device_pools=None, metrics=None) host = host_manager.HostState("fakehost", "fakenode") host.update_from_compute_node(compute) self.assertEqual(5, host.num_instances) self.assertEqual(42, host.num_io_ops) self.assertEqual(10, len(host.stats)) self.assertEqual('127.0.0.1', str(host.host_ip)) self.assertEqual('htype', host.hypervisor_type) self.assertEqual('hostname', host.hypervisor_hostname) self.assertEqual('cpu_info', host.cpu_info) self.assertEqual([], host.supported_instances) self.assertEqual(hyper_ver_int, host.hypervisor_version)
def __init__(self, virtapi, read_only=False): super(FakeDriver, self).__init__(virtapi) self.instances = {} self.resources = Resources(vcpus=self.vcpus, memory_mb=self.memory_mb, local_gb=self.local_gb) self.host_status_base = { "hypervisor_type": "fake", "hypervisor_version": utils.convert_version_to_int("1.0"), "hypervisor_hostname": CONF.host, "cpu_info": {}, "disk_available_least": 0, "supported_instances": jsonutils.dumps([(arch.X86_64, hv_type.FAKE, vm_mode.HVM)]), "numa_topology": None, } self._mounts = {} self._interfaces = {} if not _FAKE_NODES: set_nodes([CONF.host])
def get_available_resource(self, nodename): """Retrieve resource information. This method is called when patron-compute launches, and as part of a periodic task that records the results in the DB. :param nodename: ignored in this driver :returns: dictionary describing resources """ host_stats = self.host_state.get_host_stats(refresh=True) # Updating host information total_ram_mb = host_stats['host_memory_total'] / units.Mi # NOTE(belliott) memory-free-computed is a value provided by XenServer # for gauging free memory more conservatively than memory-free. free_ram_mb = host_stats['host_memory_free_computed'] / units.Mi 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) dic = {'vcpus': host_stats['host_cpu_info']['cpu_count'], 'memory_mb': total_ram_mb, 'local_gb': total_disk_gb, 'vcpus_used': host_stats['vcpus_used'], 'memory_mb_used': total_ram_mb - free_ram_mb, 'local_gb_used': used_disk_gb, 'hypervisor_type': 'xen', 'hypervisor_version': hyper_ver, 'hypervisor_hostname': host_stats['host_hostname'], 'cpu_info': jsonutils.dumps(host_stats['cpu_model']), 'disk_available_least': total_disk_gb - allocated_disk_gb, 'supported_instances': jsonutils.dumps( host_stats['supported_instances']), 'pci_passthrough_devices': jsonutils.dumps( host_stats['pci_passthrough_devices']), 'numa_topology': None} return dic
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.PatronException, utils.convert_version_to_int, '5a.6b')