Remove test for log_api/v2 version

Log api v2 is no longer supported.
Fix failing 'should_reject_if_body_is_empty' test.

Story: 2001400
Task: 14427
Change-Id: Ifdca09ca430415614956befc0744c52ad6b3a0a6
This commit is contained in:
Adrian Czarnecki 2018-04-20 13:28:58 +02:00
parent 1a334d5ed3
commit f5ef89e62a
6 changed files with 67 additions and 163 deletions

View File

@ -14,7 +14,6 @@
from tempest import clients
from monasca_tempest_tests.services import log_api_v2_client
from monasca_tempest_tests.services import log_api_v3_client
from monasca_tempest_tests.services import log_search_client
@ -23,18 +22,12 @@ class Manager(clients.Manager):
def __init__(self, credentials=None):
super(Manager, self).__init__(credentials)
self.log_api_clients = {
"v2": log_api_v2_client.LogApiV2Client(
self.auth_provider,
'logs_v2',
None
),
"v3": log_api_v3_client.LogApiV3Client(
self.auth_provider,
'logs',
None
)
}
self.log_api_client = log_api_v3_client.LogApiV3Client(
self.auth_provider,
'logs',
None
)
self.log_search_client = log_search_client.LogsSearchClient(
self.auth_provider,
'logs-search',

View File

@ -1,51 +0,0 @@
# Copyright 2015 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_serialization import jsonutils as json
from tempest.lib.common import rest_client
class LogApiV2Client(rest_client.RestClient):
_uri = "/log/single"
def __init__(self, auth_provider, service, region):
super(LogApiV2Client, self).__init__(
auth_provider,
service,
region
)
def get_version(self):
resp, response_body = self.send_request('GET', '/')
return resp, response_body
def send_single_log(self,
log,
headers=None,
fields=None):
default_headers = {
'X-Tenant-Id': 'b4265b0a48ae4fd3bdcee0ad8c2b6012',
'X-Roles': 'admin',
'X-Dimensions': 'dev:tempest'
}
default_headers.update(headers)
msg = json.dumps(log)
resp, body = self.post(LogApiV2Client._uri, msg, default_headers)
return resp, body
def custom_request(self, method, headers=None, body=None):
self.request(method=method, url=LogApiV2Client._uri, headers=headers, body=body)

View File

@ -85,17 +85,12 @@ def _get_headers(headers=None, content_type="application/json"):
return headers
def _get_data(message, content_type="application/json", version="v3"):
if version == "v3":
data = {
'logs': [{
'message': message
}]
}
elif 'application/json' == content_type:
data = {
def _get_data(message):
data = {
'logs': [{
'message': message
}
}]
}
return data
@ -117,7 +112,7 @@ class BaseLogsTestCase(test.BaseTestCase):
['monasca-user', 'admin']).credentials
cls.os_primary = clients.Manager(credentials=credentials)
cls.logs_clients = cls.os_primary.log_api_clients
cls.logs_client = cls.os_primary.log_api_client
cls.logs_search_client = cls.os_primary.log_search_client
@staticmethod

View File

@ -22,45 +22,40 @@ class TestLogApiConstraints(base.BaseLogsTestCase):
@decorators.attr(type='gate')
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
try:
self.logs_client.custom_request('POST', headers, None)
except exceptions.BadRequest as urc:
self.assertEqual(400, urc.resp.status)
return
self.assertTrue(False, 'API should respond with an error')
self.assertTrue(False, 'API should respond with an error')
@decorators.attr(type='gate')
def test_should_reject_if_content_type_missing(self):
headers = base._get_headers(content_type='')
for cli in self.logs_clients.itervalues():
try:
cli.custom_request('POST', headers, '{}')
except exceptions.BadRequest as urc:
self.assertEqual(400, urc.resp.status)
return
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')
self.assertTrue(False, 'API should respond with 400')
@decorators.attr(type='gate')
def test_should_reject_if_wrong_content_type(self):
headers = base._get_headers(content_type='video/3gpp')
for cli in self.logs_clients.itervalues():
try:
cli.custom_request('POST', headers, '{}')
except exceptions.InvalidContentType as urc:
self.assertEqual(415, urc.resp.status)
return
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')
self.assertTrue(False, 'API should respond with 400')
@decorators.attr(type='gate')
def test_should_reject_too_big_message(self):
_, message = base.generate_rejectable_message()
headers = base._get_headers(self.logs_clients["v3"].get_headers())
headers = base._get_headers(self.logs_client.get_headers())
# 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).
@ -68,24 +63,23 @@ class TestLogApiConstraints(base.BaseLogsTestCase):
# 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
data = base._get_data(message)
try:
self.logs_client.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')
self.assertTrue(False, 'API should respond with 413 or 503')
@decorators.attr(type='gate')
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())
headers = base._get_headers(self.logs_client.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).
@ -93,15 +87,14 @@ class TestLogApiConstraints(base.BaseLogsTestCase):
# 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
data = base._get_data(message)
try:
self.logs_client.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')
self.assertTrue(False, 'API should respond with 413 or 503')

View File

@ -23,7 +23,7 @@ _RETRY_WAIT = 2
class TestSingleLog(base.BaseLogsTestCase):
def _run_and_wait(self, key, data, version,
def _run_and_wait(self, key, data,
content_type='application/json',
headers=None, fields=None):
@ -38,9 +38,9 @@ class TestSingleLog(base.BaseLogsTestCase):
'Find log message in elasticsearch: {0}'.format(key))
headers = base._get_headers(headers, content_type)
data = base._get_data(data, content_type, version=version)
data = base._get_data(data)
client = self.logs_clients[version]
client = self.logs_client
response, _ = client.send_single_log(data, headers, fields)
self.assertEqual(204, response.status)
@ -53,54 +53,30 @@ class TestSingleLog(base.BaseLogsTestCase):
@decorators.attr(type="gate")
def test_small_message(self):
for ver in self.logs_clients:
self._run_and_wait(*base.generate_small_message(), version=ver)
self._run_and_wait(*base.generate_small_message())
@decorators.attr(type="gate")
def test_medium_message(self):
for ver in self.logs_clients:
self._run_and_wait(*base.generate_medium_message(), version=ver)
self._run_and_wait(*base.generate_medium_message())
@decorators.attr(type="gate")
def test_big_message(self):
for ver in self.logs_clients:
self._run_and_wait(*base.generate_large_message(), version=ver)
self._run_and_wait(*base.generate_large_message())
@decorators.attr(type="gate")
def test_small_message_multiline(self):
for ver in self.logs_clients:
sid, message = base.generate_small_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
sid, message = base.generate_small_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
@decorators.attr(type="gate")
def test_medium_message_multiline(self):
for ver in self.logs_clients:
sid, message = base.generate_medium_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
sid, message = base.generate_medium_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
@decorators.attr(type="gate")
def test_big_message_multiline(self):
for ver in self.logs_clients:
sid, message = base.generate_large_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
@decorators.attr(type="gate")
def test_send_header_application_type(self):
sid, message = base.generate_unique_message()
headers = {'X-Application-Type': 'application-type-test'}
response = self._run_and_wait(sid, message, headers=headers,
version="v2")
self.assertEqual('application-type-test',
response[0]['_source']['component'])
@decorators.attr(type="gate")
def test_send_header_dimensions(self):
sid, message = base.generate_unique_message()
headers = {'X-Dimensions': 'server:WebServer01,environment:production'} # noqa
response = self._run_and_wait(sid, message, headers=headers,
version="v2")
self.assertEqual('production', response[0]['_source']['environment'])
self.assertEqual('WebServer01', response[0]['_source']['server'])
sid, message = base.generate_large_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
@decorators.attr(type="gate")
def test_send_cross_tenant(self):
@ -108,8 +84,7 @@ class TestSingleLog(base.BaseLogsTestCase):
headers = {'X-Roles': 'admin, monitoring-delegate'}
cross_tennant_id = '2106b2c8da0eecdb3df4ea84a0b5624b'
fields = {'tenant_id': cross_tennant_id}
response = self._run_and_wait(sid, message, version="v3",
headers=headers, fields=fields)
response = self._run_and_wait(sid, message, headers=headers, fields=fields)
self.assertThat(response[0]['_source']['tenant'],
matchers.StartsWith(cross_tennant_id))

View File

@ -17,7 +17,6 @@ from tempest.lib import decorators
from monasca_tempest_tests.tests.log_api import base
_API_VERSION = 'v3'
_RETRY_COUNT = 15
_RETRY_WAIT = 2
_UNICODE_CASES = base.UNICODE_MESSAGES
@ -40,9 +39,9 @@ class TestUnicodeV3(base.BaseLogsTestCase):
'Find log message in elasticsearch: {0}'.format(key))
headers = base._get_headers(headers, content_type)
data = base._get_data(data, content_type, version=_API_VERSION)
data = base._get_data(data)
client = self.logs_clients[_API_VERSION]
client = self.logs_client
response, _ = client.send_single_log(data, headers, fields)
self.assertEqual(204, response.status)