From bf298f7dfa5de497ef3cd69aaea7218ed7559160 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 29 Jun 2017 03:38:04 +0000 Subject: Add API to show test case documentation JIRA: YARDSTICK-694 We need API to show test case documentation. API: /yardstick/testcases//docs method: GET example: http://192.168.131.2:8888/yardstick/testcases/opnfv_yardstick_tc002/docs Change-Id: Ib8d591f0ff5f91c4d0a740539727ec73ddd86249 Signed-off-by: chenjiankun --- api/resources/case_docs.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api/resources/case_docs.py (limited to 'api/resources') diff --git a/api/resources/case_docs.py b/api/resources/case_docs.py new file mode 100644 index 000000000..289410d2d --- /dev/null +++ b/api/resources/case_docs.py @@ -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}) -- cgit 1.2.3-korg