summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkubi <jean.gaoliang@huawei.com>2016-03-26 16:55:00 +0800
committerkubi <jean.gaoliang@huawei.com>2016-03-26 17:00:18 +0800
commitcfde1fac2c062ca45d2816e6830b611abd8a61d0 (patch)
treeb79c1ce87177d0b3d5c363f4051560a225d1a714
parente587b562bb2094a0e08bbdb25cff408e667ebe71 (diff)
add "yardstick testcase list" command function
"yardstick testcase list" will list test cases info(Name, Description) in tests/OPNFV/test_cases/ Change-Id: Icf2e6a803d90d33012f009519e47e750bfd57489 JIRA:- Signed-off-by: kubi <jean.gaoliang@huawei.com>
-rw-r--r--tests/unit/cmd/commands/test_testcase.py27
-rw-r--r--yardstick/cmd/cli.py4
-rw-r--r--yardstick/cmd/commands/testcase.py91
3 files changed, 121 insertions, 1 deletions
diff --git a/tests/unit/cmd/commands/test_testcase.py b/tests/unit/cmd/commands/test_testcase.py
new file mode 100644
index 000000000..351e5e79f
--- /dev/null
+++ b/tests/unit/cmd/commands/test_testcase.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.cmd.commands.testcase
+
+import mock
+import unittest
+
+from yardstick.cmd.commands import testcase
+from yardstick.cmd.commands.testcase import TestcaseCommands
+
+class TestcaseCommandsUT(unittest.TestCase):
+
+ def test_do_list(self):
+ t = testcase.TestcaseCommands()
+ result = t.do_list("")
+ self.assertEqual(result, True)
+
+
diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py
index 8d75d7d5e..a7ba04f57 100644
--- a/yardstick/cmd/cli.py
+++ b/yardstick/cmd/cli.py
@@ -22,6 +22,7 @@ from oslo_config import cfg
from yardstick.cmd.commands import task
from yardstick.cmd.commands import runner
from yardstick.cmd.commands import scenario
+from yardstick.cmd.commands import testcase
CONF = cfg.CONF
cli_opts = [
@@ -58,7 +59,8 @@ class YardstickCLI():
categories = {
'task': task.TaskCommands,
'runner': runner.RunnerCommands,
- 'scenario': scenario.ScenarioCommands
+ 'scenario': scenario.ScenarioCommands,
+ 'testcase': testcase.TestcaseCommands
}
def __init__(self):
diff --git a/yardstick/cmd/commands/testcase.py b/yardstick/cmd/commands/testcase.py
new file mode 100644
index 000000000..c37fcc214
--- /dev/null
+++ b/yardstick/cmd/commands/testcase.py
@@ -0,0 +1,91 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+""" Handler for yardstick command 'testcase' """
+from yardstick.cmd import print_hbar
+from yardstick.common.task_template import TaskTemplate
+import os
+import yaml
+import sys
+
+
+class TestcaseCommands(object):
+ '''Testcase commands.
+
+ Set of commands to discover and display test cases.
+ '''
+ def __init__(self):
+ self.test_case_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
+
+ 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
+
+ def _format_print(self, testcase_list):
+ '''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_hbar(88)