diff options
-rw-r--r-- | docs/dovetailtool/dovetail.tool.cli.rst | 180 | ||||
-rw-r--r-- | docs/dovetailtool/index.rst | 1 | ||||
-rw-r--r-- | dovetail/conf/cmd_config.yml | 6 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.yml | 4 | ||||
-rw-r--r-- | dovetail/conf/functest_config.yml | 1 | ||||
-rw-r--r-- | dovetail/conf/yardstick_config.yml | 1 | ||||
-rw-r--r-- | dovetail/container.py | 6 | ||||
-rw-r--r-- | dovetail/utils/dovetail_utils.py | 19 |
8 files changed, 216 insertions, 2 deletions
diff --git a/docs/dovetailtool/dovetail.tool.cli.rst b/docs/dovetailtool/dovetail.tool.cli.rst new file mode 100644 index 00000000..bdcf46e4 --- /dev/null +++ b/docs/dovetailtool/dovetail.tool.cli.rst @@ -0,0 +1,180 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International +.. License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) OPNFV, Huawei Technologies Co.,Ltd and others. + +Command Line Interface +====================== + +Dovetail supports modifying some parameters at the run-time by using the command +line interface (CLI). The parameters can be defined through a config file by +developers easily and then be used at the run-time. + +The CLI now fits all three kinds of running: directly running the python script, +running after setup and running within Docker containers. + +Define CLI with config file +--------------------------- + +For easy to be modified, Dovetail provides ``dovetail/dovetail/conf/cmd_config.yml`` +to define CLI automatically. + +:: + + cli: + arguments: + config: + # 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' + # path: + # - 'functest/docker_tag' + # - 'yardstick/docker_tag' + control: + + options: + config: + SUT_TYPE: + flags: + - '--SUT_TYPE' + - '-t' + path: + - 'functest/envs' + - 'yardstick/envs' + help: 'Installer type of the system under test (SUT).' + yard_tag: + flags: + - '--yard_tag' + - '-y' + path: + - 'yardstick/docker_tag' + help: 'Overwrite tag for yardstick docker container (e.g. stable or latest)' + func_tag: + flags: + - '--func_tag' + - '-f' + path: + - 'functest/docker_tag' + help: 'Overwrite tag for functest docker container (e.g. stable or latest)' + control: + testsuite: + flags: + - '--testsuite' + default: 'compliance_set' + help: 'compliance testsuite.' + testarea: + flags: + - '--testarea' + default: 'full' + help: 'compliance testarea within testsuite' + +Dovetail uses click module in python to parse parameters defined in the above +config file. The basic config file shown above contains two subsections: +**arguments** and **options** corresponding to two types of parameters in click. + +Add options ++++++++++++ + +Just as the name suggested, option parameters can either be given or not by users +after adding into CLI. + +Then how to add an option for developers? + +For each option, it at least needs a key **flags** to give its name. Customarily, +each option has two names, full name and short name, and they are begin with '--' +and '-' respectively. All other keys should be consistent with click's keys. + +Take option **scenario** as the example. Its full name is '--scenario', and its +short name is '-s'. Actually full name is necessary but short name is optional. +The full name '--scenario' should be the same with the block's name **scenario**. +**default** section gives the default value of this option if it doesn't given +by users. Without the **default** section, it will be set None. **help** section +offers its help message that will be shown when excute -h/--help command. For +more information about click, please refer to: http://click.pocoo.org/5/ + +Add arguments ++++++++++++++ + +Arguments must given orderly by users once they are defined in the config file. +The Dovetail tool doesn't need any argument parameters currently. However, here +just give a simple example for its format. + +Arguments also need subsection **flags** to give its name. Each argument can just +have one name, and the name should be the same with the key of this section. Other +keys should also be consistent with the click module. + +Config and control +++++++++++++++++++ + +All options/arguments are divided into two parts: **config** and **control**. +The config ones are used for updating functest or yardstick config files according +to the **path** given. For example, functest's config file is +``dovetail/dovetail/conf/functest_config.yml``, following is a simple example: + +:: + + docker_tag: latest + envs: '-e INSTALLER_TYPE=compass -e INSTALLER_IP=192.168.200.2 + -e NODE_NAME=dovetail-pod -e DEPLOY_SCENARIO=ha_nosdn + -e BUILD_TAG=dovetail -e CI_DEBUG=true -e DEPLOY_TYPE=baremetal' + +If running with the command ``python run.py --SUT_TYPE fuel -f stable``, then +the configs will be changed into + +:: + + docker_tag: stable + envs: '-e INSTALLER_TYPE=fuel -e INSTALLER_IP=192.168.200.2 + -e NODE_NAME=dovetail-pod -e DEPLOY_SCENARIO=ha_nosdn + -e BUILD_TAG=dovetail -e CI_DEBUG=true -e DEPLOY_TYPE=baremetal' + +The config options/arguments can be added or deleted just by modifying +``cmd_config.yml`` rather than changing the source code. However, for control +command, besides adding it into ``cmd_config.yml``, some other operations about +the source code are also needed. + +Run with CLI +------------ + +For users, they can use CLI to input their own envs at the run-time instead of +modifying the config files of functest or yardstick. So Dovetail can supports +different environments more flexible with CLI. Dovetail now can be run with three +methods, directly running ``run.py`` script, running after setup and running +in Docker containers. The uses of CLI are almost the same for these three methods +and here take the first one as the example. + +All parameters offered by Dovetail can be listed by using help option ``--help``. + +:: + + root@90256c4efd05:~/dovetail/dovetail$ python run.py --help + Usage: run.py [OPTIONS] + + Dovetail compliance test entry! + + Options: + -t, --SUT_TYPE TEXT Installer type of the system under test (SUT). + -f, --func_tag TEXT Overwrite tag for functest docker container (e.g. + stable or latest) + -i, --SUT_IP TEXT IP of the system under test (SUT). + -y, --yard_tag TEXT Overwrite tag for yardstick docker container (e.g. + stable or latest) + -d, --DEBUG TEXT DEBUG for showing debug log. + --testarea TEXT compliance testarea within testsuite + --testsuite TEXT compliance testsuite. + -h, --help Show this message and exit. + +All options listed can be used to input special environment values at the run-time. +For example: + +:: + + python run.py --SUT_TYPE compass -y stable + +There is no need to give all these options. If it is not given by CLI, it will +be set with the system's environment value. If it is not included in system's +environment variables, it will be set with the default value in functest/yardstick +config file. diff --git a/docs/dovetailtool/index.rst b/docs/dovetailtool/index.rst index 592fa564..676c72db 100644 --- a/docs/dovetailtool/index.rst +++ b/docs/dovetailtool/index.rst @@ -14,3 +14,4 @@ Dovetail Overview dovetail.tool.installation.rst dovetail.tool.configuration.rst dovetail.tool.configtemplate.rst + dovetail.tool.cli.rst diff --git a/dovetail/conf/cmd_config.yml b/dovetail/conf/cmd_config.yml index e2159ca7..1c6418cb 100644 --- a/dovetail/conf/cmd_config.yml +++ b/dovetail/conf/cmd_config.yml @@ -52,6 +52,12 @@ cli: path: - 'functest/docker_tag' help: 'Overwrite tag for functest docker container (e.g. stable or latest)' + creds: + flags: + - '--creds' + path: + - 'creds' + help: 'Openstack Credential file location' control: testsuite: flags: diff --git a/dovetail/conf/dovetail_config.yml b/dovetail/conf/dovetail_config.yml index c01394ed..837f8840 100644 --- a/dovetail/conf/dovetail_config.yml +++ b/dovetail/conf/dovetail_config.yml @@ -3,6 +3,10 @@ work_dir: /home/opnfv/dovetail result_dir: /home/opnfv/dovetail/results report_file: 'dovetail_report.txt' cli_file_name: 'cmd_config.yml' + +# OPENSTACK Credential file +creds: '/home/opnfv/dovetail/openstack.creds' + # TO DO: once version scheme settled, adjust accordingly repo: 'https://github.com/opnfv/dovetail/tree/master/' COMPLIANCE_PATH: ./compliance/ diff --git a/dovetail/conf/functest_config.yml b/dovetail/conf/functest_config.yml index 682d19bf..ceb894b3 100644 --- a/dovetail/conf/functest_config.yml +++ b/dovetail/conf/functest_config.yml @@ -17,3 +17,4 @@ functest: store_type: 'file' file_path: 'tempest/tempest.log' db_url: 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1' + creds: '/home/opnfv/functest/conf/openstack.creds' diff --git a/dovetail/conf/yardstick_config.yml b/dovetail/conf/yardstick_config.yml index d13cf2c6..d971c104 100644 --- a/dovetail/conf/yardstick_config.yml +++ b/dovetail/conf/yardstick_config.yml @@ -24,3 +24,4 @@ yardstick: store_type: 'file' file_path: 'yardstick.log' db_url: 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1' + creds: '/home/opnfv/yardstick/openstack.creds' diff --git a/dovetail/container.py b/dovetail/container.py index 948dce93..62070442 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -46,10 +46,12 @@ class Container: docker_image = cls.get_docker_image(type) envs = dovetail_config[type]['envs'] opts = dovetail_config[type]['opts'] + creds = ' -v %s:%s ' % (dovetail_config['creds'], + dovetail_config[type]['creds']) 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) + cmd = 'sudo docker run %s %s %s %s %s %s /bin/bash' % \ + (opts, envs, sshkey, creds, result_volume, docker_image) dt_utils.exec_cmd(cmd, cls.logger) ret, container_id = \ dt_utils.exec_cmd("sudo docker ps | grep " + docker_image + diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index e4f91987..2d5f0dd1 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -10,6 +10,7 @@ # import sys +import time import subprocess from collections import Mapping, Set, Sequence @@ -29,6 +30,15 @@ def exec_cmd(cmd, logger=None, exit_on_error=True, info=False, print(msg_exec) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + # show progress bar + seconds = 0 + while p.poll() is None: + seconds += 1 + if seconds > 3: + show_progress_bar(seconds) + time.sleep(1) + output = p.communicate() for line in output[0].strip().split('\n'): line = line.replace('\n', '') @@ -89,3 +99,12 @@ def get_obj_by_path(obj, dst_path): for path, obj in objwalk(obj): if path == dst_path: return obj + + +def show_progress_bar(length): + max_len = 50 + length %= max_len + sys.stdout.write('Running ' + ' ' * max_len + '\r') + sys.stdout.flush() + sys.stdout.write('Running ' + '=' * length + '>' + '\r') + sys.stdout.flush() |