summaryrefslogtreecommitdiffstats
path: root/dovetail/run.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2016-12-02 08:58:16 +0000
committerxudan <xudan16@huawei.com>2016-12-14 02:43:19 +0000
commit05d995655dd07dfb72191c66e2c1c5177925dd5c (patch)
tree58eb529aae0ea084e983ebb293898b17ce0658e9 /dovetail/run.py
parent4cc82a8477e7b842e83281c72127a73da73edf1d (diff)
dovetail tool: improve cli to update non-envs automatically
1. modify cmd_config.yml a. change 'env' and 'non-env' into 'config' and 'control' b. add subsection 'path' for each block in 'config' c. delete 'DEPLOY_SCENARIO' and 'DEPLOY_TYPE' d. use 'func_tag' and 'yard_tag' to control container's tag 2. if cmd in config a. if its path is envs, it will be used to update envs in dovetail_config b. if its path is non_envs, it will be used to update other value in the dict JIRA: DOVETAIL-70 Change-Id: I1cf9bfcd1a19294a390a85bce6e458ce50672b7f Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/run.py')
-rwxr-xr-xdovetail/run.py106
1 files changed, 66 insertions, 40 deletions
diff --git a/dovetail/run.py b/dovetail/run.py
index 52a350e5..c0cc872c 100755
--- a/dovetail/run.py
+++ b/dovetail/run.py
@@ -9,8 +9,8 @@
import click
-import sys
import os
+import copy
import utils.dovetail_logger as dt_logger
import utils.dovetail_utils as dt_utils
@@ -31,14 +31,6 @@ def load_testsuite(testsuite):
return Testsuite.get(testsuite)
-def set_container_tags(option_str):
- for script_tag_opt in option_str.split(','):
- option_str = script_tag_opt.split(':')
- validate_type = option_str[0].strip()
- script_tag = option_str[1].strip()
- dt_cfg.dovetail_config[validate_type]['docker_tag'] = script_tag
-
-
def load_testcase():
Testcase.load()
@@ -74,23 +66,56 @@ def run_test(testsuite, testarea, logger):
return duration
-def validate_options(input_dict, logger):
- # for 'tag' option
- for key, value in input_dict.items():
- if key == 'tag' and value is not None:
- for tag in value.split(','):
- if len(tag.split(':')) != 2:
- logger.error('TAGS option must be "<image>:<tag>,..."')
- sys.exit(1)
-
-
-def filter_env_options(input_dict):
- envs_options = {}
- for key, value in input_dict.items():
- key = key.upper()
- if key in dt_cfg.dovetail_config['cli']['options']['envs']:
- envs_options[key] = value
- return envs_options
+def validate_input(input_dict, check_dict, logger):
+ # for 'func_tag' and 'yard_tag' options
+ func_tag = input_dict['func_tag']
+ yard_tag = input_dict['yard_tag']
+ valid_tag = check_dict['valid_docker_tag']
+ if func_tag is not None and func_tag not in valid_tag:
+ logger.error("func_tag can't be %s, valid in %s", func_tag, valid_tag)
+ raise SystemExit(1)
+ if yard_tag is not None and yard_tag not in valid_tag:
+ logger.error("yard_tag can't be %s, valid in %s", yard_tag, valid_tag)
+ raise SystemExit(1)
+
+ # for 'SUT_TYPE' option
+ sut_type = input_dict['sut_type']
+ valid_type = check_dict['valid_sut_type']
+ if sut_type is not None and sut_type not in valid_type:
+ logger.error("SUT_TYPE can't be %s, valid in %s", sut_type, valid_type)
+ raise SystemExit(1)
+
+
+def filter_config(input_dict, logger):
+ cli_dict = dt_cfg.dovetail_config['cli']
+ configs = {}
+ for key in cli_dict:
+ if not cli_dict[key]:
+ continue
+ try:
+ cli_config = cli_dict[key]['config']
+ if cli_config is None:
+ continue
+ except KeyError:
+ continue
+ for key, value in input_dict.items():
+ for config_key, config_value in cli_config.items():
+ value_dict = {}
+ value_dict['value'] = value
+ try:
+ value_dict['path'] = config_value['path']
+ if key == config_key:
+ configs[key] = value_dict
+ break
+ if key.upper() == config_key:
+ configs[key.upper()] = value_dict
+ break
+ except KeyError as e:
+ logger.exception('%s lacks subsection %s', config_key, e)
+ raise SystemExit(1)
+ if not configs:
+ return None
+ return configs
def create_logs():
@@ -115,7 +140,7 @@ def clean_results_dir():
dt_utils.exec_cmd(cmd, exit_on_error=False)
else:
print "result_dir in dovetail_config.yml is not a directory."
- sys.exit(-1)
+ raise SystemExit(1)
def main(*args, **kwargs):
@@ -128,17 +153,16 @@ def main(*args, **kwargs):
logger.info('================================================')
logger.info('Dovetail compliance: %s!' % (kwargs['testsuite']))
logger.info('================================================')
- validate_options(kwargs, logger)
- envs_options = filter_env_options(kwargs)
- dt_cfg.update_envs(envs_options)
+ validate_input(kwargs, dt_cfg.dovetail_config['validate_input'], logger)
+ configs = filter_config(kwargs, logger)
+
+ if configs is not None:
+ dt_cfg.update_config(configs)
logger.info('Your new envs for functest: %s' %
dt_cfg.dovetail_config['functest']['envs'])
logger.info('Your new envs for yardstick: %s' %
dt_cfg.dovetail_config['yardstick']['envs'])
- if 'tag' in kwargs and kwargs['tag'] is not None:
- set_container_tags(kwargs['tag'])
-
testarea = kwargs['testarea']
testsuite_validation = False
testarea_validation = False
@@ -158,21 +182,23 @@ def main(*args, **kwargs):
dt_cfg.load_config_files()
-
+dovetail_config = copy.deepcopy(dt_cfg.dovetail_config)
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
-if dt_cfg.dovetail_config['cli']['options'] is not None:
- for key, value in dt_cfg.dovetail_config['cli']['options'].items():
+if dovetail_config['cli']['options'] is not None:
+ for key, value in dovetail_config['cli']['options'].items():
if value is not None:
for k, v in value.items():
flags = v['flags']
- del v['flags']
+ v.pop('flags')
+ v.pop('path', None)
main = click.option(*flags, **v)(main)
-if dt_cfg.dovetail_config['cli']['arguments'] is not None:
- for key, value in dt_cfg.dovetail_config['cli']['arguments'].items():
+if dovetail_config['cli']['arguments'] is not None:
+ for key, value in dovetail_config['cli']['arguments'].items():
if value is not None:
for k, v in value.items():
flags = v['flags']
- del v['flags']
+ v.pop('flags')
+ v.pop('path', None)
main = click.argument(flags, **v)(main)
main = click.command(context_settings=CONTEXT_SETTINGS)(main)