add "yardstick testcase show" command function 59/11659/3
authorrexlee8776 <limingjiang@huawei.com>
Mon, 28 Mar 2016 08:35:56 +0000 (04:35 -0400)
committerqi liang <liangqi1@huawei.com>
Fri, 1 Apr 2016 03:16:12 +0000 (03:16 +0000)
"yardstick testcase show" will show the details of specific test case

yardstick testcase show <case-name> (e.g. yardstick testcase show opnfv_yardstick_tc001)

JIRA:-

Change-Id: Ibb91625dc3e6802855f28160ee0aa8c7e386cf7a
Signed-off-by: rexlee8776 <limingjiang@huawei.com>
tests/unit/cmd/commands/test_testcase.py
yardstick/cmd/commands/testcase.py

index 351e5e7..c55c367 100644 (file)
@@ -17,6 +17,10 @@ import unittest
 from yardstick.cmd.commands import testcase
 from yardstick.cmd.commands.testcase import TestcaseCommands
 
+class Arg(object):
+    def __init__(self):
+        self.casename=('opnfv_yardstick_tc001',)
+
 class TestcaseCommandsUT(unittest.TestCase):
 
     def test_do_list(self):
@@ -24,4 +28,9 @@ class TestcaseCommandsUT(unittest.TestCase):
         result = t.do_list("")
         self.assertEqual(result, True)
 
+    def test_do_show(self):
+        t = testcase.TestcaseCommands()
+        casename = Arg()
+        result = t.do_show(casename)
+        self.assertEqual(result, True)
 
index c37fcc2..5205eb9 100644 (file)
@@ -10,6 +10,7 @@
 """ Handler for yardstick command 'testcase' """
 from yardstick.cmd import print_hbar
 from yardstick.common.task_template import TaskTemplate
+from yardstick.common.utils import cliargs
 import os
 import yaml
 import sys
@@ -42,6 +43,26 @@ class TestcaseCommands(object):
         self._format_print(self.testcase_list)
         return True
 
+    @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: