From 1c0f19209637572d0bd50c1a3691bc18ee6fb9ee Mon Sep 17 00:00:00 2001 From: Leo Wang Date: Tue, 29 Nov 2016 04:21:40 -0500 Subject: [dovetail tool] support shell scripts for testcase validation JIRA: DOVETAIL-46 1. for now a testcase has two kinds of validation types(functest, yardstick), and it is not enough to check the complete funcionality 2. add new validation type(shell) for extra validation of the test case to make result more accurate and more convincing. Change-Id: I45dca6b8dbd888757da163189d261f6e4dba5034 Signed-off-by: Leo Wang --- dovetail/test_runner.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 dovetail/test_runner.py (limited to 'dovetail/test_runner.py') diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py new file mode 100644 index 00000000..bc0e4679 --- /dev/null +++ b/dovetail/test_runner.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# +# grakiss.wanglei@huawei.com +# 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 +# + +import utils.dovetail_utils as dt_utils +import utils.dovetail_logger as dt_logger + +from container import Container + + +class DockerRunner(object): + + logger = None + + def __init__(self, testcase): + self.testcase = testcase + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__file__).getLogger() + + def run(self): + Container.pull_image(self.testcase.validate_type()) + container_id = Container.create(self.testcase.validate_type()) + self.logger.debug('container id:%s' % container_id) + + if not self.testcase.prepared(): + cmds = self.testcase.pre_condition() + if cmds: + for cmd in cmds: + Container.exec_cmd(container_id, cmd) + self.testcase.prepared(True) + + if not self.testcase.prepare_cmd(): + self.logger.error('failed to prepare testcase:%s', + self.testcase.name()) + else: + for cmd in self.testcase.cmds: + Container.exec_cmd(container_id, cmd) + + cmds = self.testcase.post_condition() + if cmds: + for cmd in cmds: + Container.exec_cmd(container_id, cmd) + self.testcase.cleaned(True) + + Container.clean(container_id) + + +class FunctestRunner(DockerRunner): + + def __init__(self, testcase): + super(FunctestRunner, self).__init__(testcase) + self.name = 'functest' + + +class YardstickRunner(DockerRunner): + + def __init__(self, testcase): + super(YardstickRunner, self).__init__(testcase) + self.name = 'yardstick' + + +class ShellRunner(object): + + logger = None + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__file__).getLogger() + + def __init__(self, testcase): + super(ShellRunner, self).__init__() + self.testcase = testcase + self.name = 'shell' + + def run(self): + for cmd in self.testcase.cmds: + dt_utils.exec_cmd(cmd, self.logger) + + +class TestRunnerFactory(object): + + TEST_RUNNER_MAP = { + "functest": FunctestRunner, + "yardstick": YardstickRunner, + "shell": ShellRunner, + } + + @classmethod + def create(cls, testcase): + try: + return cls.TEST_RUNNER_MAP[testcase.validate_type()](testcase) + except KeyError: + return None -- cgit 1.2.3-korg