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 --- 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 ++ 6 files changed, 51 insertions(+) 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 (limited to 'dovetail') 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): -- cgit 1.2.3-korg