Add RESTful APIs into Dovetail container 69/67869/3
authorxudan <xudan16@huawei.com>
Tue, 14 May 2019 12:28:56 +0000 (08:28 -0400)
committerDan Xu <xudan16@huawei.com>
Wed, 12 Jun 2019 01:33:40 +0000 (01:33 +0000)
JIRA: DOVETAIL-774

Change-Id: Ifb934eaeda52c1d316d80d9bb9c1890ffb71049c
Signed-off-by: xudan <xudan16@huawei.com>
docker/Dockerfile
dovetail/api/app/__init__.py [new file with mode: 0644]
dovetail/api/app/constants.py [new file with mode: 0644]
dovetail/api/app/routes.py [new file with mode: 0644]
dovetail/api/app/server.py [new file with mode: 0644]
dovetail/api/boot.sh [new file with mode: 0755]
dovetail/testcase.py
requirements.txt

index 0116a78..077f5e3 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/dovetail/api/app/constants.py b/dovetail/api/app/constants.py
new file mode 100644 (file)
index 0000000..14d9145
--- /dev/null
@@ -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 (file)
index 0000000..c235cb4
--- /dev/null
@@ -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 (file)
index 0000000..4428c25
--- /dev/null
@@ -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 (executable)
index 0000000..dc49876
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cd $(dirname $(readlink -f $0))
+exec gunicorn -b :5000 --access-logfile - --error-logfile - app.routes:app
index 279c6ba..deb0025 100644 (file)
@@ -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):
index df7b971..ae2aff1 100644 (file)
@@ -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