From d1091a5e7c5f6b466d678fca0f47801d3e3f0e1a Mon Sep 17 00:00:00 2001 From: xudan Date: Tue, 14 May 2019 08:28:56 -0400 Subject: Add RESTful APIs into Dovetail container JIRA: DOVETAIL-774 Change-Id: Ifb934eaeda52c1d316d80d9bb9c1890ffb71049c Signed-off-by: xudan --- docker/Dockerfile | 8 ++++---- dovetail/api/app/__init__.py | 0 dovetail/api/app/constants.py | 2 ++ dovetail/api/app/routes.py | 19 +++++++++++++++++++ dovetail/api/app/server.py | 24 ++++++++++++++++++++++++ dovetail/api/boot.sh | 4 ++++ dovetail/testcase.py | 2 ++ requirements.txt | 4 +++- 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 dovetail/api/app/__init__.py create mode 100644 dovetail/api/app/constants.py create mode 100644 dovetail/api/app/routes.py create mode 100644 dovetail/api/app/server.py create mode 100755 dovetail/api/boot.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 0116a788..077f5e34 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -33,6 +33,7 @@ RUN pip install -U setuptools wheel ENV HOME /home/opnfv ENV REPOS_DIR ${HOME}/dovetail +ENV API_DIR ${REPOS_DIR}/dovetail/api WORKDIR $HOME RUN \ @@ -51,7 +52,6 @@ RUN \ WORKDIR ${REPOS_DIR}/dovetail -# get db schema from opnfv sites -# RUN mkdir -p ${REPOS_DIR}/dovetail/utils/local_db -# ADD get_db_schema.py ${REPOS_DIR}/dovetail/utils/local_db -# RUN cd ${REPOS_DIR}/dovetail/utils/local_db && python get_db_schema.py +ENV FLASK_APP ${API_DIR}/app/routes.py +EXPOSE 5000 +CMD ${API_DIR}/boot.sh diff --git a/dovetail/api/app/__init__.py b/dovetail/api/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dovetail/api/app/constants.py b/dovetail/api/app/constants.py new file mode 100644 index 00000000..14d9145e --- /dev/null +++ b/dovetail/api/app/constants.py @@ -0,0 +1,2 @@ +NFVI_PROJECT = ['bottlenecks', 'functest', 'yardstick'] +VNF_PROJECT = ['onap-vtp', 'onap-vvp'] diff --git a/dovetail/api/app/routes.py b/dovetail/api/app/routes.py new file mode 100644 index 00000000..c235cb48 --- /dev/null +++ b/dovetail/api/app/routes.py @@ -0,0 +1,19 @@ +#!flask/bin/python + +from flask import Flask, jsonify + +import server + +app = Flask(__name__) + + +@app.route('/api/v1/scenario/nfvi/testsuites', methods=['GET']) +def get_all_testsuites(): + testsuites = server.list_testsuites() + return jsonify({'testsuites': testsuites}), 200 + + +@app.route('/api/v1/scenario/nfvi/testcases', methods=['GET']) +def get_testcases(): + testcases = server.list_testcases() + return jsonify({'testcases': testcases}), 200 diff --git a/dovetail/api/app/server.py b/dovetail/api/app/server.py new file mode 100644 index 00000000..4428c251 --- /dev/null +++ b/dovetail/api/app/server.py @@ -0,0 +1,24 @@ +import constants + +from dovetail.testcase import Testsuite, Testcase + + +def list_testsuites(): + return Testsuite.load() + + +def list_testcases(): + testcases = Testcase.load() + testcase_list = [] + for key, value in testcases.items(): + testcase = {'testCaseName': key, + 'description': value.objective(), + 'subTestCase': value.sub_testcase()} + if value.validate_type() in constants.NFVI_PROJECT: + testcase['scenario'] = 'nfvi' + elif value.validate_type() in constants.VNF_PROJECT: + testcase['scenario'] = 'vnf' + else: + testcase['scenario'] = 'unknown' + testcase_list.append(testcase) + return testcase_list diff --git a/dovetail/api/boot.sh b/dovetail/api/boot.sh new file mode 100755 index 00000000..dc49876a --- /dev/null +++ b/dovetail/api/boot.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd $(dirname $(readlink -f $0)) +exec gunicorn -b :5000 --access-logfile - --error-logfile - app.routes:app diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 279c6ba0..deb00250 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -202,6 +202,7 @@ class Testcase(object): else: cls.logger.error('Failed to create test case: {}' .format(testcase_file)) + return cls.testcase_list @classmethod def get(cls, testcase_name): @@ -403,6 +404,7 @@ class Testsuite(object): with open(os.path.join(root, testsuite_yaml)) as f: testsuite_yaml = yaml.safe_load(f) cls.testsuite_list.update(testsuite_yaml) + return cls.testsuite_list @classmethod def get(cls, testsuite_name): diff --git a/requirements.txt b/requirements.txt index df7b971d..ae2aff1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,10 +9,12 @@ ansible==2.2.0 click==6.7 +docker==3.4.1 +flask==1.0.2 +gunicorn==19.9.0 Jinja2==2.10 os-client-config==1.29.0 pbr==3.1.1 python-hosts==0.4.1 PyYAML==3.12 shade==1.27.2 -docker==3.4.1 -- cgit 1.2.3-korg