Example #1
0
 def _get_fake_response(self, raw_response=None, exc=False):
     if exc:
         return messaging.Response(self.ctxt, 'fake',
                                   test.TestingException(),
                                   True)
     if raw_response is None:
         raw_response = 'fake-response'
     return messaging.Response(self.ctxt, 'fake', raw_response, False)
Example #2
0
    def test_compute_node_stats(self):
        raw_resp1 = {'key1': 1, 'key2': 2}
        raw_resp2 = {'key2': 1, 'key3': 2}
        raw_resp3 = {'key3': 1, 'key4': 2}
        responses = [messaging.Response(self.ctxt, 'cell1', raw_resp1, False),
                     messaging.Response(self.ctxt, 'cell2', raw_resp2, False),
                     messaging.Response(self.ctxt, 'cell2', raw_resp3, False)]
        expected_resp = {'key1': 1, 'key2': 3, 'key3': 3, 'key4': 2}

        self.mox.StubOutWithMock(self.msg_runner,
                                 'compute_node_stats')
        self.msg_runner.compute_node_stats(self.ctxt).AndReturn(responses)
        self.mox.ReplayAll()
        response = self.cells_manager.compute_node_stats(self.ctxt)
        self.assertEqual(expected_resp, response)
Example #3
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:
             fake_compute = objects.ComputeNode(**compute_node)
             fake_compute._cached_service = None
             compute_nodes.append(fake_compute)
             expected_compute_node = cells_utils.ComputeNodeProxy(
                 fake_compute, cell_name)
             expected_response.append(
                 (cell_name, expected_compute_node, fake_compute))
         response = messaging.Response(self.ctxt, cell_name, compute_nodes,
                                       False)
         responses.append(response)
     self.mox.StubOutWithMock(self.msg_runner,
                              'compute_node_get_all')
     self.mox.StubOutWithMock(cells_utils, 'add_cell_to_compute_node')
     self.msg_runner.compute_node_get_all(self.ctxt,
             hypervisor_match='fake-match').AndReturn(responses)
     # Calls are done by cells, so we need to sort the list by the cell name
     expected_response.sort(key=lambda k: k[0])
     for cell_name, compute_proxy, compute_node in expected_response:
         cells_utils.add_cell_to_compute_node(
             compute_node, cell_name).AndReturn(compute_proxy)
     self.mox.ReplayAll()
     response = self.cells_manager.compute_node_get_all(self.ctxt,
             hypervisor_match='fake-match')
     self.assertEqual([proxy for cell, proxy, compute in expected_response],
                      response)
Example #4
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:
                fake_service = objects.Service(**service)
                services.append(fake_service)
                expected_service = cells_utils.ServiceProxy(fake_service,
                                                            cell_name)
                expected_response.append(
                    (cell_name, expected_service, fake_service))
            response = messaging.Response(self.ctxt, cell_name, services,
                                          False)
            responses.append(response)

        self.mox.StubOutWithMock(self.msg_runner,
                                 'service_get_all')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_get_all(self.ctxt,
                                        'fake-filters').AndReturn(responses)
        # Calls are done by cells, so we need to sort the list by the cell name
        expected_response.sort(key=lambda k: k[0])
        for cell_name, service_proxy, service in expected_response:
            cells_utils.add_cell_to_service(
                service, cell_name).AndReturn(service_proxy)
        self.mox.ReplayAll()
        response = self.cells_manager.service_get_all(self.ctxt,
                                                      filters='fake-filters')
        self.assertEqual([proxy for cell, proxy, service in expected_response],
                         response)
Example #5
0
 def test_action_events_get(self):
     fake_action_id = fake_server_actions.FAKE_ACTION_ID1
     fake_events = fake_server_actions.FAKE_EVENTS[fake_action_id]
     fake_response = messaging.Response(self.ctxt, 'fake-cell', fake_events,
                                        False)
     expected_response = fake_events
     self.mox.StubOutWithMock(self.msg_runner, 'action_events_get')
     self.msg_runner.action_events_get(self.ctxt, 'fake-cell',
                                 'fake-action').AndReturn(fake_response)
     self.mox.ReplayAll()
     response = self.cells_manager.action_events_get(self.ctxt, 'fake-cell',
                                                     'fake-action')
     self.assertEqual(expected_response, response)
Example #6
0
 def test_actions_get(self):
     fake_uuid = fake_server_actions.FAKE_UUID
     fake_req_id = fake_server_actions.FAKE_REQUEST_ID1
     fake_act = fake_server_actions.FAKE_ACTIONS[fake_uuid][fake_req_id]
     fake_response = messaging.Response(self.ctxt, 'fake-cell', [fake_act],
                                        False)
     expected_response = [fake_act]
     self.mox.StubOutWithMock(self.msg_runner, 'actions_get')
     self.msg_runner.actions_get(self.ctxt, 'fake-cell',
                                 'fake-uuid').AndReturn(fake_response)
     self.mox.ReplayAll()
     response = self.cells_manager.actions_get(self.ctxt, 'fake-cell',
                                               'fake-uuid')
     self.assertEqual(expected_response, response)
Example #7
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(self.ctxt, 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)
Example #8
0
 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(self.ctxt, cell_name, task_logs,
                                       False)
         responses.append(response)
     return expected_response, responses
Example #9
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)
Example #10
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)
Example #11
0
    def test_service_update(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')
        params_to_update = {'disabled': True}

        self.mox.StubOutWithMock(self.msg_runner, 'service_update')
        self.mox.StubOutWithMock(cells_utils, 'add_cell_to_service')
        self.msg_runner.service_update(self.ctxt,
                fake_cell, 'fake-host', 'patron-api',
                params_to_update).AndReturn(fake_response)
        cells_utils.add_cell_to_service(fake_service, fake_cell).AndReturn(
            expected_response)
        self.mox.ReplayAll()

        response = self.cells_manager.service_update(
            self.ctxt, host_name=cell_and_host, binary='patron-api',
            params_to_update=params_to_update)
        self.assertEqual(expected_response, response)