Example #1
0
    def test_get_all_host_states(self, mock_gbh):
        # Ensure .service is set and we have the values we expect to.
        context = 'fake_context'

        self.mox.StubOutWithMock(objects.ServiceList, 'get_by_binary')
        self.mox.StubOutWithMock(objects.ComputeNodeList, 'get_all')
        objects.ServiceList.get_by_binary(context, 'nova-compute').AndReturn(
            ironic_fakes.SERVICES)
        objects.ComputeNodeList.get_all(context).AndReturn(
            ironic_fakes.COMPUTE_NODES)
        self.mox.ReplayAll()

        self.host_manager.get_all_host_states(context)
        self.assertEqual(0, mock_gbh.call_count)
        host_states_map = self.host_manager.host_state_map

        self.assertEqual(len(host_states_map), 4)
        for i in range(4):
            compute_node = ironic_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(
                    ironic_fakes.get_service_by_host(host)))
            self.assertEqual(compute_node.stats,
                             host_states_map[state_key].stats)
            self.assertEqual(compute_node.free_ram_mb,
                             host_states_map[state_key].free_ram_mb)
            self.assertEqual(compute_node.free_disk_gb * 1024,
                             host_states_map[state_key].free_disk_mb)
Example #2
0
    def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
                                 mock_get_by_binary):
        mock_get_all.return_value = ironic_fakes.COMPUTE_NODES
        mock_get_by_binary.return_value = ironic_fakes.SERVICES
        context = 'fake_context'

        self.host_manager.get_all_host_states(context)
        self.assertEqual(0, mock_get_by_host.call_count)
        host_states_map = self.host_manager.host_state_map
        self.assertEqual(len(host_states_map), 4)

        for i in range(4):
            compute_node = ironic_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(
                                 ironic_fakes.get_service_by_host(host)))
            self.assertEqual(compute_node.stats,
                             host_states_map[state_key].stats)
            self.assertEqual(compute_node.free_ram_mb,
                             host_states_map[state_key].free_ram_mb)
            self.assertEqual(compute_node.free_disk_gb * 1024,
                             host_states_map[state_key].free_disk_mb)
    def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
                                 mock_get_by_binary):
        mock_get_all.return_value = ironic_fakes.COMPUTE_NODES
        mock_get_by_binary.return_value = ironic_fakes.SERVICES
        context = 'fake_context'

        self.host_manager.get_all_host_states(context)
        self.assertEqual(0, mock_get_by_host.call_count)
        host_states_map = self.host_manager.host_state_map
        self.assertEqual(len(host_states_map), 4)

        for i in range(4):
            compute_node = ironic_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(
                    ironic_fakes.get_service_by_host(host)))
            self.assertEqual(compute_node.stats,
                             host_states_map[state_key].stats)
            self.assertEqual(compute_node.free_ram_mb,
                             host_states_map[state_key].free_ram_mb)
            self.assertEqual(compute_node.free_disk_gb * 1024,
                             host_states_map[state_key].free_disk_mb)
Example #4
0
    def test_get_all_host_states(self, mock_gbh):
        # Ensure .service is set and we have the values we expect to.
        context = "fake_context"

        self.mox.StubOutWithMock(objects.ServiceList, "get_by_binary")
        self.mox.StubOutWithMock(objects.ComputeNodeList, "get_all")
        objects.ServiceList.get_by_binary(context, "nova-compute").AndReturn(ironic_fakes.SERVICES)
        objects.ComputeNodeList.get_all(context).AndReturn(ironic_fakes.COMPUTE_NODES)
        self.mox.ReplayAll()

        self.host_manager.get_all_host_states(context)
        self.assertEqual(0, mock_gbh.call_count)
        host_states_map = self.host_manager.host_state_map

        self.assertEqual(len(host_states_map), 4)
        for i in range(4):
            compute_node = ironic_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(ironic_fakes.get_service_by_host(host))
            )
            self.assertEqual(compute_node.stats, host_states_map[state_key].stats)
            self.assertEqual(compute_node.free_ram_mb, host_states_map[state_key].free_ram_mb)
            self.assertEqual(compute_node.free_disk_gb * 1024, host_states_map[state_key].free_disk_mb)