summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2016-12-21 02:41:09 +0000
committerxudan <xudan16@huawei.com>2016-12-26 09:20:34 +0000
commit352bd08bce665e41c23dfce930b315533d39df0b (patch)
treecb449c9a14b69404d45b0c49afb21e7f1f382cd3
parentf87b8d9136682c9617449bb8595230c074c5d8e3 (diff)
dovetail tool: reorganize function prepare_cmd in testcase.py
1. move the common statements in prepare_cmd of class FunctestTestcase and Testcase into parse_cmd. JIRA: DOVETAIL-163 Change-Id: I61a0a24b47cfc9e8d49ca9c62fafbac7cce21111 Signed-off-by: xudan <xudan16@huawei.com>
-rw-r--r--dovetail/test_runner.py6
-rw-r--r--dovetail/testcase.py48
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):