From 39942dc9c5bc152a6ed20534755cc0dc38d85ede Mon Sep 17 00:00:00 2001 From: Leo Wang Date: Thu, 22 Sep 2016 21:56:54 -0400 Subject: Use template to unify commands in functest/yardstick JIRA: DOVETAIL-19 1. use jinja2 to unify commands in config files 2. it simplify the process of test execution, put the dissimilarity in config 3. add precondition/postcondition for functest/yardstick config Change-Id: Ib996b11ea065b61910b34b78191bb7b1ffd92e59 Signed-off-by: Leo Wang --- scripts/testcase.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'scripts/testcase.py') diff --git a/scripts/testcase.py b/scripts/testcase.py index 71ffd7ac..4deabe2e 100644 --- a/scripts/testcase.py +++ b/scripts/testcase.py @@ -7,9 +7,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 # +import jinja2 + import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils +from parser import * + logger = dt_logger.Logger('testcase.py').getLogger() from conf.dovetail_config import * @@ -19,9 +23,19 @@ class Testcase: def __init__(self, testcase_yaml): self.testcase = testcase_yaml.values()[0] self.testcase['passed'] = False + self.cmds = [] self.sub_testcase_status = {} Testcase.update_script_testcase(self.script_type(), self.script_testcase()) + def prepare_cmd(self): + for cmd in dovetail_config[self.script_type()]['testcase']['cmds']: + cmd_lines = Parser.parse_cmd(cmd,self) + if not cmd_lines: + return False + self.cmds.append(cmd_lines) + + return True + def __str__(self): return self.testcase @@ -63,16 +77,45 @@ class Testcase: def script_result_acquired(self, acquired=None): return Testcase._result_acquired(self.script_type(), self.script_testcase(), acquired) + def pre_condition(self): + return Testcase.pre_condition(self.script_type()) + + def post_condition(self): + return Testcase.post_condition(self.script_type()) + + #testcase in upstream testing project script_testcase_list = {'functest':{}, 'yardstick':{}} #testcase in dovetail testcase_list = {} + @classmethod + def prepared(cls, script_type, prepared=None): + if prepared is not None: + cls.script_testcase_list[script_type]['prepared'] = prepared + return cls.script_testcase_list[script_type]['prepared'] + + @classmethod + def cleaned(cls, script_type, cleaned=None): + if cleaned is not None: + cls.scrpit_testcase_list[script_type]['cleaned'] = cleaned + return cls.script_testcase_list[script_type]['cleaned'] + + @classmethod + def pre_condition(cls, script_type): + return dovetail_config[script_type]['pre_condition'] + + def post_condition(cls, script_type): + return dovetail_config[script_type]['post_condition'] + + @classmethod def update_script_testcase(cls,script_type, script_testcase): if script_testcase not in cls.script_testcase_list[script_type]: cls.script_testcase_list[script_type][script_testcase] = {'retry':0, 'acquired':False} + cls.script_testcase_list[script_type]['prepared'] = False + cls.script_testcase_list[script_type]['cleaned'] = False @classmethod def _exceed_max_retry_times(cls, script_type, script_testcase ): -- cgit 1.2.3-korg