diff options
Diffstat (limited to 'api')
-rwxr-xr-x | api/api-prepare.sh | 84 | ||||
-rw-r--r-- | api/database/v2/models.py | 2 | ||||
-rw-r--r-- | api/resources/v1/env.py | 52 | ||||
-rw-r--r-- | api/resources/v2/containers.py | 2 | ||||
-rw-r--r-- | api/resources/v2/environments.py | 8 | ||||
-rw-r--r-- | api/resources/v2/images.py | 10 | ||||
-rw-r--r-- | api/resources/v2/openrcs.py | 8 | ||||
-rw-r--r-- | api/resources/v2/pods.py | 8 | ||||
-rw-r--r-- | api/resources/v2/projects.py | 8 | ||||
-rw-r--r-- | api/resources/v2/tasks.py | 11 | ||||
-rw-r--r-- | api/resources/v2/testcases.py | 10 | ||||
-rw-r--r-- | api/resources/v2/testsuites.py | 8 | ||||
-rw-r--r-- | api/urls.py | 3 | ||||
-rw-r--r-- | api/utils/thread.py | 8 |
14 files changed, 117 insertions, 105 deletions
diff --git a/api/api-prepare.sh b/api/api-prepare.sh deleted file mode 100755 index 7632d9da9..000000000 --- a/api/api-prepare.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -############################################################################## -# 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 -############################################################################## - -: ${YARDSTICK_REPO_DIR:='/home/opnfv/repos/yardstick'} - -# generate uwsgi config file -mkdir -p /etc/yardstick -uwsgi_config='/etc/yardstick/yardstick.ini' -if [[ ! -e "${uwsgi_config}" ]];then - - cat << EOF > "${uwsgi_config}" -[uwsgi] -master = true -debug = true -chdir = ${YARDSTICK_REPO_DIR}/api -module = server -plugins = python -processes = 10 -threads = 5 -async = true -max-requests = 5000 -chmod-socket = 666 -callable = app_wrapper -enable-threads = true -close-on-exec = 1 -daemonize= /var/log/yardstick/uwsgi.log -socket = /var/run/yardstick.sock -EOF - if [[ "${YARDSTICK_VENV}" ]];then - echo "virtualenv = ${YARDSTICK_VENV}" >> "${uwsgi_config}" - fi -fi - -# nginx config -nginx_config='/etc/nginx/conf.d/yardstick.conf' - -if [[ ! -e "${nginx_config}" ]];then - - cat << EOF > "${nginx_config}" -server { - listen 5000; - server_name localhost; - index index.htm index.html; - location / { - include uwsgi_params; - uwsgi_pass unix:///var/run/yardstick.sock; - } -} -EOF -fi - -# nginx service start when boot -supervisor_config='/etc/supervisor/conf.d/yardstick.conf' - -if [[ ! -e "${supervisor_config}" ]];then - cat << EOF > "${supervisor_config}" -[supervisord] -nodaemon = true - -[program:yardstick_nginx] -user = root -command = service nginx restart -autorestart = true - -[program:yardstick_uwsgi] -user = root -directory = /etc/yardstick -command = uwsgi -i yardstick.ini -autorestart = true -EOF -fi - -# create api log directory -mkdir -p /var/log/yardstick - -# create yardstick.sock for communicating -touch /var/run/yardstick.sock diff --git a/api/database/v2/models.py b/api/database/v2/models.py index 64d49cc9d..1e85559cb 100644 --- a/api/database/v2/models.py +++ b/api/database/v2/models.py @@ -31,7 +31,7 @@ class V2Environment(Base): class V2Openrc(Base): - __tablename__ = 'V2_openrc' + __tablename__ = 'v2_openrc' id = Column(Integer, primary_key=True) uuid = Column(String(30)) name = Column(String(30)) diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py index 4632f15fe..8943db3d1 100644 --- a/api/resources/v1/env.py +++ b/api/resources/v1/env.py @@ -65,16 +65,20 @@ class V1Env(ApiResource): client.pull(consts.GRAFANA_IMAGE, consts.GRAFANA_TAG) LOG.info('Createing grafana container') - self._create_grafana_container(client) + container = self._create_grafana_container(client) LOG.info('Grafana container is created') time.sleep(5) + container = client.inspect_container(container['Id']) + ip = container['NetworkSettings']['Networks']['bridge']['IPAddress'] + LOG.debug('container ip is: %s', ip) + LOG.info('Creating data source for grafana') - self._create_data_source() + self._create_data_source(ip) LOG.info('Creating dashboard for grafana') - self._create_dashboard() + self._create_dashboard(ip) self._update_task_status(task_id) LOG.info('Finished') @@ -82,8 +86,8 @@ class V1Env(ApiResource): self._update_task_error(task_id, str(e)) LOG.exception('Create grafana failed') - def _create_dashboard(self): - url = 'http://admin:admin@%s:3000/api/dashboards/db' % consts.GRAFANA_IP + def _create_dashboard(self, ip): + url = 'http://admin:admin@{}:{}/api/dashboards/db'.format(ip, consts.GRAFANA_PORT) path = os.path.join(consts.REPOS_DIR, 'dashboard', '*dashboard.json') for i in sorted(glob.iglob(path)): @@ -95,13 +99,21 @@ class V1Env(ApiResource): LOG.exception('Create dashboard %s failed', i) raise - def _create_data_source(self): - url = 'http://admin:admin@%s:3000/api/datasources' % consts.GRAFANA_IP + 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 + data = { "name": "yardstick", "type": "influxdb", "access": "proxy", - "url": "http://%s:8086" % consts.INFLUXDB_IP, + "url": influx_url, "password": "root", "user": "root", "database": "yardstick", @@ -117,8 +129,8 @@ class V1Env(ApiResource): raise def _create_grafana_container(self, client): - ports = [3000] - port_bindings = {k: k for k in ports} + ports = [consts.GRAFANA_PORT] + port_bindings = {consts.GRAFANA_PORT: consts.GRAFANA_MAPPING_PORT} restart_policy = {"MaximumRetryCount": 0, "Name": "always"} host_config = client.create_host_config(port_bindings=port_bindings, restart_policy=restart_policy) @@ -133,6 +145,7 @@ class V1Env(ApiResource): host_config=host_config) LOG.info('Starting container') client.start(container) + return container def _check_image_exist(self, client, t): return any(t in a['RepoTags'][0] @@ -152,9 +165,6 @@ class V1Env(ApiResource): client = Client(base_url=consts.DOCKER_URL) try: - LOG.info('Changing output to influxdb') - self._change_output_to_influxdb() - LOG.info('Checking if influxdb image exist') if not self._check_image_exist(client, '%s:%s' % (consts.INFLUXDB_IMAGE, @@ -163,11 +173,18 @@ class V1Env(ApiResource): client.pull(consts.INFLUXDB_IMAGE, tag=consts.INFLUXDB_TAG) LOG.info('Createing influxdb container') - self._create_influxdb_container(client) + container = self._create_influxdb_container(client) LOG.info('Influxdb container is created') time.sleep(5) + container = client.inspect_container(container['Id']) + ip = container['NetworkSettings']['Networks']['bridge']['IPAddress'] + LOG.debug('container ip is: %s', ip) + + LOG.info('Changing output to influxdb') + self._change_output_to_influxdb(ip) + LOG.info('Config influxdb') self._config_influxdb() @@ -180,7 +197,7 @@ class V1Env(ApiResource): def _create_influxdb_container(self, client): - ports = [8083, 8086] + ports = [consts.INFLUXDB_DASHBOARD_PORT, consts.INFLUXDB_PORT] port_bindings = {k: k for k in ports} restart_policy = {"MaximumRetryCount": 0, "Name": "always"} host_config = client.create_host_config(port_bindings=port_bindings, @@ -196,6 +213,7 @@ class V1Env(ApiResource): host_config=host_config) LOG.info('Starting container') client.start(container) + return container def _config_influxdb(self): try: @@ -208,7 +226,7 @@ class V1Env(ApiResource): except Exception: LOG.exception('Config influxdb failed') - def _change_output_to_influxdb(self): + def _change_output_to_influxdb(self, ip): utils.makedirs(consts.CONF_DIR) parser = configparser.ConfigParser() @@ -218,7 +236,7 @@ class V1Env(ApiResource): LOG.info('Set dispatcher to influxdb') parser.set('DEFAULT', 'dispatcher', 'influxdb') parser.set('dispatcher_influxdb', 'target', - 'http://%s:8086' % consts.INFLUXDB_IP) + 'http://{}:{}'.format(ip, consts.INFLUXDB_PORT)) LOG.info('Writing to %s', consts.CONF_FILE) with open(consts.CONF_FILE, 'w') as f: diff --git a/api/resources/v2/containers.py b/api/resources/v2/containers.py index ce7130376..66dc94120 100644 --- a/api/resources/v2/containers.py +++ b/api/resources/v2/containers.py @@ -1,5 +1,5 @@ ############################################################################## -# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others. +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 diff --git a/api/resources/v2/environments.py b/api/resources/v2/environments.py index e4679b0d6..f021a3c5a 100644 --- a/api/resources/v2/environments.py +++ b/api/resources/v2/environments.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 uuid import logging diff --git a/api/resources/v2/images.py b/api/resources/v2/images.py index 701818493..8359e105b 100644 --- a/api/resources/v2/images.py +++ b/api/resources/v2/images.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 logging import subprocess import threading @@ -29,6 +37,8 @@ class V2Images(ApiResource): else: images = [self.get_info(change_obj_to_dict(i)) for i in images_list] status = 1 if all(i['status'] == 'ACTIVE' for i in images) else 0 + if not images: + status = 0 return result_handler(consts.API_SUCCESS, {'status': status, 'images': images}) diff --git a/api/resources/v2/openrcs.py b/api/resources/v2/openrcs.py index 5f3b9382f..cb506d0e8 100644 --- a/api/resources/v2/openrcs.py +++ b/api/resources/v2/openrcs.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 uuid import logging import re diff --git a/api/resources/v2/pods.py b/api/resources/v2/pods.py index ebc1312da..f2316d353 100644 --- a/api/resources/v2/pods.py +++ b/api/resources/v2/pods.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 uuid import yaml import logging diff --git a/api/resources/v2/projects.py b/api/resources/v2/projects.py index 376cf1a37..2ff61d0fe 100644 --- a/api/resources/v2/projects.py +++ b/api/resources/v2/projects.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 uuid import logging diff --git a/api/resources/v2/tasks.py b/api/resources/v2/tasks.py index 9790d7640..885a190c6 100644 --- a/api/resources/v2/tasks.py +++ b/api/resources/v2/tasks.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 uuid import logging from datetime import datetime @@ -106,7 +114,8 @@ class V2Task(ApiResource): if project.tasks: LOG.info('update tasks in project') - new_task_list = project.tasks.split(',').remove(task_id) + new_task_list = project.tasks.split(',') + new_task_list.remove(task_id) if new_task_list: new_tasks = ','.join(new_task_list) else: diff --git a/api/resources/v2/testcases.py b/api/resources/v2/testcases.py index 81b4aa88c..b47a8f6b7 100644 --- a/api/resources/v2/testcases.py +++ b/api/resources/v2/testcases.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 logging import errno import os @@ -17,7 +25,7 @@ class V2Testcases(ApiResource): def get(self): param = Param({}) testcase_list = Testcase().list_all(param) - return result_handler(consts.API_SUCCESS, testcase_list) + return result_handler(consts.API_SUCCESS, {'testcases': testcase_list}) def post(self): return self._dispatch_post() diff --git a/api/resources/v2/testsuites.py b/api/resources/v2/testsuites.py index ee942eff9..56ad47375 100644 --- a/api/resources/v2/testsuites.py +++ b/api/resources/v2/testsuites.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 logging diff --git a/api/urls.py b/api/urls.py index 2211348f3..3fef91af8 100644 --- a/api/urls.py +++ b/api/urls.py @@ -26,15 +26,18 @@ urlpatterns = [ Url('/api/v2/yardstick/environments/action', 'v2_environments'), Url('/api/v2/yardstick/environments/<environment_id>', 'v2_environment'), + Url('/api/v2/yardstick/openrcs', 'v2_openrcs'), Url('/api/v2/yardstick/openrcs/action', 'v2_openrcs'), Url('/api/v2/yardstick/openrcs/<openrc_id>', 'v2_openrc'), + Url('/api/v2/yardstick/pods', 'v2_pods'), Url('/api/v2/yardstick/pods/action', 'v2_pods'), Url('/api/v2/yardstick/pods/<pod_id>', 'v2_pod'), Url('/api/v2/yardstick/images', 'v2_images'), Url('/api/v2/yardstick/images/action', 'v2_images'), + Url('/api/v2/yardstick/containers', 'v2_containers'), Url('/api/v2/yardstick/containers/action', 'v2_containers'), Url('/api/v2/yardstick/containers/<container_id>', 'v2_container'), diff --git a/api/utils/thread.py b/api/utils/thread.py index 5f4ec7e94..20bd07a12 100644 --- a/api/utils/thread.py +++ b/api/utils/thread.py @@ -1,3 +1,11 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# 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 threading import os import logging |