Exemple #1
0
    def test_channel_multiple_statuses_down(self):
        channel = yield self.create_channel(self.service,
                                            self.redis,
                                            id='channel-id')

        components = {}

        for i in range(5):
            status = TransportStatus(status='ok',
                                     component=i,
                                     type='bar',
                                     message='Bar')
            yield channel.sstore.store_status('channel-id', status)
            components[str(i)] = api_from_status('channel-id', status)

        status = TransportStatus(status='degraded',
                                 component=5,
                                 type='bar',
                                 message='Bar')
        yield channel.sstore.store_status('channel-id', status)
        components['5'] = api_from_status('channel-id', status)

        status = TransportStatus(status='down',
                                 component=6,
                                 type='bar',
                                 message='Bar')
        yield channel.sstore.store_status('channel-id', status)
        components['6'] = api_from_status('channel-id', status)

        self.assert_status((yield channel.status())['status'],
                           level='down',
                           components=components)
    def test_channel_multiple_statuses_down(self):
        channel = yield self.create_channel(
            self.service, self.redis, id='channel-id')

        components = {}

        for i in range(5):
            status = TransportStatus(
                status='ok',
                component=i,
                type='bar',
                message='Bar')
            yield channel.sstore.store_status('channel-id', status)
            components[str(i)] = api_from_status('channel-id', status)

        status = TransportStatus(
            status='degraded',
            component=5,
            type='bar',
            message='Bar')
        yield channel.sstore.store_status('channel-id', status)
        components['5'] = api_from_status('channel-id', status)

        status = TransportStatus(
            status='down',
            component=6,
            type='bar',
            message='Bar')
        yield channel.sstore.store_status('channel-id', status)
        components['6'] = api_from_status('channel-id', status)

        self.assert_status(
            (yield channel.status())['status'], level='down',
            components=components)
Exemple #3
0
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        resp = yield post(self.config['status_url'], data)

        if request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r' % (resp.code,
                                               (yield resp.content()), status))
Exemple #4
0
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        resp = yield post(self.config['status_url'], data)

        if request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r'
                % (resp.code, (yield resp.content()), status))
Exemple #5
0
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        config = self.get_static_config()
        resp = yield post(config.status_url, data,
                          timeout=config.status_url_timeout)

        if resp and request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r'
                % (resp.code, (yield resp.content()), status))
Exemple #6
0
    def send_status(self, status):
        data = api_from_status(self.config['channel_id'], status)
        config = self.get_static_config()
        resp = yield post(config.status_url, data,
                          timeout=config.status_url_timeout)

        if resp and request_failed(resp):
            logging.exception(
                'Error sending status event, received HTTP code %r with '
                'body %r. Status event: %r'
                % (resp.code, (yield resp.content()), status))
    def test_channel_status_single_status(self):
        channel = yield self.create_channel(
            self.service, self.redis, id='channel-id')

        status = TransportStatus(
            status='ok',
            component='foo',
            type='bar',
            message='Bar')
        yield channel.sstore.store_status('channel-id', status)

        self.assert_status((yield channel.status())['status'], components={
            'foo': api_from_status('channel-id', status),
            }, level='ok')
Exemple #8
0
    def test_channel_status_single_status(self):
        channel = yield self.create_channel(
            self.service, self.redis, id='channel-id')

        status = TransportStatus(
            status='ok',
            component='foo',
            type='bar',
            message='Bar')
        yield channel.sstore.store_status('channel-id', status)

        self.assert_status((yield channel.status())['status'], components={
            'foo': api_from_status('channel-id', status),
            }, level='ok')
Exemple #9
0
    def test_api_from_status(self):
        status = TransportStatus(
            component='foo',
            status='ok',
            type='bar',
            message='Bar',
            details={'baz': 'quux'})

        self.assertEqual(api_from_status('channel-23', status), {
            'channel_id': 'channel-23',
            'status': 'ok',
            'component': 'foo',
            'type': 'bar',
            'message': 'Bar',
            'details': {'baz': 'quux'}
        })
Exemple #10
0
    def test_api_from_status(self):
        status = TransportStatus(component='foo',
                                 status='ok',
                                 type='bar',
                                 message='Bar',
                                 details={'baz': 'quux'})

        self.assertEqual(
            api_from_status('channel-23', status), {
                'channel_id': 'channel-23',
                'status': 'ok',
                'component': 'foo',
                'type': 'bar',
                'message': 'Bar',
                'details': {
                    'baz': 'quux'
                }
            })
Exemple #11
0
    def test_status_sent_to_status_url(self):
        '''The published status gets consumed and sent to the configured
        status_url'''
        worker = yield self.get_worker({
            'channel_id': 'channel-23',
            'status_url': self.logging_api.url,
        })

        status = TransportStatus(component='foo',
                                 status='ok',
                                 type='bar',
                                 message='Bar')

        yield worker.consume_status(status)

        [req] = self.logging_api.requests

        self.assert_request(req,
                            method='POST',
                            headers={'content-type': ['application/json']},
                            body=api_from_status('channel-23', status))
Exemple #12
0
    def _get_status(self):
        components = yield self.sstore.get_statuses(self.id)
        components = dict(
            (k, api_from_status(self.id, v)) for k, v in components.iteritems()
        )

        status_values = {
            'down': 0,
            'degraded': 1,
            'ok': 2,
        }

        try:
            status = min(
                (c['status'] for c in components.values()),
                key=status_values.get)
        except ValueError:
            # No statuses
            status = None

        returnValue({
            'components': components,
            'status': status,
            'inbound_message_rate': (
                yield self._get_message_rate('inbound')),
            'outbound_message_rate': (
                yield self._get_message_rate('outbound')),
            'submitted_event_rate': (
                yield self._get_message_rate('submitted')),
            'rejected_event_rate': (
                yield self._get_message_rate('rejected')),
            'delivery_succeeded_rate': (
                yield self._get_message_rate('delivery_succeeded')),
            'delivery_failed_rate': (
                yield self._get_message_rate('delivery_failed')),
            'delivery_pending_rate': (
                yield self._get_message_rate('delivery_pending')),
        })
Exemple #13
0
    def test_status_sent_to_status_url(self):
        '''The published status gets consumed and sent to the configured
        status_url'''
        worker = yield self.get_worker({
            'channel_id': 'channel-23',
            'status_url': self.logging_api.url,
        })

        status = TransportStatus(
            component='foo',
            status='ok',
            type='bar',
            message='Bar')

        yield worker.consume_status(status)

        [req] = self.logging_api.requests

        self.assert_request(
            req,
            method='POST',
            headers={'content-type': ['application/json']},
            body=api_from_status('channel-23', status))