From 423a206606c64552314263177f687671ffacb27a Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 20 Jul 2017 03:46:17 +0000 Subject: Add API(v2) to get certain test case info JIRA: YARDSTICK-744 API: /api/v2/yardstick/testcases METHOD: GET Change-Id: I4b1867f713bce2f9f2342ecec8540b08b0bb3456 Signed-off-by: chenjiankun --- api/resources/v2/testcases.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'api') diff --git a/api/resources/v2/testcases.py b/api/resources/v2/testcases.py index 3277b4c43..a14543c66 100644 --- a/api/resources/v2/testcases.py +++ b/api/resources/v2/testcases.py @@ -1,4 +1,5 @@ import logging +import errno import os from api import ApiResource @@ -33,3 +34,18 @@ class V2Testcases(ApiResource): upload_file.save(case_name) return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename}) + + +class V2Testcase(ApiResource): + + def get(self, case_name): + case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name)) + + try: + with open(case_path) as f: + data = f.read() + except IOError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'case does not exist') + + return result_handler(consts.API_SUCCESS, {'testcase': data}) -- cgit 1.2.3-korg