Esempio n. 1
0
    def _run_and_wait(self,
                      key,
                      data,
                      version,
                      content_type='application/json',
                      headers=None,
                      fields=None):

        headers = base._get_headers(headers, content_type)

        def wait():
            return self.logs_search_client.count_search_messages(key,
                                                                 headers) > 0

        self.assertEqual(
            0, self.logs_search_client.count_search_messages(key, headers),
            'Find log message in elasticsearch: {0}'.format(key))

        headers = base._get_headers(headers, content_type)
        data = base._get_data(data, content_type, version=version)

        client = self.logs_clients[version]
        response, _ = client.send_single_log(data, headers, fields)
        self.assertEqual(204, response.status)

        test_utils.call_until_true(wait, _RETRY_COUNT * _RETRY_WAIT,
                                   _RETRY_WAIT)
        response = self.logs_search_client.search_messages(key, headers)
        self.assertEqual(1, len(response))

        return response
    def test_should_reject_if_wrong_content_type(self):
        headers = base._get_headers(content_type='video/3gpp')
        try:
            self.logs_client.custom_request('POST', headers, '{}')
        except exceptions.InvalidContentType as urc:
            self.assertEqual(415, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 400')
    def test_should_reject_if_content_length_missing(self):
        headers = base._get_headers()
        try:
            self.logs_client.custom_request('POST', headers, None)
        except exceptions.UnexpectedResponseCode as urc:
            self.assertIn('411', str(urc))  # Only possible way to detect that
            return

        self.assertTrue(False, 'API should respond with 411')
    def test_should_reject_if_content_type_missing(self):
        headers = base._get_headers(content_type='')
        try:
            self.logs_client.custom_request('POST', headers, '{}')
        except exceptions.BadRequest as urc:
            self.assertEqual(400, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 400')
Esempio n. 5
0
    def test_should_reject_if_wrong_content_type(self):
        headers = base._get_headers(content_type='video/3gpp')
        try:
            self.logs_client.custom_request('POST', headers, '{}')
        except exceptions.InvalidContentType as urc:
            self.assertEqual(415, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 400')
Esempio n. 6
0
    def test_should_reject_if_content_type_missing(self):
        headers = base._get_headers(content_type='')
        try:
            self.logs_client.custom_request('POST', headers, '{}')
        except exceptions.BadRequest as urc:
            self.assertEqual(400, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 400')
Esempio n. 7
0
    def test_should_reject_if_content_length_missing(self):
        headers = base._get_headers()
        try:
            self.logs_client.custom_request('POST', headers, None)
        except exceptions.UnexpectedResponseCode as urc:
            self.assertIn('411', str(urc))  # Only possible way to detect that
            return

        self.assertTrue(False, 'API should respond with 411')
    def test_should_reject_too_big_message(self):
        _, message = base.generate_rejectable_message()
        headers = base._get_headers(self.logs_client.get_headers())
        try:
            self.logs_client.send_single_log(message, headers)
        except exceptions.OverLimit as urc:
            self.assertEqual(413, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 413')
Esempio n. 9
0
    def test_should_reject_if_body_is_empty(self):
        headers = base._get_headers()
        for cli in self.logs_clients.itervalues():
            try:
                cli.custom_request('POST', headers, None)
            except exceptions.UnprocessableEntity as urc:
                self.assertEqual(422, urc.resp.status)
                return

            self.assertTrue(False, 'API should respond with 411')
Esempio n. 10
0
    def test_should_reject_if_body_is_empty(self):
        headers = base._get_headers()
        for cli in self.logs_clients.itervalues():
            try:
                cli.custom_request('POST', headers, None)
            except exceptions.UnprocessableEntity as urc:
                # depending on the actual server (for example gunicorn vs mod_wsgi)
                # monasca-log-api may return a different error code
                self.assertTrue(urc.resp.status in [411, 422])
                return

            self.assertTrue(False, 'API should respond with an error')
Esempio n. 11
0
    def _run_and_wait(self, key, data, content_type='application/json',
                      headers=None):

        headers = base._get_headers(headers, content_type)

        def wait():
            return self.logs_search_client.count_search_messages(key, headers) > 0

        self.assertEqual(0, self.logs_search_client.count_search_messages(key, headers),
                         'Find log message in elasticsearch: {0}'.format(key))

        headers = base._get_headers(headers, content_type)
        data = base._get_data(data, content_type)

        response, _ = self.logs_client.send_single_log(data, headers)
        self.assertEqual(204, response.status)

        test.call_until_true(wait, _RETRY_COUNT, _RETRY_WAIT)
        response = self.logs_search_client.search_messages(key, headers)
        self.assertEqual(1, len(response))

        return response
Esempio n. 12
0
    def test_should_reject_too_big_message(self):
        _, message = base.generate_rejectable_message()
        headers = base._get_headers(self.logs_client.get_headers())
        data = base._get_data(message)
        # Add 'Connection: Keep-Alive' to send large message before
        # connection is closed by client. In class ClosingHttp is added
        # header 'connection:close' (which will cause closing socket before sending whole message).
        # Data are send in small TCP packages.
        # Without this header set to Keep-Alive Tempest lib will try to retry connection and finally
        # raise ProtocolError.
        headers.update({'Connection': 'Keep-Alive'})
        try:
            self.logs_client.send_single_log(data, headers)
        except exceptions.OverLimit as urc:
            self.assertEqual(413, urc.resp.status)
            return

        self.assertTrue(False, 'API should respond with 413')
Esempio n. 13
0
    def test_should_accept_message_but_reject_after_adding_metadata(self):
        _, message = base.generate_unique_message(
            size=base._get_message_size(0.9999))
        headers = base._get_headers(self.logs_client.get_headers())
        data = base._get_data(message)

        try:
            self.logs_client.send_single_log(data, headers)
        except exceptions.ServerFault as urc:
            self.assertEqual(500, urc.resp.status)
            msg = urc.resp_body.get('title', None)
            # in Java that is under message
            if msg is None:
                msg = urc.resp_body.get('message', None)
            self.assertIsNotNone(msg, 'Should get status message')
            self.assertEqual('Envelope size exceeded', msg)
            return

        self.assertTrue(False, 'API should respond with 500')
    def test_should_reject_too_big_message_multiline(self):
        _, message = base.generate_rejectable_message()
        message = message.replace(' ', '\n')
        headers = base._get_headers(self.logs_clients["v3"].get_headers())
        # Add Connection: Keep-Alive to send large message before
        # connection is closed by cli. In class ClosingHttp is added
        # header connection:close (which will cause closing socket before sending whole message).
        # Data are send in small TCP packages.
        # Without this header set to Keep-Alive Tempest lib will try to retry connection and finally
        # raise ProtocolError.
        headers.update({'Connection': 'Keep-Alive'})
        for ver, cli in self.logs_clients.items():
            data = base._get_data(message, version=ver)
            try:
                cli.send_single_log(data, headers)
            except exceptions.OverLimit as urc:
                self.assertEqual(413, urc.resp.status)
                return
            except exceptions.UnexpectedContentType as uct:
                self.assertEqual(503, uct.resp.status)
                return

            self.assertTrue(False, 'API should respond with 413 or 503')