summaryrefslogtreecommitdiffstats
path: root/scripts/run.py
diff options
context:
space:
mode:
authorLeo Wang <grakiss.wanglei@huawei.com>2016-09-17 23:15:18 -0400
committerLeo Wang <grakiss.wanglei@huawei.com>2016-09-20 02:39:46 -0400
commitcb55f6dbfe4867e4d232f51b5a32764f82d2399b (patch)
tree54cf76d8595b33f744e3e069b7daa55688d3d097 /scripts/run.py
parente7316237cc9f5b469c53682af6f57099d42a3279 (diff)
add prototype of dovetail tool
JIRA: DOVETAIL-12 Change-Id: I1ee120ed8199589e1e7cbce9cbb55036e9e5f7ea Signed-off-by: Leo Wang <grakiss.wanglei@huawei.com>
Diffstat (limited to 'scripts/run.py')
-rwxr-xr-xscripts/run.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/scripts/run.py b/scripts/run.py
new file mode 100755
index 00000000..a8ef819c
--- /dev/null
+++ b/scripts/run.py
@@ -0,0 +1,99 @@
+#!/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 click
+import yaml
+import os
+import time
+
+import utils.dovetail_logger as dt_logger
+import utils.dovetail_utils as dt_utils
+logger = dt_logger.Logger('run.py').getLogger()
+
+from container import Container
+from testcase import *
+from report import *
+from conf.dovetail_config import *
+
+def load_scenario(scenario):
+ Scenario.load()
+ return Scenario.get(SCENARIO_NAMING_FMT % scenario)
+
+def load_testcase():
+ Testcase.load()
+
+def copy_file(file_dir, container_id, container_dir):
+ for root, dirs, files in os.walk(file_dir):
+ for file_name in files:
+ cmd = 'sudo docker cp %s %s:%s' % (os.path.join(file_dir,file_name), container_id, container_dir)
+ dt_utils.exec_cmd(cmd, logger, exit_on_error = False)
+
+def run_functest(testcase, container_id):
+ sub_cmd = dovetail_config[testcase.script_type()]['testcase']['pre_cmd']
+ Container.exec_cmd(container_id, sub_cmd)
+ sub_cmd = dovetail_config[testcase.script_type()]['testcase']['exec_cmd'] % testcase.script_testcase()
+ Container.exec_cmd(container_id, sub_cmd)
+
+def run_yardstick(testcase, container_id):
+ copy_file(os.path.join(os.getcwd(),container_config[testcase.script_type()]['shell_dir_name']),\
+ container_id,container_config[testcase.script_type()]['shell_dir'])
+ if container_config[testcase.script_type()]['has_build_images'] == True:
+ cmd = 'sudo docker exec %s %s/run_test.sh %s.yaml %s/%s.out' \
+ % (container_id, container_config[testcase.script_type()]['shell_dir'], testcase.script_testcase(),\
+ container_config[testcase.script_type()]['result_dir'], testcase.name())
+ else:
+ container_config[testcase.script_type()]['has_build_images'] = True
+ cmd = 'sudo docker exec %s %s/build_run_test.sh %s.yaml %s/%s.out' \
+ % (container_id, container_config[testcase.script_type()]['shell_dir'], testcase.script_testcase(),\
+ container_config[testcase.script_type()]['result_dir'], testcase.name())
+ dt_utils.exec_cmd(cmd,logger,exit_on_error = False)
+ time.sleep(5)
+
+def run_test(scenario):
+ for testcase_name in scenario['testcase_list']:
+ logger.info('>>[testcase]: %s' % (testcase_name))
+ testcase = Testcase.get(testcase_name)
+ run_test = True
+
+ if testcase.exceed_max_retry_times():
+ run_test = False
+
+ if testcase.script_result_acquired():
+ run_test = False
+
+ if run_test:
+ Container.pull_image(testcase.script_type())
+ container_id = Container.create(testcase.script_type())
+ logger.debug('container id:%s' % container_id)
+
+ if testcase.script_type() == 'functest':
+ run_functest(testcase, container_id)
+ else:
+ run_yardstick(testcase, container_id)
+
+ Container.clean(container_id)
+
+ db_result = Report.get_result(testcase)
+ Report.check_result(testcase, db_result)
+
+@click.command()
+@click.option('--scenario', default='basic', help='certification scenario')
+def main(scenario):
+ """Dovetail certification test entry!"""
+ logger.info('=======================================')
+ logger.info('Dovetail certification: %s!' % scenario)
+ logger.info('=======================================')
+ load_testcase()
+ scenario_yaml = load_scenario(scenario)
+ run_test(scenario_yaml)
+ Report.generate(scenario_yaml)
+
+if __name__ == '__main__':
+ main()