Merge "tc006: fio job_file.ini the volume should be configed"
[yardstick.git] / yardstick / cmd / commands / testcase.py
index cb76c7a..a151871 100644 (file)
 ##############################################################################
 
 """ Handler for yardstick command 'testcase' """
-import os
-import yaml
-import sys
+from __future__ import print_function
+from __future__ import absolute_import
 
-from yardstick.cmd import print_hbar
-from yardstick.common.task_template import TaskTemplate
+from yardstick.benchmark.core.testcase import Testcase
+from yardstick.benchmark.core import print_hbar
 from yardstick.common.utils import cliargs
-from yardstick.definitions import YARDSTICK_ROOT_PATH
+from yardstick.cmd.commands import change_osloobj_to_paras
+from yardstick.cmd.commands import Commands
 
 
-class TestcaseCommands(object):
-    '''Testcase commands.
+class TestcaseCommands(Commands):
+    """Testcase commands.
 
        Set of commands to discover and display test cases.
-    '''
-    def __init__(self):
-        self.test_case_path = YARDSTICK_ROOT_PATH + 'tests/opnfv/test_cases/'
-        self.testcase_list = []
+    """
 
     def do_list(self, args):
-        '''List existing test cases'''
-
-        try:
-            testcase_files = os.listdir(self.test_case_path)
-        except Exception as e:
-            print(("Failed to list dir:\n%(path)s\n%(err)s\n")
-                  % {"path": self.test_case_path, "err": e})
-            raise e
-        testcase_files.sort()
-
-        for testcase_file in testcase_files:
-            record = self._get_record(testcase_file)
-            self.testcase_list.append(record)
-
-        self._format_print(self.testcase_list)
-        return True
+        """List existing test cases"""
+        testcase_list = self.client.get('/yardstick/testcases')['result']
+        self._format_print(testcase_list)
 
     @cliargs("casename", type=str, help="test case name", nargs=1)
     def do_show(self, args):
-        '''Show details of a specific test case'''
-        testcase_name = args.casename[0]
-        testcase_path = self.test_case_path + testcase_name + ".yaml"
-        try:
-            with open(testcase_path) as f:
-                try:
-                    testcase_info = f.read()
-                    print testcase_info
-
-                except Exception as e:
-                    print(("Failed to load test cases:"
-                           "\n%(testcase_file)s\n%(err)s\n")
-                          % {"testcase_file": testcase_path, "err": e})
-                    raise e
-        except IOError as ioerror:
-            sys.exit(ioerror)
-        return True
-
-    def _get_record(self, testcase_file):
-
-        try:
-            with open(self.test_case_path + testcase_file) as f:
-                try:
-                    testcase_info = f.read()
-                except Exception as e:
-                    print(("Failed to load test cases:"
-                           "\n%(testcase_file)s\n%(err)s\n")
-                          % {"testcase_file": testcase_file, "err": e})
-                    raise e
-                description, installer, deploy_scenarios = \
-                    self._parse_testcase(testcase_info)
-
-                record = {'Name': testcase_file.split(".")[0],
-                          'Description': description,
-                          'installer': installer,
-                          'deploy_scenarios': deploy_scenarios}
-                return record
-        except IOError as ioerror:
-            sys.exit(ioerror)
-
-    def _parse_testcase(self, testcase_info):
-
-        kw = {}
-        rendered_testcase = TaskTemplate.render(testcase_info, **kw)
-        testcase_cfg = yaml.load(rendered_testcase)
-        test_precondition = testcase_cfg.get('precondition', None)
-        installer_type = 'all'
-        deploy_scenarios = 'all'
-        if test_precondition is not None:
-            installer_type = test_precondition.get('installer_type', 'all')
-            deploy_scenarios = test_precondition.get('deploy_scenarios', 'all')
-
-        description = testcase_info.split("\n")[2][1:].strip()
-        return description, installer_type, deploy_scenarios
+        """Show details of a specific test case"""
+        param = change_osloobj_to_paras(args)
+        Testcase().show(param)
 
     def _format_print(self, testcase_list):
-        '''format output'''
+        """format output"""
 
         print_hbar(88)
         print("| %-21s | %-60s" % ("Testcase Name", "Description"))
         print_hbar(88)
         for testcase_record in testcase_list:
-            print "| %-16s | %-60s" % (testcase_record['Name'],
-                                       testcase_record['Description'])
+            print("| %-16s | %-60s" % (testcase_record['Name'],
+                                       testcase_record['Description']))
         print_hbar(88)