Ejemplo n.º 1
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 range(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)
Ejemplo n.º 2
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 range(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)
Ejemplo n.º 3
0
 def service_get_by_compute_host(self, ctxt, host_name):
     """Return a service entry for a compute host in a certain cell."""
     cell_name, host_name = cells_utils.split_cell_and_item(host_name)
     response = self.msg_runner.service_get_by_compute_host(ctxt, cell_name, host_name)
     service = response.value_or_raise()
     cells_utils.add_cell_to_service(service, response.cell_name)
     return service
Ejemplo n.º 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:
                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(self.ctxt, 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)
Ejemplo n.º 5
0
 def service_get_by_compute_host(self, ctxt, host_name):
     """Return a service entry for a compute host in a certain cell."""
     cell_name, host_name = cells_utils.split_cell_and_item(host_name)
     response = self.msg_runner.service_get_by_compute_host(
         ctxt, cell_name, host_name)
     service = response.value_or_raise()
     cells_utils.add_cell_to_service(service, response.cell_name)
     return service
Ejemplo n.º 6
0
 def service_get_all(self, ctxt, filters):
     """Return services in this cell and in all child cells."""
     responses = self.msg_runner.service_get_all(ctxt, filters)
     ret_services = []
     # 1 response per cell.  Each response is a list of services.
     for response in responses:
         services = response.value_or_raise()
         for service in services:
             cells_utils.add_cell_to_service(service, response.cell_name)
             ret_services.append(service)
     return ret_services
Ejemplo n.º 7
0
 def service_get_all(self, ctxt, filters):
     """Return services in this cell and in all child cells."""
     responses = self.msg_runner.service_get_all(ctxt, filters)
     ret_services = []
     # 1 response per cell.  Each response is a list of services.
     for response in responses:
         services = response.value_or_raise()
         for service in services:
             cells_utils.add_cell_to_service(service, response.cell_name)
             ret_services.append(service)
     return ret_services
Ejemplo n.º 8
0
    def test_service_get_by_compute_host(self):
        self.mox.StubOutWithMock(self.msg_runner, "service_get_by_compute_host")
        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")
        self.msg_runner.service_get_by_compute_host(self.ctxt, fake_cell, "fake-host").AndReturn(fake_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)
Ejemplo n.º 9
0
    def test_service_get_by_compute_host(self):
        self.mox.StubOutWithMock(self.msg_runner,
                                 'service_get_by_compute_host')
        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')
        self.msg_runner.service_get_by_compute_host(
            self.ctxt, fake_cell, 'fake-host').AndReturn(fake_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)
Ejemplo n.º 10
0
    def service_update(self, ctxt, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        :returns: the service reference
        """
        cell_name, host_name = cells_utils.split_cell_and_item(host_name)
        response = self.msg_runner.service_update(
            ctxt, cell_name, host_name, binary, params_to_update)
        service = response.value_or_raise()
        cells_utils.add_cell_to_service(service, response.cell_name)
        return service
Ejemplo n.º 11
0
    def service_update(self, ctxt, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        :returns: the service reference
        """
        cell_name, host_name = cells_utils.split_cell_and_item(host_name)
        response = self.msg_runner.service_update(ctxt, cell_name, host_name,
                                                  binary, params_to_update)
        service = response.value_or_raise()
        cells_utils.add_cell_to_service(service, response.cell_name)
        return service
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
    def test_add_cell_to_service_no_compute_node(self, mock_get_by_id):
        fake_service = objects.Service(id=1, host='fake')
        mock_get_by_id.side_effect = exception.ServiceNotFound(service_id=1)
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_service(fake_service, cell_path)

        self.assertIsInstance(proxy, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(AttributeError, getattr, proxy, 'compute_node')
Ejemplo n.º 16
0
    def test_add_cell_to_service_with_compute_node(self):
        fake_service = objects.Service(id=1, host='fake')
        fake_service.compute_node = objects.ComputeNode(id=1, host='fake')
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_service(fake_service, cell_path)

        self.assertIsInstance(proxy, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(AttributeError, getattr, proxy, 'compute_node')
Ejemplo n.º 17
0
    def test_add_cell_to_service_no_compute_node(self, mock_get_by_id):
        fake_service = objects.Service(id=1, host='fake')
        mock_get_by_id.side_effect = exception.ServiceNotFound(service_id=1)
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_service(fake_service, cell_path)

        self.assertIsInstance(proxy, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(AttributeError,
                          getattr, proxy, 'compute_node')
Ejemplo n.º 18
0
    def test_add_cell_to_service_with_compute_node(self):
        fake_service = objects.Service(id=1, host='fake')
        fake_service.compute_node = objects.ComputeNode(id=1, host='fake')
        cell_path = 'fake_path'

        proxy = cells_utils.add_cell_to_service(fake_service, cell_path)

        self.assertIsInstance(proxy, cells_utils.ServiceProxy)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 1), proxy.id)
        self.assertEqual(cells_utils.cell_with_item(cell_path, 'fake'),
                         proxy.host)
        self.assertRaises(AttributeError,
                          getattr, proxy, 'compute_node')
Ejemplo n.º 19
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', 'nova-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='nova-api',
            params_to_update=params_to_update)
        self.assertEqual(expected_response, response)
Ejemplo n.º 20
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)