Example #1
0
    def test_get_all_without_backend(self):
        cfg.CONF.set_default('backend_url', None, 'coordination')

        coordination.cleanup_service_coordinator()
        coordination.get_service_coordinator()

        context = self.assertRaises(
            webtest_app.AppError,
            self.app.get,
            '/v2/services',
        )

        self.assertIn('Service API is not supported', context.message)
Example #2
0
    def test_get_all_without_backend(self):
        cfg.CONF.set_default('backend_url', None, 'coordination')

        coordination.cleanup_service_coordinator()
        coordination.get_service_coordinator()

        context = self.assertRaises(
            webtest_app.AppError,
            self.app.get,
            '/v2/services',
        )

        self.assertIn('Service API is not supported', context.args[0])
Example #3
0
    def test_get_all_with_get_members_error(self, mock_get_members):
        cfg.CONF.set_default('backend_url', 'zake://', 'coordination')

        coordination.cleanup_service_coordinator()
        coordination.get_service_coordinator()

        context = self.assertRaises(
            webtest_app.AppError,
            self.app.get,
            '/v2/services',
        )

        self.assertIn(
            'Failed to get service members from coordination backend',
            context.args[0])
Example #4
0
    def test_get_all_with_get_members_error(self, mock_get_members):
        cfg.CONF.set_default('backend_url', 'zake://', 'coordination')

        coordination.cleanup_service_coordinator()
        coordination.get_service_coordinator()

        context = self.assertRaises(
            webtest_app.AppError,
            self.app.get,
            '/v2/services',
        )

        self.assertIn(
            'Failed to get service members from coordination backend',
            context.message
        )
Example #5
0
    def get_all(self):
        """Return all services."""

        LOG.info("Fetch services.")

        if not cfg.CONF.coordination.backend_url:
            raise exc.CoordinationException("Service API is not supported.")

        service_coordinator = coordination.get_service_coordinator()

        if not service_coordinator.is_active():
            raise exc.CoordinationException(
                "Failed to connect to coordination backend."
            )

        services_list = []
        service_group = ['%s_group' % i for i in launch.LAUNCH_OPTIONS]

        try:
            for group in service_group:
                members = service_coordinator.get_members(group)
                services_list.extend(
                    [Service.from_dict({'type': group, 'name': member})
                     for member in members]
                )
        except tooz.coordination.ToozError as e:
            # In the scenario of network interruption or manually shutdown
            # connection shutdown, ToozError will be raised.
            raise exc.CoordinationException(
                "Failed to get service members from coordination backend. %s"
                % six.text_type(e)
            )

        return Services(services=services_list)
Example #6
0
    def get_all(self):
        """Return all services."""
        acl.enforce('services:list', context.ctx())

        LOG.info("Fetch services.")

        if not cfg.CONF.coordination.backend_url:
            raise exc.CoordinationException("Service API is not supported.")

        service_coordinator = coordination.get_service_coordinator()

        if not service_coordinator.is_active():
            raise exc.CoordinationException(
                "Failed to connect to coordination backend.")

        services_list = []
        service_group = ['%s_group' % i for i in launch.LAUNCH_OPTIONS]

        try:
            for group in service_group:
                members = service_coordinator.get_members(group)
                services_list.extend([
                    resources.Service.from_dict({
                        'type': group,
                        'name': member
                    }) for member in members
                ])
        except tooz.coordination.ToozError as e:
            # In the scenario of network interruption or manually shutdown
            # connection shutdown, ToozError will be raised.
            raise exc.CoordinationException(
                "Failed to get service members from coordination backend. %s" %
                six.text_type(e))

        return resources.Services(services=services_list)
Example #7
0
    def test_get_all(self):
        cfg.CONF.set_default('backend_url', 'zake://', 'coordination')

        coordination.cleanup_service_coordinator()
        service_coordinator = coordination.get_service_coordinator(
            my_id='service1')
        service_coordinator.join_group('api_group')

        resp = self.app.get('/v2/services')

        self.assertEqual(200, resp.status_int)

        self.assertEqual(1, len(resp.json['services']))

        srv_ret = [{"name": "service1", "type": "api_group"}]
        self.assertItemsEqual(srv_ret, resp.json['services'])
Example #8
0
    def test_get_all(self):
        cfg.CONF.set_default('backend_url', 'zake://', 'coordination')

        coordination.cleanup_service_coordinator()
        service_coordinator = coordination.get_service_coordinator(
            my_id='service1'
        )
        service_coordinator.join_group('api_group')

        resp = self.app.get('/v2/services')

        self.assertEqual(200, resp.status_int)

        self.assertEqual(1, len(resp.json['services']))

        srv_ret = [{"name": "service1", "type": "api_group"}]
        self.assertItemsEqual(srv_ret, resp.json['services'])
Example #9
0
    def get_all(self):
        """Return all services."""
        acl.enforce('services:list', context.ctx())

        LOG.debug("Fetch services.")

        if not cfg.CONF.coordination.backend_url:
            raise exc.CoordinationNotSupportedException("Service API "
                                                        "is not supported.")

        service_coordinator = coordination.get_service_coordinator()

        if not service_coordinator.is_active():
            raise exc.CoordinationException(
                "Failed to connect to coordination backend.")

        # Should be the same as LAUNCH_OPTIONS in launch.py
        # At the moment there is a duplication, need to solve it.
        # We cannot depend on launch.py since it uses eventlet monkey patch
        # under wsgi it causes problems
        mistral_services = {
            'api', 'engine', 'executor', 'event-engine', 'notifier'
        }
        services_list = []
        service_group = ['%s_group' % i for i in mistral_services]

        try:
            for group in service_group:
                members = service_coordinator.get_members(group)

                members_list = [
                    resources.Service.from_dict({
                        'type': group,
                        'name': member
                    }) for member in members
                ]

                services_list.extend(members_list)
        except tooz.coordination.ToozError as e:
            # In the scenario of network interruption or manually shutdown
            # connection shutdown, ToozError will be raised.
            raise exc.CoordinationException(
                "Failed to get service members from coordination backend. %s" %
                six.text_type(e))

        return resources.Services(services=services_list)