diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/resources/v1/env.py | 16 | ||||
-rw-r--r-- | api/resources/v1/tasks.py | 50 | ||||
-rw-r--r-- | api/resources/v2/containers.py | 18 | ||||
-rw-r--r-- | api/resources/v2/testcases.py | 8 | ||||
-rw-r--r-- | api/urls.py | 1 |
5 files changed, 69 insertions, 24 deletions
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py index 47ea91643..7c831fd74 100644 --- a/api/resources/v1/env.py +++ b/api/resources/v1/env.py @@ -101,21 +101,15 @@ class V1Env(ApiResource): def _create_data_source(self, ip): url = 'http://admin:admin@{}:{}/api/datasources'.format(ip, consts.GRAFANA_PORT) - influx_conf = utils.parse_ini_file(consts.CONF_FILE) - - try: - influx_url = influx_conf['dispatcher_influxdb']['target'] - except KeyError: - LOG.exception('influxdb url not set in yardstick.conf') - raise + influx_conf = utils.parse_ini_file(consts.CONF_FILE).get('dispatcher_influxdb', {}) data = { "name": "yardstick", "type": "influxdb", "access": "proxy", - "url": influx_url, - "password": "root", - "user": "root", + "url": influx_conf.get('target', ''), + "password": influx_conf.get('password', ''), + "user": influx_conf.get('username', ''), "database": "yardstick", "basicAuth": True, "basicAuthUser": "admin", @@ -123,7 +117,7 @@ class V1Env(ApiResource): "isDefault": True, } try: - HttpClient().post(url, data) + HttpClient().post(url, data, timeout=10) except Exception: LOG.exception('Create datasources failed') raise diff --git a/api/resources/v1/tasks.py b/api/resources/v1/tasks.py new file mode 100644 index 000000000..52455fbf5 --- /dev/null +++ b/api/resources/v1/tasks.py @@ -0,0 +1,50 @@ +############################################################################## +# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import os +import errno +import uuid + +from api import ApiResource +from api.database.v1.handlers import TasksHandler +from yardstick.common import constants as consts +from yardstick.common.utils import result_handler + + +class V1TaskLog(ApiResource): + def get(self, task_id): + + try: + uuid.UUID(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid task_id') + + task_handler = TasksHandler() + try: + task = task_handler.get_task_by_taskid(task_id) + except ValueError: + return result_handler(consts.API_ERROR, 'invalid task_id') + + index = int(self._get_args().get('index', 0)) + + try: + with open(os.path.join(consts.TASK_LOG_DIR, '{}.log'.format(task_id))) as f: + f.seek(index) + data = f.readlines() + index = f.tell() + except OSError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'log file does not exist') + return result_handler(consts.API_ERROR, 'error with log file') + + return_data = { + 'index': index, + 'data': data + } + + return result_handler(task.status, return_data) diff --git a/api/resources/v2/containers.py b/api/resources/v2/containers.py index 66dc94120..f71e607e7 100644 --- a/api/resources/v2/containers.py +++ b/api/resources/v2/containers.py @@ -259,34 +259,28 @@ class V2Containers(ApiResource): def _create_dashboard(self, ip): url = 'http://admin:admin@{}:{}/api/dashboards/db'.format(ip, 3000) - path = os.path.join(consts.REPOS_DIR, 'dashboard', '*dashboard.json') + path = os.path.join(consts.REPOS_DIR, 'dashboard', 'opnfv_yardstick_tc*.json') for i in sorted(glob.iglob(path)): with open(i) as f: data = jsonutils.load(f) try: - HttpClient().post(url, data) + HttpClient().post(url, {'dashboard': data}) except Exception: LOG.exception('Create dashboard %s failed', i) raise def _create_data_source(self, ip): url = 'http://admin:admin@{}:{}/api/datasources'.format(ip, 3000) - - influx_conf = utils.parse_ini_file(consts.CONF_FILE) - try: - influx_url = influx_conf['dispatcher_influxdb']['target'] - except KeyError: - LOG.exception('influxdb url not set in yardstick.conf') - raise + influx_conf = utils.parse_ini_file(consts.CONF_FILE).get('dispatcher_influxdb', {}) data = { "name": "yardstick", "type": "influxdb", "access": "proxy", - "url": influx_url, - "password": "root", - "user": "root", + "url": influx_conf.get('target', ''), + "password": influx_conf.get('password', ''), + "user": influx_conf.get('username', ''), "database": "yardstick", "basicAuth": True, "basicAuthUser": "admin", diff --git a/api/resources/v2/testcases.py b/api/resources/v2/testcases.py index 316ef2664..0edbf6285 100644 --- a/api/resources/v2/testcases.py +++ b/api/resources/v2/testcases.py @@ -60,7 +60,13 @@ class V2Testcase(ApiResource): options = {k: {'description': '', 'type': v.__class__.__name__} for k, v in jinja2schema.infer(data).items()} - + # [('segmentation_id', < scalar >), ('image', < string >), ('provider', < scalar >), + # ('physical_network', < string >), ('packetsize', < number >)] + for k, v in options.items(): + if k == 'segmentation_id': + options[k]['type'] = 'Number' + if k == 'provider': + options[k]['type'] = 'String' return result_handler(consts.API_SUCCESS, {'testcase': data, 'args': options}) def delete(self, case_name): diff --git a/api/urls.py b/api/urls.py index 9b0040b6c..4b8e39e8f 100644 --- a/api/urls.py +++ b/api/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ Url('/yardstick/testsuites/action', 'v1_test_suite'), Url('/yardstick/results', 'v1_result'), Url('/yardstick/env/action', 'v1_env'), + Url('/yardstick/tasks/<task_id>/log', 'v1_task_log'), # api v2 Url('/api/v2/yardstick/environments', 'v2_environments'), |