summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rwxr-xr-xapi/api-prepare.sh33
-rw-r--r--api/conf.py28
-rw-r--r--api/resources/env_action.py101
-rw-r--r--api/resources/release_action.py6
-rw-r--r--api/resources/samples_action.py4
-rw-r--r--api/swagger/docs/release_action.yaml108
-rw-r--r--api/swagger/docs/results.yaml8
-rw-r--r--api/swagger/docs/testsuites_action.yaml8
-rw-r--r--api/urls.py1
-rw-r--r--api/utils/common.py2
-rw-r--r--api/utils/daemonthread.py4
-rw-r--r--api/utils/influx.py8
-rw-r--r--api/yardstick.ini16
13 files changed, 136 insertions, 191 deletions
diff --git a/api/api-prepare.sh b/api/api-prepare.sh
index 5cc65c959..7632d9da9 100755
--- a/api/api-prepare.sh
+++ b/api/api-prepare.sh
@@ -8,6 +8,36 @@
# 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'
@@ -24,7 +54,6 @@ server {
}
}
EOF
-echo "daemon off;" >> /etc/nginx/nginx.conf
fi
# nginx service start when boot
@@ -42,7 +71,7 @@ autorestart = true
[program:yardstick_uwsgi]
user = root
-directory = /home/opnfv/repos/yardstick/api
+directory = /etc/yardstick
command = uwsgi -i yardstick.ini
autorestart = true
EOF
diff --git a/api/conf.py b/api/conf.py
deleted file mode 100644
index a4f332533..000000000
--- a/api/conf.py
+++ /dev/null
@@ -1,28 +0,0 @@
-##############################################################################
-# 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
-##############################################################################
-from __future__ import absolute_import
-from pyroute2 import IPDB
-
-
-# configuration for influxdb
-with IPDB() as ip:
- GATEWAY_IP = ip.routes['default'].gateway
-PORT = 8086
-
-TEST_CASE_PATH = '../tests/opnfv/test_cases/'
-
-SAMPLE_PATH = '../samples/'
-
-TEST_CASE_PRE = 'opnfv_yardstick_'
-
-TEST_SUITE_PATH = '../tests/opnfv/test_suites/'
-
-TEST_SUITE_PRE = 'opnfv_'
-
-OUTPUT_CONFIG_FILE_PATH = '/etc/yardstick/yardstick.conf'
diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 9d1686a1d..7bfaf27a7 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -19,17 +19,17 @@ import glob
from six.moves import configparser
from oslo_serialization import jsonutils
+from docker import Client
-from api import conf as api_conf
from api.database.handler import AsyncTaskHandler
from api.utils import influx
from api.utils.common import result_handler
-from docker import Client
-from yardstick.common import constants as config
+from yardstick.common import constants as consts
from yardstick.common import utils as yardstick_utils
from yardstick.common import openstack_utils
from yardstick.common.httpClient import HttpClient
+
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@@ -46,12 +46,12 @@ def createGrafanaContainer(args):
def _create_grafana(task_id):
_create_task(task_id)
- client = Client(base_url=config.DOCKER_URL)
+ client = Client(base_url=consts.DOCKER_URL)
try:
- if not _check_image_exist(client, '%s:%s' % (config.GRAFANA_IMAGE,
- config.GRAFANA_TAGS)):
- client.pull(config.GRAFANA_IMAGE, config.GRAFANA_TAGS)
+ image = '{}:{}'.format(consts.GRAFANA_IMAGE, consts.GRAFANA_TAG)
+ if not _check_image_exist(client, image):
+ client.pull(consts.GRAFANA_IMAGE, consts.GRAFANA_TAG)
_create_grafana_container(client)
@@ -64,13 +64,12 @@ def _create_grafana(task_id):
_update_task_status(task_id)
except Exception as e:
_update_task_error(task_id, str(e))
- logger.debug('Error: %s', e)
+ logger.exception('Error: %s', e)
def _create_dashboard():
- url = 'http://admin:admin@%s:3000/api/dashboards/db' % api_conf.GATEWAY_IP
- path = os.path.join(config.YARDSTICK_REPOS_DIR, 'dashboard',
- '*dashboard.json')
+ url = 'http://admin:admin@%s:3000/api/dashboards/db' % consts.GRAFANA_IP
+ path = os.path.join(consts.REPOS_DIR, 'dashboard', '*dashboard.json')
for i in sorted(glob.iglob(path)):
with open(i) as f:
@@ -79,12 +78,12 @@ def _create_dashboard():
def _create_data_source():
- url = 'http://admin:admin@%s:3000/api/datasources' % api_conf.GATEWAY_IP
+ url = 'http://admin:admin@%s:3000/api/datasources' % consts.GRAFANA_IP
data = {
"name": "yardstick",
"type": "influxdb",
"access": "proxy",
- "url": "http://%s:8086" % api_conf.GATEWAY_IP,
+ "url": "http://%s:8086" % consts.INFLUXDB_IP,
"password": "root",
"user": "root",
"database": "yardstick",
@@ -101,8 +100,8 @@ def _create_grafana_container(client):
port_bindings = {k: k for k in ports}
host_config = client.create_host_config(port_bindings=port_bindings)
- container = client.create_container(image='%s:%s' % (config.GRAFANA_IMAGE,
- config.GRAFANA_TAGS),
+ container = client.create_container(image='%s:%s' % (consts.GRAFANA_IMAGE,
+ consts.GRAFANA_TAG),
ports=ports,
detach=True,
tty=True,
@@ -126,14 +125,14 @@ def createInfluxDBContainer(args):
def _create_influxdb(task_id):
_create_task(task_id)
- client = Client(base_url=config.DOCKER_URL)
+ client = Client(base_url=consts.DOCKER_URL)
try:
_change_output_to_influxdb()
- if not _check_image_exist(client, '%s:%s' % (config.INFLUXDB_IMAGE,
- config.INFLUXDB_TAG)):
- client.pull(config.INFLUXDB_IMAGE, tag=config.INFLUXDB_TAG)
+ if not _check_image_exist(client, '%s:%s' % (consts.INFLUXDB_IMAGE,
+ consts.INFLUXDB_TAG)):
+ client.pull(consts.INFLUXDB_IMAGE, tag=consts.INFLUXDB_TAG)
_create_influxdb_container(client)
@@ -153,8 +152,8 @@ def _create_influxdb_container(client):
port_bindings = {k: k for k in ports}
host_config = client.create_host_config(port_bindings=port_bindings)
- container = client.create_container(image='%s:%s' % (config.INFLUXDB_IMAGE,
- config.INFLUXDB_TAG),
+ container = client.create_container(image='%s:%s' % (consts.INFLUXDB_IMAGE,
+ consts.INFLUXDB_TAG),
ports=ports,
detach=True,
tty=True,
@@ -165,24 +164,26 @@ def _create_influxdb_container(client):
def _config_influxdb():
try:
client = influx.get_data_db_client()
- client.create_user(config.USER, config.PASSWORD, config.DATABASE)
- client.create_database(config.DATABASE)
+ client.create_user(consts.INFLUXDB_USER,
+ consts.INFLUXDB_PASS,
+ consts.INFLUXDB_DB_NAME)
+ client.create_database(consts.INFLUXDB_DB_NAME)
logger.info('Success to config influxDB')
except Exception as e:
logger.debug('Failed to config influxDB: %s', e)
def _change_output_to_influxdb():
- yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)
+ yardstick_utils.makedirs(consts.CONF_DIR)
parser = configparser.ConfigParser()
- parser.read(config.YARDSTICK_CONFIG_SAMPLE_FILE)
+ parser.read(consts.CONF_SAMPLE_FILE)
parser.set('DEFAULT', 'dispatcher', 'influxdb')
parser.set('dispatcher_influxdb', 'target',
- 'http://%s:8086' % api_conf.GATEWAY_IP)
+ 'http://%s:8086' % consts.INFLUXDB_IP)
- with open(config.YARDSTICK_CONFIG_FILE, 'w') as f:
+ with open(consts.CONF_FILE, 'w') as f:
parser.write(f)
@@ -198,30 +199,25 @@ def prepareYardstickEnv(args):
def _already_source_openrc():
"""Check if openrc is sourced already"""
return all(os.environ.get(k) for k in ['OS_AUTH_URL', 'OS_USERNAME',
- 'OS_PASSWORD', 'OS_TENANT_NAME',
- 'EXTERNAL_NETWORK'])
+ 'OS_PASSWORD', 'EXTERNAL_NETWORK'])
def _prepare_env_daemon(task_id):
_create_task(task_id)
- installer_ip = os.environ.get('INSTALLER_IP', 'undefined')
- installer_type = os.environ.get('INSTALLER_TYPE', 'undefined')
-
try:
- _check_variables(installer_ip, installer_type)
-
_create_directories()
- rc_file = config.OPENSTACK_RC_FILE
+ rc_file = consts.OPENRC
if not _already_source_openrc():
- _get_remote_rc_file(rc_file, installer_ip, installer_type)
+ if not os.path.exists(rc_file):
+ installer_ip = os.environ.get('INSTALLER_IP', '192.168.200.2')
+ installer_type = os.environ.get('INSTALLER_TYPE', 'compass')
+ _get_remote_rc_file(rc_file, installer_ip, installer_type)
+ _source_file(rc_file)
+ _append_external_network(rc_file)
_source_file(rc_file)
- _append_external_network(rc_file)
-
- # update the external_network
- _source_file(rc_file)
_clean_images()
@@ -233,19 +229,8 @@ def _prepare_env_daemon(task_id):
logger.debug('Error: %s', e)
-def _check_variables(installer_ip, installer_type):
-
- if installer_ip == 'undefined':
- raise SystemExit('Missing INSTALLER_IP')
-
- if installer_type == 'undefined':
- raise SystemExit('Missing INSTALLER_TYPE')
- elif installer_type not in config.INSTALLERS:
- raise SystemExit('INSTALLER_TYPE is not correct')
-
-
def _create_directories():
- yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)
+ yardstick_utils.makedirs(consts.CONF_DIR)
def _source_file(rc_file):
@@ -254,7 +239,7 @@ def _source_file(rc_file):
def _get_remote_rc_file(rc_file, installer_ip, installer_type):
- os_fetch_script = os.path.join(config.RELENG_DIR, config.OS_FETCH_SCRIPT)
+ os_fetch_script = os.path.join(consts.RELENG_DIR, consts.FETCH_SCRIPT)
try:
cmd = [os_fetch_script, '-d', rc_file, '-i', installer_type,
@@ -287,17 +272,15 @@ def _append_external_network(rc_file):
def _clean_images():
- cmd = [config.CLEAN_IMAGES_SCRIPT]
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- cwd=config.YARDSTICK_REPOS_DIR)
+ cmd = [consts.CLEAN_IMAGES_SCRIPT]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=consts.REPOS_DIR)
output = p.communicate()[0]
logger.debug('The result is: %s', output)
def _load_images():
- cmd = [config.LOAD_IMAGES_SCRIPT]
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- cwd=config.YARDSTICK_REPOS_DIR)
+ cmd = [consts.LOAD_IMAGES_SCRIPT]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=consts.REPOS_DIR)
output = p.communicate()[0]
logger.debug('The result is: %s', output)
diff --git a/api/resources/release_action.py b/api/resources/release_action.py
index c5aa20afc..9016d4aa2 100644
--- a/api/resources/release_action.py
+++ b/api/resources/release_action.py
@@ -11,8 +11,8 @@ import uuid
import os
import logging
-from api import conf
from api.utils import common as common_utils
+from yardstick.common import constants as consts
logger = logging.getLogger(__name__)
@@ -24,8 +24,8 @@ def runTestCase(args):
except KeyError:
return common_utils.error_handler('Lack of testcase argument')
- testcase_name = conf.TEST_CASE_PRE + testcase
- testcase = os.path.join(conf.TEST_CASE_PATH, testcase_name + '.yaml')
+ testcase_name = consts.TESTCASE_PRE + testcase
+ testcase = os.path.join(consts.TESTCASE_DIR, testcase_name + '.yaml')
task_id = str(uuid.uuid4())
diff --git a/api/resources/samples_action.py b/api/resources/samples_action.py
index 490e48b25..3093864e0 100644
--- a/api/resources/samples_action.py
+++ b/api/resources/samples_action.py
@@ -11,8 +11,8 @@ import uuid
import os
import logging
-from api import conf
from api.utils import common as common_utils
+from yardstick.common import constants as consts
logger = logging.getLogger(__name__)
@@ -24,7 +24,7 @@ def runTestCase(args):
except KeyError:
return common_utils.error_handler('Lack of testcase argument')
- testcase = os.path.join(conf.SAMPLE_PATH, testcase_name + '.yaml')
+ testcase = os.path.join(consts.SAMPLE_CASE_DIR, testcase_name + '.yaml')
task_id = str(uuid.uuid4())
diff --git a/api/swagger/docs/release_action.yaml b/api/swagger/docs/release_action.yaml
index 0e08e582f..0a6968bc5 100644
--- a/api/swagger/docs/release_action.yaml
+++ b/api/swagger/docs/release_action.yaml
@@ -1,58 +1,50 @@
-##############################################################################
-# Copyright (c) 2017 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
-##############################################################################
-TestCases Actions
-
-This API may offer many actions, including runTestCase
-
-action: runTestCase
-This api offer the interface to run a test case in yardstick
-we will return a task_id for querying
-you can use the returned task_id to get the result data
----
-tags:
- - Release Action
-parameters:
- - in: body
- name: body
- description: this is the input json dict
- schema:
- id: TestCaseActionModel
- required:
- - action
- - args
- properties:
- action:
- type: string
- description: this is action for testcases
- default: runTestCase
- args:
- schema:
- id: TestCaseActionArgsModel
- required:
- - testcase
- properties:
- testcase:
- type: string
- description: this is the test case name
- default: tc002
- opts:
- schema:
- id: TestCaseActionArgsOptsModel
-responses:
- 200:
- description: A result json dict
- schema:
- id: result
- properties:
- status:
- type: string
- default: success
- result:
- type: string
- description: task_id of this task
+TestCases Actions
+
+This API may offer many actions, including runTestCase
+
+action: runTestCase
+This api offer the interface to run a test case in yardstick
+we will return a task_id for querying
+you can use the returned task_id to get the result data
+---
+tags:
+ - Release Action
+parameters:
+ - in: body
+ name: body
+ description: this is the input json dict
+ schema:
+ id: TestCaseActionModel
+ required:
+ - action
+ - args
+ properties:
+ action:
+ type: string
+ description: this is action for testcases
+ default: runTestCase
+ args:
+ schema:
+ id: TestCaseActionArgsModel
+ required:
+ - testcase
+ properties:
+ testcase:
+ type: string
+ description: this is the test case name
+ default: tc002
+ opts:
+ schema:
+ id: TestCaseActionArgsOptsModel
+responses:
+ 200:
+ description: A result json dict
+ schema:
+ id: result
+ properties:
+ status:
+ type: string
+ default: success
+ result:
+ type: string
+ description: task_id of this task
diff --git a/api/swagger/docs/results.yaml b/api/swagger/docs/results.yaml
index 00b159003..7bdab3eb6 100644
--- a/api/swagger/docs/results.yaml
+++ b/api/swagger/docs/results.yaml
@@ -1,11 +1,3 @@
-##############################################################################
-# Copyright (c) 2017 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
-##############################################################################
Query task result data
This api offer the interface to get the result data via task_id
diff --git a/api/swagger/docs/testsuites_action.yaml b/api/swagger/docs/testsuites_action.yaml
index ca8d22738..ebf01e4ec 100644
--- a/api/swagger/docs/testsuites_action.yaml
+++ b/api/swagger/docs/testsuites_action.yaml
@@ -1,11 +1,3 @@
-##############################################################################
-# Copyright (c) 2017 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
-##############################################################################
TestSuites Actions
This API may offer many actions, including runTestSuite
diff --git a/api/urls.py b/api/urls.py
index 3ccb67dbc..b9ddd4c72 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from __future__ import absolute_import
+
from api import views
from api.utils.common import Url
diff --git a/api/utils/common.py b/api/utils/common.py
index 3e9bf8f8b..f8b0d40ba 100644
--- a/api/utils/common.py
+++ b/api/utils/common.py
@@ -11,10 +11,10 @@ import collections
import logging
from flask import jsonify
+import six
from api.utils.daemonthread import DaemonThread
from yardstick.cmd.cli import YardstickCLI
-import six
logger = logging.getLogger(__name__)
diff --git a/api/utils/daemonthread.py b/api/utils/daemonthread.py
index 0049834eb..3d5625547 100644
--- a/api/utils/daemonthread.py
+++ b/api/utils/daemonthread.py
@@ -11,7 +11,7 @@ import threading
import os
import errno
-from api import conf
+from yardstick.common import constants as consts
from api.database.handlers import TasksHandler
@@ -43,7 +43,7 @@ class DaemonThread(threading.Thread):
def _handle_testsuite_file(task_id):
try:
- os.remove(os.path.join(conf.TEST_SUITE_PATH, task_id + '.yaml'))
+ os.remove(os.path.join(consts.TESTSUITE_DIR, task_id + '.yaml'))
except OSError as e:
if e.errno != errno.ENOENT:
raise
diff --git a/api/utils/influx.py b/api/utils/influx.py
index 08996b9c9..9bc6e9abe 100644
--- a/api/utils/influx.py
+++ b/api/utils/influx.py
@@ -14,7 +14,7 @@ import six.moves.configparser as ConfigParser
from six.moves.urllib.parse import urlsplit
from influxdb import InfluxDBClient
-from api import conf
+from yardstick.common import constants as consts
logger = logging.getLogger(__name__)
@@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
def get_data_db_client():
parser = ConfigParser.ConfigParser()
try:
- parser.read(conf.OUTPUT_CONFIG_FILE_PATH)
+ parser.read(consts.CONF_FILE)
if parser.get('DEFAULT', 'dispatcher') != 'influxdb':
raise RuntimeError
@@ -35,10 +35,10 @@ def get_data_db_client():
def _get_client(parser):
ip = _get_ip(parser.get('dispatcher_influxdb', 'target'))
- username = parser.get('dispatcher_influxdb', 'username')
+ user = parser.get('dispatcher_influxdb', 'username')
password = parser.get('dispatcher_influxdb', 'password')
db_name = parser.get('dispatcher_influxdb', 'db_name')
- return InfluxDBClient(ip, conf.PORT, username, password, db_name)
+ return InfluxDBClient(ip, consts.INFLUXDB_PORT, user, password, db_name)
def _get_ip(url):
diff --git a/api/yardstick.ini b/api/yardstick.ini
deleted file mode 100644
index d2e8956e2..000000000
--- a/api/yardstick.ini
+++ /dev/null
@@ -1,16 +0,0 @@
-[uwsgi]
-master = true
-debug = true
-chdir = /home/opnfv/repos/yardstick/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