Merge "fix pep8 problem in env.py"
[yardstick.git] / api / resources / v2 / testcases.py
index ca88e98..0edbf62 100644 (file)
@@ -10,6 +10,8 @@ import logging
 import errno
 import os
 
+import jinja2schema
+
 from api import ApiResource
 from yardstick.common.utils import result_handler
 from yardstick.common import constants as consts
@@ -25,7 +27,7 @@ class V2Testcases(ApiResource):
     def get(self):
         param = Param({})
         testcase_list = Testcase().list_all(param)
-        return result_handler(consts.API_SUCCESS, testcase_list)
+        return result_handler(consts.API_SUCCESS, {'testcases': testcase_list})
 
     def post(self):
         return self._dispatch_post()
@@ -56,7 +58,16 @@ class V2Testcase(ApiResource):
             if e.errno == errno.ENOENT:
                 return result_handler(consts.API_ERROR, 'case does not exist')
 
-        return result_handler(consts.API_SUCCESS, {'testcase': data})
+        options = {k: {'description': '', 'type': v.__class__.__name__}
+                   for k, v in jinja2schema.infer(data).items()}
+        # [('segmentation_id', < scalar >), ('image', < string >), ('provider', < scalar >),
+        # ('physical_network', < string >), ('packetsize', < number >)]
+        for k, v in options.items():
+            if k == 'segmentation_id':
+                options[k]['type'] = 'Number'
+            if k == 'provider':
+                options[k]['type'] = 'String'
+        return result_handler(consts.API_SUCCESS, {'testcase': data, 'args': options})
 
     def delete(self, case_name):
         case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))