Add API to show test case documentation 91/36691/3
authorchenjiankun <chenjiankun1@huawei.com>
Thu, 29 Jun 2017 03:38:04 +0000 (03:38 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Fri, 30 Jun 2017 02:52:58 +0000 (02:52 +0000)
JIRA: YARDSTICK-694

We need API to show test case documentation.
API: /yardstick/testcases/<testcase_name>/docs
method: GET

example:
http://192.168.131.2:8888/yardstick/testcases/opnfv_yardstick_tc002/docs

Change-Id: Ib8d591f0ff5f91c4d0a740539727ec73ddd86249
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/base.py
api/resources/case_docs.py [new file with mode: 0644]
api/urls.py
api/views.py
yardstick/common/constants.py

index 6fa2777..6a4ba12 100644 (file)
@@ -47,8 +47,9 @@ class ApiResource(Resource):
         action, args = self._post_args()
         return self._dispatch(args, action)
 
-    def _dispatch_get(self):
+    def _dispatch_get(self, **kwargs):
         args = self._get_args()
+        args.update(kwargs)
         return self._dispatch(args)
 
     def _dispatch(self, args, action='default'):
diff --git a/api/resources/case_docs.py b/api/resources/case_docs.py
new file mode 100644 (file)
index 0000000..289410d
--- /dev/null
@@ -0,0 +1,30 @@
+import os
+import logging
+
+from api.utils.common import result_handler
+from yardstick.common import constants as consts
+
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
+
+
+def default(args):
+    return get_case_docs(args)
+
+
+def get_case_docs(args):
+    try:
+        case_name = args['case_name']
+    except KeyError:
+        return result_handler(consts.API_ERROR, 'case_name must be provided')
+
+    docs_path = os.path.join(consts.DOCS_DIR, '{}.rst'.format(case_name))
+
+    if not os.path.exists(docs_path):
+        return result_handler(consts.API_ERROR, 'case not exists')
+
+    LOG.info('Reading %s', case_name)
+    with open(docs_path) as f:
+        content = f.read()
+
+    return result_handler(consts.API_SUCCESS, {'docs': content})
index b9ddd4c..13c6c76 100644 (file)
@@ -17,6 +17,7 @@ urlpatterns = [
     Url('/yardstick/testcases', views.Testcases, 'testcases'),
     Url('/yardstick/testcases/release/action', views.ReleaseAction, 'release'),
     Url('/yardstick/testcases/samples/action', views.SamplesAction, 'samples'),
+    Url('/yardstick/testcases/<case_name>/docs', views.CaseDocs, 'casedocs'),
     Url('/yardstick/testsuites/action', views.TestsuitesAction, 'testsuites'),
     Url('/yardstick/results', views.Results, 'results'),
     Url('/yardstick/env/action', views.EnvAction, 'env')
index 9fd236f..9c9ca4e 100644 (file)
@@ -74,3 +74,9 @@ class EnvAction(ApiResource):
 
     def post(self):
         return self._dispatch_post()
+
+
+class CaseDocs(ApiResource):
+
+    def get(self, case_name):
+        return self._dispatch_get(case_name=case_name)
index d445e86..d251341 100644 (file)
@@ -39,6 +39,7 @@ ANSIBLE_DIR = join(REPOS_DIR, 'ansible')
 SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
 TESTCASE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_cases/')
 TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
+DOCS_DIR = join(REPOS_DIR, 'docs/testing/user/userguide/')
 
 # file
 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')