Add tempest tests for Log API v3

Change-Id: I46c0fd4e5119ad04dce2a2d15af196ba262b3a81
This commit is contained in:
Witold Bedyk 2016-07-28 13:14:25 +02:00 committed by Dobroslaw Zybort
parent 71ec276071
commit d52f1fd1f5
7 changed files with 140 additions and 63 deletions

View File

@ -24,6 +24,6 @@ respawn
#setgid kibana
#setuid kibana
#env NODE_OPTIONS="--harmony"
exec /opt/kibana/bin/kibana --config /opt/kibana/config/kibana.yml

View File

@ -14,18 +14,25 @@
from tempest import clients
from monasca_log_api_tempest.services import log_api_client
from monasca_log_api_tempest.services import log_api_v2_client
from monasca_log_api_tempest.services import log_api_v3_client
from monasca_log_api_tempest.services import log_search_client
class Manager(clients.Manager):
def __init__(self, credentials=None, service=None):
super(Manager, self).__init__(credentials, service)
self.log_api_client = log_api_client.LogApiClient(
self.log_api_clients = {}
self.log_api_clients["v2"] = log_api_v2_client.LogApiV2Client(
self.auth_provider,
'logs_v2',
None
)
self.log_api_clients["v3"] = 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

@ -19,12 +19,12 @@ from tempest.lib.common import rest_client
CONF = config.CONF
class LogApiClient(rest_client.RestClient):
class LogApiV2Client(rest_client.RestClient):
_uri = "/log/single"
def __init__(self, auth_provider, service, region):
super(LogApiClient, self).__init__(
super(LogApiV2Client, self).__init__(
auth_provider,
service,
region
@ -45,9 +45,9 @@ class LogApiClient(rest_client.RestClient):
default_headers.update(headers)
msg = json.dumps(log)
resp, body = self.post(LogApiClient._uri, msg, default_headers)
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=LogApiClient._uri, headers=headers, body=body)
self.request(method=method, url=LogApiV2Client._uri, headers=headers, body=body)

View File

@ -0,0 +1,50 @@
# 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 import config
from tempest.lib.common import rest_client
CONF = config.CONF
class LogApiV3Client(rest_client.RestClient):
_uri = "/logs"
def __init__(self, auth_provider, service, region):
super(LogApiV3Client, 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):
default_headers = {
'X-Tenant-Id': 'b4265b0a48ae4fd3bdcee0ad8c2b6012',
'X-Roles': 'admin',
}
default_headers.update(headers)
msg = json.dumps(log)
resp, body = self.post(LogApiV3Client._uri, msg, default_headers)
return resp, body
def custom_request(self, method, headers=None, body=None):
self.request(method=method, url=LogApiV3Client._uri, headers=headers, body=body)

View File

@ -81,10 +81,16 @@ def _get_headers(headers=None, content_type="application/json"):
return headers
def _get_data(data, content_type="application/json"):
if 'application/json' == content_type:
def _get_data(message, content_type="application/json", version="v3"):
if version == "v3":
data = {
'message': data
'logs': [{
'message': message
}]
}
elif 'application/json' == content_type:
data = {
'message': message
}
return data
@ -107,7 +113,7 @@ class BaseLogsTestCase(test.BaseTestCase):
['monasca-user']).credentials
cls.os = clients.Manager(credentials=credentials)
cls.logs_client = cls.os.log_api_client
cls.logs_clients = cls.os.log_api_clients
cls.logs_search_client = cls.os.log_search_client
@staticmethod

View File

@ -22,41 +22,43 @@ class TestLogApiConstraints(base.BaseLogsTestCase):
@test.attr(type='gate')
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
for cli in self.logs_clients.itervalues():
try:
cli.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')
self.assertTrue(False, 'API should respond with 411')
@test.attr(type='gate')
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
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
self.assertTrue(False, 'API should respond with 400')
self.assertTrue(False, 'API should respond with 400')
@test.attr(type='gate')
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
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
self.assertTrue(False, 'API should respond with 400')
self.assertTrue(False, 'API should respond with 400')
@test.attr(type='gate')
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)
headers = base._get_headers(self.logs_clients["v3"].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).
@ -64,31 +66,34 @@ 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'})
try:
self.logs_client.send_single_log(data, headers)
except exceptions.OverLimit as urc:
self.assertEqual(413, urc.resp.status)
return
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
self.assertTrue(False, 'API should respond with 413')
self.assertTrue(False, 'API should respond with 413')
@test.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_client.get_headers())
data = base._get_data(message)
headers = base._get_headers(self.logs_clients["v3"].get_headers())
# Add Connection: Keep-Alive to send large message before
# connection is closed by client. In class ClosingHttp is added
# 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'})
try:
self.logs_client.send_single_log(data, headers)
except exceptions.OverLimit as urc:
self.assertEqual(413, urc.resp.status)
return
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
self.assertTrue(False, 'API should respond with 413')
self.assertTrue(False, 'API should respond with 413')

View File

@ -21,8 +21,8 @@ _RETRY_WAIT = 2
class TestSingleLog(base.BaseLogsTestCase):
def _run_and_wait(self, key, data, content_type='application/json',
headers=None):
def _run_and_wait(self, key, data, version,
content_type='application/json', headers=None):
headers = base._get_headers(headers, content_type)
@ -33,9 +33,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)
data = base._get_data(data, content_type, version=version)
response, _ = self.logs_client.send_single_log(data, headers)
response, _ = self.logs_clients[version].send_single_log(data, headers)
self.assertEqual(204, response.status)
test.call_until_true(wait, _RETRY_COUNT, _RETRY_WAIT)
@ -46,44 +46,53 @@ class TestSingleLog(base.BaseLogsTestCase):
@test.attr(type="gate")
def test_small_message(self):
self._run_and_wait(*base.generate_small_message())
for ver in self.logs_clients:
self._run_and_wait(*base.generate_small_message(), version=ver)
@test.attr(type="gate")
def test_medium_message(self):
self._run_and_wait(*base.generate_medium_message())
for ver in self.logs_clients:
self._run_and_wait(*base.generate_medium_message(), version=ver)
@test.attr(type="gate")
def test_big_message(self):
self._run_and_wait(*base.generate_large_message())
for ver in self.logs_clients:
self._run_and_wait(*base.generate_large_message(), version=ver)
@test.attr(type="gate")
def test_small_message_multiline(self):
sid, message = base.generate_small_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
for ver in self.logs_clients:
sid, message = base.generate_small_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
@test.attr(type="gate")
def test_medium_message_multiline(self):
sid, message = base.generate_medium_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
for ver in self.logs_clients:
sid, message = base.generate_medium_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
@test.attr(type="gate")
def test_big_message_multiline(self):
sid, message = base.generate_large_message()
self._run_and_wait(sid, message.replace(' ', '\n'))
for ver in self.logs_clients:
sid, message = base.generate_large_message()
self._run_and_wait(sid, message.replace(' ', '\n'), version=ver)
@test.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)
response = self._run_and_wait(sid, message, headers=headers,
version="v2")
self.assertEqual('application-type-test',
response[0]['_source']['component'])
@test.attr(type="gate")
def test_send_header_dimensions(self):
sid, message = base.generate_unique_message()
headers = {'X-Dimensions': 'server:WebServer01,environment:production'}
response = self._run_and_wait(sid, message, headers=headers)
headers = {'X-Dimensions':
'server:WebServer01,environment:production'}
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'])
@ -95,7 +104,7 @@ class TestSingleLog(base.BaseLogsTestCase):
# message_size = base._get_message_size(0.9999)
# sid, message = base.generate_unique_message(size=message_size)
#
# headers = base._get_headers(self.logs_client.get_headers())
# headers = base._get_headers(self.logs_clients.get_headers())
# response = self._run_and_wait(sid, message, headers=headers)
#
# self.assertTrue(False, 'API should respond with 500')