Improve configurability of Tempest tests

Adds basic support for configuring various parts of the tests to
make it easier to use them in environments which are configured
differently to DevStack. Specifically in this case the motivation
is to run the Monasca Tempest tests in Kolla CI.

This should be a NOOP change for existing environments.

Change-Id: If6be3a4d54a7b10c3ff40f9ed34045c50ffc3bae
This commit is contained in:
Doug Szumski 2020-07-27 15:20:23 +00:00
parent 42e94266d7
commit 4e5cab3fb8
5 changed files with 39 additions and 11 deletions

View File

@ -13,10 +13,13 @@
# under the License.
from tempest import clients
from tempest import config
from monasca_tempest_tests.services import elasticsearch_client
from monasca_tempest_tests.services import log_api_v3_client
CONF = config.CONF
class Manager(clients.Manager):
def __init__(self, credentials=None):
@ -24,12 +27,12 @@ class Manager(clients.Manager):
self.log_api_client = log_api_v3_client.LogApiV3Client(
self.auth_provider,
'logs',
CONF.monitoring.catalog_type_logs,
None
)
self.log_search_client = elasticsearch_client.ElasticsearchClient(
self.auth_provider,
'logs-search',
CONF.monitoring.catalog_type_log_query,
None
)

View File

@ -43,7 +43,23 @@ MonitoringGroup = [
"used."),
cfg.StrOpt("catalog_type",
default="monitoring",
help="Catalog type of the monitoring service."),
help="Keystone catalog service type of the monitoring service."),
cfg.StrOpt('catalog_type_logs',
default='logs',
help='Keystone catalog service type of the logging service.'),
cfg.StrOpt('catalog_type_log_query',
default='logs-search',
help='Keystone catalog service type of the log query service.'),
cfg.StrOpt('log_query_message_field',
default='message',
help='The field under which the log message is stored.'),
cfg.StrOpt('log_uri_path',
default='/logs',
help='Path used to form Log API URI.'),
cfg.ListOpt('log_project_id_path',
default=['_source', 'tenant'],
help='Series of keys to access the Project ID field in a persisted'
'log file.'),
cfg.StrOpt('endpoint_type',
default='publicURL',
choices=['public', 'admin', 'internal',

View File

@ -19,6 +19,7 @@ from tempest.lib.common import rest_client
CONF = cfg.CONF
header = {'kbn-version': CONF.monitoring.kibana_version, 'kbn-xsrf': 'kibana'}
@ -56,9 +57,11 @@ class ElasticsearchClient(rest_client.RestClient):
def search_messages(self, message, headers=None):
uri = '_msearch'
body = u"""
{"index" : "*", "search_type" : "dfs_query_then_fetch"}
{"query" : {"match" : {"message":" """ + message + """ "}}}\n"""
field = CONF.monitoring.log_query_message_field
body = ('\n'
'{"index" : "*", "search_type" : "dfs_query_then_fetch"}\n'
'{"query" : {"match" : {"' + field + '":"' + message + '"}}}'
'\n')
response, body = self.post(self._uri(uri), body, headers)
self.expected_success(200, response.status)
body = self.deserialize(body)

View File

@ -14,13 +14,14 @@
from oslo_serialization import jsonutils as json
from six.moves.urllib.parse import urlencode
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,
@ -39,7 +40,7 @@ class LogApiV3Client(rest_client.RestClient):
}
default_headers.update(headers)
msg = json.dumps(log)
uri = LogApiV3Client._uri
uri = CONF.monitoring.log_uri_path
if fields:
uri += '?' + urlencode(fields)
@ -49,4 +50,4 @@ class LogApiV3Client(rest_client.RestClient):
return resp, body
def custom_request(self, method, headers=None, body=None):
self.request(method=method, url=LogApiV3Client._uri, headers=headers, body=body)
self.request(method=method, url=CONF.monitoring.log_uri_path, headers=headers, body=body)

View File

@ -12,12 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest import config
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
from testtools import matchers
from monasca_tempest_tests.tests.log_api import base
CONF = config.CONF
_RETRY_COUNT = 15
_RETRY_WAIT = 2
@ -85,7 +87,10 @@ class TestSingleLog(base.BaseLogsSearchTestCase):
cross_tennant_id = '2106b2c8da0eecdb3df4ea84a0b5624b'
fields = {'tenant_id': cross_tennant_id}
response = self._run_and_wait(sid, message, headers=headers, fields=fields)
self.assertThat(response[0]['_source']['tenant'],
log_msg = response[0]
for key in CONF.monitoring.log_project_id_path:
log_msg = log_msg.pop(key)
self.assertThat(log_msg,
matchers.StartsWith(cross_tennant_id))
# TODO(trebski) following test not passing - failed to retrieve