diff options
-rw-r--r-- | dovetail/conf/cmd_config.yml | 45 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.py | 36 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.yml | 1 | ||||
-rw-r--r-- | dovetail/container.py | 10 | ||||
-rwxr-xr-x | dovetail/run.py | 44 |
5 files changed, 123 insertions, 13 deletions
diff --git a/dovetail/conf/cmd_config.yml b/dovetail/conf/cmd_config.yml new file mode 100644 index 00000000..63d51ed0 --- /dev/null +++ b/dovetail/conf/cmd_config.yml @@ -0,0 +1,45 @@ +cli: + arguments: + envs: + # This is a simple example of arguments. + # Dovetail has no need of this kind of parameters currently. + # The arguments must be given orderly at the run-time. + # + # docker_tag: + # flags: 'docker_tag' + non-envs: + + options: + envs: + SUT_TYPE: + flags: + - '--SUT_TYPE' + - '-t' + help: 'Installer type of the system under test (SUT).' + SUT_IP: + flags: + - '--SUT_IP' + - '-i' + help: 'IP of the system under test (SUT).' + DEPLOY_SCENARIO: + flags: + - '--DEPLOY_SCENARIO' + - '-S' + help: 'DEPLOY_SCENARIO of the system under test (SUT).' + DEPLOY_TYPE: + flags: + - '--DEPLOY_TYPE' + - '-T' + help: 'DEPLOY_TYPE of the system under test (SUT).' + CI_DEBUG: + flags: + - '--CI_DEBUG' + - '-d' + help: 'CI_DEBUG for showing debug log.' + non-envs: + scenario: + flags: + - '--scenario' + - '-s' + default: 'basic' + help: 'certification scenario.' diff --git a/dovetail/conf/dovetail_config.py b/dovetail/conf/dovetail_config.py index 6f3eebf2..03d0bb78 100644 --- a/dovetail/conf/dovetail_config.py +++ b/dovetail/conf/dovetail_config.py @@ -9,6 +9,7 @@ import yaml import os +import re CERT_PATH = './cert/' TESTCASE_PATH = './testcase/' @@ -27,3 +28,38 @@ container_config = {} container_config['functest'] = dovetail_config['functest'] container_config['yardstick'] = dovetail_config['yardstick'] + + +with open(os.path.join(curr_path, dovetail_config['cli_file_name'])) as f: + cmd_yml = yaml.safe_load(f) + dovetail_config['cli'] = cmd_yml[cmd_yml.keys()[0]] + + +def cmd_name_trans(cmd_name): + key = cmd_name.upper() + if key == 'SUT_TYPE': + key = 'INSTALLER_TYPE' + if key == 'SUT_IP': + key = 'INSTALLER_IP' + return key + + +def update_envs(options): + for item in options: + if options[item] is not None: + key = cmd_name_trans(item) + os.environ[key] = options[item] + update_config_envs('functest', key) + update_config_envs('yardstick', key) + + +def update_config_envs(script_type, key): + old_value = re.findall(r'\s+%s=(.*?)(\s+|$)' % key, + dovetail_config[script_type]['envs']) + if old_value == []: + dovetail_config[script_type]['envs'] += \ + ' -e ' + key + '=' + os.environ[key] + else: + dovetail_config[script_type]['envs'] = \ + dovetail_config[script_type]['envs'].replace(old_value[0][0], + os.environ[key]) diff --git a/dovetail/conf/dovetail_config.yml b/dovetail/conf/dovetail_config.yml index 901988f8..1f5de672 100644 --- a/dovetail/conf/dovetail_config.yml +++ b/dovetail/conf/dovetail_config.yml @@ -2,6 +2,7 @@ work_dir: /home/opnfv/dovetail result_dir: /home/opnfv/dovetail/results report_file: 'dovetail_report.txt' +cli_file_name: 'cmd_config.yml' # used for testcase cmd template in jinja2 format # we have two variables available now diff --git a/dovetail/container.py b/dovetail/container.py index 6ff3980d..6d7ac94d 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -import os + import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils from conf.dovetail_config import dovetail_config @@ -39,18 +39,12 @@ class Container: # sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa " docker_image = cls.get_docker_image(type) envs = dovetail_config[type]['envs'] - import re - for i in ['INSTALLER_TYPE', 'DEPLOY_SCENARIO', - 'DEPLOY_TYPE', 'CI_DEBUG']: - envs = re.sub("%s=(\w+)" % i, '%s=%s' % (i, os.getenv(i)), envs) - envs = re.sub("INSTALLER_IP=\d+\.?\d+\.?\d+\.?\d+", - 'INSTALLER_IP=' + os.getenv('INSTALLER_IP'), envs) opts = dovetail_config[type]['opts'] sshkey = '' result_volume = ' -v %s:%s ' % (dovetail_config['result_dir'], dovetail_config[type]['result']['dir']) cmd = 'sudo docker run %s %s %s %s %s /bin/bash' % \ - (opts, envs, sshkey, result_volume, docker_image) + (opts, envs, sshkey, result_volume, docker_image) dt_utils.exec_cmd(cmd, logger) ret, container_id = \ dt_utils.exec_cmd("sudo docker ps | grep " + docker_image + diff --git a/dovetail/run.py b/dovetail/run.py index ddeb3117..39dec07c 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -18,6 +18,8 @@ from testcase import Testcase from testcase import Scenario from report import Report from conf.dovetail_config import SCENARIO_NAMING_FMT +from conf.dovetail_config import dovetail_config +from conf.dovetail_config import update_envs logger = dt_logger.Logger('run.py').getLogger() @@ -69,17 +71,49 @@ def run_test(scenario): Report.check_result(testcase, db_result) -@click.command() -@click.option('--scenario', default='basic', help='certification scenario') -def main(scenario): +def filter_env_options(input_dict): + envs_options = {} + for key, value in input_dict.items(): + key = key.upper() + if key in dovetail_config['cli']['options']['envs']: + envs_options[key] = value + return envs_options + + +def main(*args, **kwargs): """Dovetail certification test entry!""" logger.info('=======================================') - logger.info('Dovetail certification: %s!' % scenario) + logger.info('Dovetail certification: %s!' % (kwargs['scenario'])) logger.info('=======================================') + envs_options = filter_env_options(kwargs) + update_envs(envs_options) + logger.info('Your new envs for functest: %s' % + dovetail_config['functest']['envs']) + logger.info('Your new envs for yardstick: %s' % + dovetail_config['yardstick']['envs']) load_testcase() - scenario_yaml = load_scenario(scenario) + scenario_yaml = load_scenario(kwargs['scenario']) run_test(scenario_yaml) Report.generate(scenario_yaml) + +CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) +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'] + main = click.option(*flags, **v)(main) +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'] + main = click.argument(flags, **v)(main) +main = click.command(context_settings=CONTEXT_SETTINGS)(main) + + if __name__ == '__main__': main() |