def test_get_all_host_states(self): context = 'fake_context' self.mox.StubOutWithMock(objects.ServiceList, 'get_by_topic') self.mox.StubOutWithMock(objects.ComputeNodeList, 'get_all') self.mox.StubOutWithMock(host_manager.LOG, 'warning') objects.ServiceList.get_by_topic( context, CONF.compute_topic).AndReturn(fakes.SERVICES) objects.ComputeNodeList.get_all(context).AndReturn(fakes.COMPUTE_NODES) # node 3 host physical disk space is greater than database host_manager.LOG.warning("Host %(hostname)s has more disk space " "than database expected (%(physical)sgb >" " %(database)sgb)", {'physical': 3333, 'database': 3072, 'hostname': 'node3'}) # Invalid service host_manager.LOG.warning("No service record found for host %(host)s " "on %(topic)s topic", {'host': 'fake', 'topic': CONF.compute_topic}) self.mox.ReplayAll() self.host_manager.get_all_host_states(context) host_states_map = self.host_manager.host_state_map self.assertEqual(len(host_states_map), 4) # Check that .service is set properly for i in xrange(4): compute_node = fakes.COMPUTE_NODES[i] host = compute_node['host'] node = compute_node['hypervisor_hostname'] state_key = (host, node) self.assertEqual(host_states_map[state_key].service, obj_base.obj_to_primitive(fakes.get_service_by_host(host))) self.assertEqual(host_states_map[('host1', 'node1')].free_ram_mb, 512) # 511GB self.assertEqual(host_states_map[('host1', 'node1')].free_disk_mb, 524288) self.assertEqual(host_states_map[('host2', 'node2')].free_ram_mb, 1024) # 1023GB self.assertEqual(host_states_map[('host2', 'node2')].free_disk_mb, 1048576) self.assertEqual(host_states_map[('host3', 'node3')].free_ram_mb, 3072) # 3071GB self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb, 3145728) self.assertThat( objects.NUMATopology.obj_from_db_obj( host_states_map[('host3', 'node3')].numa_topology )._to_dict(), matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict())) self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb, 8192) # 8191GB self.assertEqual(host_states_map[('host4', 'node4')].free_disk_mb, 8388608)
def test_get_all_host_states(self, mock_get_by_host, mock_get_all, mock_get_by_binary, mock_log): mock_get_by_host.return_value = objects.InstanceList() mock_get_all.return_value = fakes.COMPUTE_NODES mock_get_by_binary.return_value = fakes.SERVICES context = 'fake_context' self.host_manager.get_all_host_states(context) host_states_map = self.host_manager.host_state_map self.assertEqual(len(host_states_map), 4) calls = [ mock.call( "Host %(hostname)s has more disk space than database " "expected (%(physical)s GB > %(database)s GB)", {'physical': 3333, 'database': 3072, 'hostname': 'node3'} ), mock.call( "No compute service record found for host %(host)s", {'host': 'fake'} ) ] self.assertEqual(calls, mock_log.warning.call_args_list) # Check that .service is set properly for i in range(4): compute_node = fakes.COMPUTE_NODES[i] host = compute_node['host'] node = compute_node['hypervisor_hostname'] state_key = (host, node) self.assertEqual(host_states_map[state_key].service, obj_base.obj_to_primitive(fakes.get_service_by_host(host))) self.assertEqual(host_states_map[('host1', 'node1')].free_ram_mb, 512) # 511GB self.assertEqual(host_states_map[('host1', 'node1')].free_disk_mb, 524288) self.assertEqual(host_states_map[('host2', 'node2')].free_ram_mb, 1024) # 1023GB self.assertEqual(host_states_map[('host2', 'node2')].free_disk_mb, 1048576) self.assertEqual(host_states_map[('host3', 'node3')].free_ram_mb, 3072) # 3071GB self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb, 3145728) self.assertThat( objects.NUMATopology.obj_from_db_obj( host_states_map[('host3', 'node3')].numa_topology )._to_dict(), matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict())) self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb, 8192) # 8191GB self.assertEqual(host_states_map[('host4', 'node4')].free_disk_mb, 8388608)
def test_get_all_host_partial_states(self, mock_get_by_host, mock_get_all, mock_get_by_binary, mock_log): mock_get_by_host.return_value = nova.objects.InstanceList() mock_get_all.return_value = fakes.COMPUTE_NODES mock_get_by_binary.return_value = fakes.SERVICES context = 'fake_context' self.host_manager.get_all_host_partial_states(context) host_states_map = self.host_manager.host_state_map self.assertEqual(len(host_states_map), 4) calls = [ mock.call("No compute service record found for host %(host)s", {'host': 'fake'}) ] self.assertEqual(calls, mock_log.warning.call_args_list) # Check that .service is set properly for i in range(4): compute_node = fakes.COMPUTE_NODES[i] host = compute_node['host'] node = compute_node['hypervisor_hostname'] state_key = (host, node) self.assertEqual( host_states_map[state_key].service, obj_base.obj_to_primitive(fakes.get_service_by_host(host))) self.assertEqual(host_states_map[('host1', 'node1')].free_ram_mb, 512) # 511GB self.assertEqual(host_states_map[('host1', 'node1')].free_disk_mb, 524288) self.assertEqual(host_states_map[('host2', 'node2')].free_ram_mb, 1024) # 1023GB self.assertEqual(host_states_map[('host2', 'node2')].free_disk_mb, 1048576) self.assertEqual(host_states_map[('host3', 'node3')].free_ram_mb, 3072) # 3071GB self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb, 3145728) self.assertThat( nova.objects.NUMATopology.obj_from_db_obj( host_states_map[('host3', 'node3')].numa_topology)._to_dict(), matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict())) self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb, 8192) # 8191GB self.assertEqual(host_states_map[('host4', 'node4')].free_disk_mb, 8388608)
def test_get_all_host_states(self, mock_get_by_host): mock_get_by_host.return_value = objects.InstanceList() context = "fake_context" self.mox.StubOutWithMock(objects.ServiceList, "get_by_binary") self.mox.StubOutWithMock(objects.ComputeNodeList, "get_all") self.mox.StubOutWithMock(host_manager.LOG, "warning") objects.ServiceList.get_by_binary(context, "nova-compute").AndReturn(fakes.SERVICES) objects.ComputeNodeList.get_all(context).AndReturn(fakes.COMPUTE_NODES) # node 3 host physical disk space is greater than database host_manager.LOG.warning( "Host %(hostname)s has more disk space " "than database expected (%(physical)s GB >" " %(database)s GB)", {"physical": 3333, "database": 3072, "hostname": "node3"}, ) # Invalid service host_manager.LOG.warning("No compute service record found for " "host %(host)s", {"host": "fake"}) self.mox.ReplayAll() self.host_manager.get_all_host_states(context) host_states_map = self.host_manager.host_state_map self.assertEqual(len(host_states_map), 4) # Check that .service is set properly for i in range(4): compute_node = fakes.COMPUTE_NODES[i] host = compute_node["host"] node = compute_node["hypervisor_hostname"] state_key = (host, node) self.assertEqual( host_states_map[state_key].service, obj_base.obj_to_primitive(fakes.get_service_by_host(host)) ) self.assertEqual(host_states_map[("host1", "node1")].free_ram_mb, 512) # 511GB self.assertEqual(host_states_map[("host1", "node1")].free_disk_mb, 524288) self.assertEqual(host_states_map[("host2", "node2")].free_ram_mb, 1024) # 1023GB self.assertEqual(host_states_map[("host2", "node2")].free_disk_mb, 1048576) self.assertEqual(host_states_map[("host3", "node3")].free_ram_mb, 3072) # 3071GB self.assertEqual(host_states_map[("host3", "node3")].free_disk_mb, 3145728) self.assertThat( objects.NUMATopology.obj_from_db_obj(host_states_map[("host3", "node3")].numa_topology)._to_dict(), matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict()), ) self.assertEqual(host_states_map[("host4", "node4")].free_ram_mb, 8192) # 8191GB self.assertEqual(host_states_map[("host4", "node4")].free_disk_mb, 8388608)