def setUp(self, mock_init_agg, mock_init_inst): super(HostManagerChangedNodesTestCase, self).setUp() self.host_manager = host_manager.HostManager() self.fake_hosts = [ host_manager.HostState('host1', 'node1'), host_manager.HostState('host2', 'node2'), host_manager.HostState('host3', 'node3'), host_manager.HostState('host4', 'node4') ]
def host_state_cls(self, host, node, **kwargs): """Factory function/property to create a new HostState.""" compute = kwargs.get('compute') if compute and compute.get('hypervisor_type') == hv_type.IRONIC: return IronicNodeState(host, node, **kwargs) else: return host_manager.HostState(host, node, **kwargs)
def setUp(self, mock_init_agg, mock_init_inst): super(HostManagerTestCase, self).setUp() self.flags(scheduler_available_filters=[ '%s.%s' % (__name__, cls) for cls in ['FakeFilterClass1', 'FakeFilterClass2'] ]) self.flags(scheduler_default_filters=['FakeFilterClass1']) self.host_manager = host_manager.HostManager() self.fake_hosts = [ host_manager.HostState('fake_host%s' % x, 'fake-node') for x in xrange(1, 5) ] self.fake_hosts += [ host_manager.HostState('fake_multihost', 'fake-node%s' % x) for x in xrange(1, 5) ]
def _get_fake_host_state(self, index=0): host_state = host_manager.HostState('host_%s' % index, 'node_%s' % index) host_state.free_ram_mb = 50000 host_state.service = { "disabled": False, "updated_at": timeutils.utcnow(), "created_at": timeutils.utcnow(), } return host_state
def test_stat_consumption_from_instance(self, host_topo_mock, instance_topo_mock, numa_fit_mock, numa_usage_mock): fake_numa_topology = mock.Mock() host_topo_mock.return_value = ('fake-host-topology', None) numa_usage_mock.return_value = 'fake-consumed-once' numa_fit_mock.return_value = 'fake-fitted-once' instance_topo_mock.return_value = fake_numa_topology instance = dict(root_gb=0, ephemeral_gb=0, memory_mb=0, vcpus=0, project_id='12345', vm_state=vm_states.BUILDING, task_state=task_states.SCHEDULING, os_type='Linux', uuid='fake-uuid', numa_topology=fake_numa_topology, pci_requests={'requests': []}) host = host_manager.HostState("fakehost", "fakenode") host.consume_from_instance(instance) numa_fit_mock.assert_called_once_with('fake-host-topology', fake_numa_topology, limits=None, pci_requests=None, pci_stats=None) numa_usage_mock.assert_called_once_with(host, instance) self.assertEqual('fake-consumed-once', host.numa_topology) self.assertEqual('fake-fitted-once', instance['numa_topology']) instance = dict(root_gb=0, ephemeral_gb=0, memory_mb=0, vcpus=0, project_id='12345', vm_state=vm_states.PAUSED, task_state=None, os_type='Linux', uuid='fake-uuid', numa_topology=fake_numa_topology) numa_usage_mock.return_value = 'fake-consumed-twice' numa_fit_mock.return_value = 'fake-fitted-twice' host.consume_from_instance(instance) self.assertEqual('fake-fitted-twice', instance['numa_topology']) self.assertEqual(2, host.num_instances) self.assertEqual(1, host.num_io_ops) self.assertEqual(2, numa_usage_mock.call_count) self.assertEqual(((host, instance), ), numa_usage_mock.call_args) self.assertEqual('fake-consumed-twice', host.numa_topology)
def test_post_select_populate(self): # Test addition of certain filter props after a node is selected. retry = {'hosts': [], 'num_attempts': 1} filter_properties = {'retry': retry} host_state = host_manager.HostState('host', 'node') host_state.limits['vcpus'] = 5 scheduler_utils.populate_filter_properties(filter_properties, host_state) self.assertEqual(['host', 'node'], filter_properties['retry']['hosts'][0]) self.assertEqual({'vcpus': 5}, host_state.limits)
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 test_stat_consumption_from_instance_pci(self): inst_topology = objects.InstanceNUMATopology(cells=[ objects.InstanceNUMACell(cpuset=set([0]), memory=512, id=0) ]) fake_requests = [{ 'request_id': 'fake_request1', 'count': 1, 'spec': [{ 'vendor_id': '8086' }] }] fake_requests_obj = objects.InstancePCIRequests( requests=[objects.InstancePCIRequest(**r) for r in fake_requests], instance_uuid='fake-uuid') instance = objects.Instance(root_gb=0, ephemeral_gb=0, memory_mb=512, vcpus=1, project_id='12345', vm_state=vm_states.BUILDING, task_state=task_states.SCHEDULING, os_type='Linux', uuid='fake-uuid', numa_topology=inst_topology, pci_requests=fake_requests_obj, id=1243) req_spec = sched_utils.build_request_spec( None, None, [instance], objects.Flavor(root_gb=0, ephemeral_gb=0, memory_mb=1024, vcpus=1)) host = host_manager.HostState("fakehost", "fakenode") host.pci_stats = pci_stats.PciDeviceStats([ objects.PciDevicePool(vendor_id='8086', product_id='15ed', numa_node=1, count=1) ]) host.numa_topology = fakes.NUMA_TOPOLOGY host.consume_from_instance(req_spec['instance_properties']) self.assertIsInstance(req_spec['instance_properties']['numa_topology'], objects.InstanceNUMATopology) self.assertEqual(512, host.numa_topology.cells[1].memory_usage) self.assertEqual(1, host.numa_topology.cells[1].cpu_usage) self.assertEqual(0, len(host.pci_stats.pools))
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 test_get_all_host_states_not_updated(self, mock_get_by_host, mock_get_all_comp, mock_get_svc_by_binary): mock_get_all_comp.return_value = fakes.COMPUTE_NODES mock_get_svc_by_binary.return_value = fakes.SERVICES context = 'fake_context' hm = self.host_manager inst1 = objects.Instance(uuid='uuid1') cn1 = objects.ComputeNode(host='host1') hm._instance_info = { 'host1': { 'instances': { 'uuid1': inst1 }, 'updated': False } } host_state = host_manager.HostState('host1', cn1) self.assertFalse(host_state.instances) mock_get_by_host.return_value = objects.InstanceList(objects=[inst1]) hm._add_instance_info(context, cn1, host_state) mock_get_by_host.assert_called_once_with(context, cn1.host) self.assertTrue(host_state.instances) self.assertEqual(host_state.instances['uuid1'], inst1)
def test_state_public_api_signatures(self): self.assertPublicAPISignatures( host_manager.HostState("dummy", "dummy"), ironic_host_manager.IronicNodeState("dummy", "dummy"))