def _build_task_log_responses(self, num):
     responses = []
     expected_response = []
     # 3 cells... so 3 responses.  Each response is a list of task log
     # entries. Manager should turn these into a single list of
     # task log entries.
     for i in xrange(num):
         cell_name = 'path!to!cell%i' % i
         task_logs = []
         for task_log in FAKE_TASK_LOGS:
             task_logs.append(copy.deepcopy(task_log))
             expected_task_log = copy.deepcopy(task_log)
             cells_utils.add_cell_to_task_log(expected_task_log, cell_name)
             expected_response.append(expected_task_log)
         response = messaging.Response(cell_name, task_logs, False)
         responses.append(response)
     return expected_response, responses
Exemple #2
0
    def test_get_host_uptime(self):
        fake_cell = 'parent!fake-cell'
        fake_host = 'fake-host'
        fake_cell_and_host = cells_utils.cell_with_item(fake_cell, fake_host)
        host_uptime = (" 08:32:11 up 93 days, 18:25, 12 users,  load average:"
                       " 0.20, 0.12, 0.14")
        fake_response = messaging.Response(fake_cell, host_uptime, False)

        self.mox.StubOutWithMock(self.msg_runner,
                                 'get_host_uptime')
        self.msg_runner.get_host_uptime(self.ctxt, fake_cell, fake_host).\
            AndReturn(fake_response)
        self.mox.ReplayAll()

        response = self.cells_manager.get_host_uptime(self.ctxt,
                                                      fake_cell_and_host)
        self.assertEqual(host_uptime, response)
    def test_run_compute_api_method(self):
        # Args should just be silently passed through
        cell_name = 'fake-cell-name'
        method_info = 'fake-method-info'

        fake_response = messaging.Response('fake', 'fake', False)

        self.mox.StubOutWithMock(self.msg_runner, 'run_compute_api_method')
        self.mox.StubOutWithMock(fake_response, 'value_or_raise')
        self.msg_runner.run_compute_api_method(self.ctxt, cell_name,
                                               method_info,
                                               True).AndReturn(fake_response)
        fake_response.value_or_raise().AndReturn('fake-response')
        self.mox.ReplayAll()
        response = self.cells_manager.run_compute_api_method(
            self.ctxt, cell_name=cell_name, method_info=method_info, call=True)
        self.assertEqual('fake-response', response)
Exemple #4
0
    def test_service_update(self):
        fake_cell = 'fake-cell'
        fake_response = messaging.Response(
            fake_cell, FAKE_SERVICES[0], False)
        expected_response = copy.deepcopy(FAKE_SERVICES[0])
        cells_utils.add_cell_to_service(expected_response, fake_cell)
        cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')
        params_to_update = {'disabled': True}

        self.mox.StubOutWithMock(self.msg_runner, 'service_update')
        self.msg_runner.service_update(self.ctxt,
                fake_cell, 'fake-host', 'nova-api',
                params_to_update).AndReturn(fake_response)
        self.mox.ReplayAll()

        response = self.cells_manager.service_update(
            self.ctxt, host_name=cell_and_host, binary='nova-api',
            params_to_update=params_to_update)
        self.assertEqual(expected_response, response)
Exemple #5
0
    def test_compute_node_get(self):
        fake_cell = 'fake-cell'
        fake_compute = objects.ComputeNode(**FAKE_COMPUTE_NODES[0])
        fake_compute._cached_service = None
        fake_response = messaging.Response(self.ctxt, fake_cell, fake_compute,
                                           False)

        expected_response = cells_utils.ComputeNodeProxy(
            fake_compute, fake_cell)
        cell_and_id = cells_utils.cell_with_item(fake_cell, 'fake-id')
        self.mox.StubOutWithMock(self.msg_runner, 'compute_node_get')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_compute_node')
        self.msg_runner.compute_node_get(self.ctxt, 'fake-cell',
                                         'fake-id').AndReturn(fake_response)
        cells_utils.add_cell_to_compute_node(
            fake_compute, fake_cell).AndReturn(expected_response)
        self.mox.ReplayAll()
        response = self.cells_manager.compute_node_get(self.ctxt,
                                                       compute_id=cell_and_id)
        self.assertEqual(expected_response, response)
Exemple #6
0
    def test_service_get_by_compute_host(self):
        fake_cell = 'fake-cell'
        fake_service = objects.Service(**FAKE_SERVICES[0])
        fake_response = messaging.Response(self.ctxt, fake_cell, fake_service,
                                           False)
        expected_response = cells_utils.ServiceProxy(fake_service, fake_cell)
        cell_and_host = cells_utils.cell_with_item('fake-cell', 'fake-host')

        self.mox.StubOutWithMock(self.msg_runner,
                                 'service_get_by_compute_host')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_get_by_compute_host(
            self.ctxt, fake_cell, 'fake-host').AndReturn(fake_response)
        cells_utils.add_cell_to_service(fake_service,
                                        fake_cell).AndReturn(expected_response)

        self.mox.ReplayAll()
        response = self.cells_manager.service_get_by_compute_host(
            self.ctxt, host_name=cell_and_host)
        self.assertEqual(expected_response, response)
Exemple #7
0
 def test_compute_node_get_all(self):
     responses = []
     expected_response = []
     # 3 cells... so 3 responses.  Each response is a list of computes.
     # Manager should turn these into a single list of responses.
     for i in xrange(3):
         cell_name = 'path!to!cell%i' % i
         compute_nodes = []
         for compute_node in FAKE_COMPUTE_NODES:
             compute_nodes.append(copy.deepcopy(compute_node))
             expected_compute_node = copy.deepcopy(compute_node)
             cells_utils.add_cell_to_compute_node(expected_compute_node,
                                                  cell_name)
             expected_response.append(expected_compute_node)
         response = messaging.Response(cell_name, compute_nodes, False)
         responses.append(response)
     self.mox.StubOutWithMock(self.msg_runner, 'compute_node_get_all')
     self.msg_runner.compute_node_get_all(
         self.ctxt, hypervisor_match='fake-match').AndReturn(responses)
     self.mox.ReplayAll()
     response = self.cells_manager.compute_node_get_all(
         self.ctxt, hypervisor_match='fake-match')
     self.assertEqual(expected_response, response)
Exemple #8
0
    def test_service_get_all(self):
        responses = []
        expected_response = []
        # 3 cells... so 3 responses.  Each response is a list of services.
        # Manager should turn these into a single list of responses.
        for i in xrange(3):
            cell_name = 'path!to!cell%i' % i
            services = []
            for service in FAKE_SERVICES:
                services.append(copy.deepcopy(service))
                expected_service = copy.deepcopy(service)
                cells_utils.add_cell_to_service(expected_service, cell_name)
                expected_response.append(expected_service)
            response = messaging.Response(cell_name, services, False)
            responses.append(response)

        self.mox.StubOutWithMock(self.msg_runner, 'service_get_all')
        self.msg_runner.service_get_all(self.ctxt,
                                        'fake-filters').AndReturn(responses)
        self.mox.ReplayAll()
        response = self.cells_manager.service_get_all(self.ctxt,
                                                      filters='fake-filters')
        self.assertEqual(expected_response, response)
Exemple #9
0
 def _get_fake_response(self, raw_response=None, exc=False):
     if exc:
         return messaging.Response('fake', test.TestingException(), True)
     if raw_response is None:
         raw_response = 'fake-response'
     return messaging.Response('fake', raw_response, False)