diff options
author | hongbo tian <hongbo.tianhongbo@huawei.com> | 2016-12-28 03:08:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-12-28 03:08:49 +0000 |
commit | d8a21638b012c5036ac1303d5fe055a73d8ff1b7 (patch) | |
tree | 47ba537cecd0ee5634bb2b9daa5720587801ccb6 | |
parent | 5eb35fabf62a8b17089fdf4608d00ef0c55c8cfa (diff) | |
parent | 352bd08bce665e41c23dfce930b315533d39df0b (diff) |
Merge "dovetail tool: reorganize function prepare_cmd in testcase.py"
-rw-r--r-- | dovetail/test_runner.py | 6 | ||||
-rw-r--r-- | dovetail/testcase.py | 48 |
2 files changed, 26 insertions, 28 deletions
diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index 70dd2345..8315380a 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -49,9 +49,9 @@ class DockerRunner(object): if not failed: self.testcase.prepared(True) - if not self.testcase.prepare_cmd(): + if not self.testcase.prepare_cmd(self.type): self.logger.error('failed to prepare testcase:%s', - self.testcase.name) + self.testcase.name()) else: for cmd in self.testcase.cmds: ret, msg = Container.exec_cmd(container_id, cmd) @@ -112,7 +112,7 @@ class ShellRunner(object): if not failed: self.testcase.prepared(True) - if not self.testcase.prepare_cmd(): + if not self.testcase.prepare_cmd(self.type): self.logger.error('failed to prepare cmd:%s', self.testcase.name()) else: diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 040c6f98..47b0f071 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -32,21 +32,31 @@ class Testcase(object): def create_log(cls): cls.logger = dt_logger.Logger(__name__ + '.Testcase').getLogger() - def prepare_cmd(self): - try: - for cmd in self.testcase['validate']['cmds']: - cmd_lines = Parser.parse_cmd(cmd, self) - if not cmd_lines: - return False - # self.logger.debug('cmd_lines:%s', cmd_lines) - self.cmds.append(cmd_lines) - self.logger.debug('cmds:%s', self.cmds) - if len(self.cmds) > 0: - return True - else: + def parse_cmd(self, cmds_list): + for cmd in cmds_list: + cmd_lines = Parser.parse_cmd(cmd, self) + if not cmd_lines: return False + # self.logger.debug('cmd_lines:%s', cmd_lines) + self.cmds.append(cmd_lines) + self.logger.debug('cmds:%s', self.cmds) + return True + + def prepare_cmd(self, test_type): + try: + testcase_cmds = self.testcase['validate']['cmds'] except KeyError: - return False + testcase_cmds = None + try: + config_cmds = dt_cfg.dovetail_config[test_type]['cmds'] + except KeyError: + config_cmds = None + if testcase_cmds: + return self.parse_cmd(testcase_cmds) + if config_cmds: + return self.parse_cmd(config_cmds) + self.logger.error('testcase %s has no cmds', self.name()) + return False def __str__(self): return self.testcase @@ -205,18 +215,6 @@ class FunctestTestcase(Testcase): super(FunctestTestcase, self).__init__(testcase_yaml) self.type = 'functest' - def prepare_cmd(self): - ret = super(FunctestTestcase, self).prepare_cmd() - if not ret: - for cmd in \ - dt_cfg.dovetail_config[self.name]['cmds']: - cmd_lines = Parser.parse_cmd(cmd, self) - if not cmd_lines: - return False - self.logger.debug('cmd_lines:%s', cmd_lines) - self.cmds.append(cmd_lines) - return True - class YardstickTestcase(Testcase): |