diff options
-rw-r--r-- | docker/Dockerfile.centos7 | 19 | ||||
-rw-r--r-- | docs/dovetailtool/dovetail.tool.installation.rst | 19 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.py | 7 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.yml | 12 | ||||
-rw-r--r-- | dovetail/container.py | 11 | ||||
-rw-r--r-- | dovetail/parser.py | 4 | ||||
-rw-r--r-- | dovetail/report.py | 5 | ||||
-rwxr-xr-x | dovetail/run.py | 29 | ||||
-rw-r--r-- | dovetail/testcase.py | 14 | ||||
-rw-r--r-- | dovetail/tests/unit/test_parser.py | 5 | ||||
-rw-r--r-- | dovetail/utils/dovetail_logger.py | 4 | ||||
-rwxr-xr-x | unittests/unittest.sh | 22 |
12 files changed, 110 insertions, 41 deletions
diff --git a/docker/Dockerfile.centos7 b/docker/Dockerfile.centos7 new file mode 100644 index 00000000..965c535b --- /dev/null +++ b/docker/Dockerfile.centos7 @@ -0,0 +1,19 @@ +FROM centos:centos7 +MAINTAINER Tomofumi Hayashi <tohayash@redhat.com> +LABEL version="0.1" description="OPNFV Dovetail Docker Container" + +ARG BRANCH=master + +RUN yum update -y && yum install -y sudo iproute epel-release && \ + yum install -y python-pip git && \ + pip install pyyaml click jinja2 + +ENV HOME /home/opnfv +ENV REPOS_DIR ${HOME}/dovetail +WORKDIR /home/opnfv + +RUN git config --global http.sslVerify false && \ + git clone --depth 1 -b $BRANCH https://gerrit.opnfv.org/gerrit/dovetail.git ${REPOS_DIR} && \ + mkdir -p ${REPOS_DIR}/results + +WORKDIR ${REPOS_DIR}/dovetail diff --git a/docs/dovetailtool/dovetail.tool.installation.rst b/docs/dovetailtool/dovetail.tool.installation.rst index 2f544480..3c145059 100644 --- a/docs/dovetailtool/dovetail.tool.installation.rst +++ b/docs/dovetailtool/dovetail.tool.installation.rst @@ -101,6 +101,22 @@ testarea ``ipv6`` in ``compliance_set`` python run.py --testsuite compliance_set --testarea ipv6 +Dovetail provides some sets, ``debug``, ``proposed_tests`` and ``compliance_set``, +``debug`` is used for locally and Continuous Integration(CI) developing purpose, +which provides typical testcase examples, feel free to edit it when develops locally, such as +only to run a testcase which only takes minutes. ``proposed_tests`` is the testcase +candidate which mainly comes from the wiki link +https://wiki.opnfv.org/display/dovetail/Dovetail+Test+Areas+and+Test+Cases. +``compliance_set`` is used for compliance. Moreover, dovetail tool can be easily +extended to support more complicated compliance requirements, +such as feature set based or scenario based compliance. + +If you want to run ``debug``, just run with + +:: + + python run.py --testsuite debug + Running Dovetail in a Docker container ######################################## @@ -115,6 +131,9 @@ Pull Dovetail Docker image from public Dockerhub <Tag> here is the version, 'latest' is used for the master branch. +As an alternative way, you can build own docker image from Dockfile(s) under ``docker/`` directory, +``Dockerfile`` is based on ubuntu system and ``Dockerfile.centos7`` is for centos7. + Dovetail Docker container creation ---------------------------------- diff --git a/dovetail/conf/dovetail_config.py b/dovetail/conf/dovetail_config.py index 452ed6de..d812c5c9 100644 --- a/dovetail/conf/dovetail_config.py +++ b/dovetail/conf/dovetail_config.py @@ -14,13 +14,6 @@ import re class DovetailConfig: - COMPLIANCE_PATH = './compliance/' - TESTCASE_PATH = './testcase/' - # testsuite supported tuple, should adjust accordingly - testsuite_supported = ('compliance_set', 'proposed_tests', 'debug') - # testarea supported tuple, should adjust accordingly - testarea_supported = ('vimops', 'nfvi', 'ipv6') - dovetail_config = {} CMD_NAME_TRANS = { diff --git a/dovetail/conf/dovetail_config.yml b/dovetail/conf/dovetail_config.yml index c4131a91..be2d075d 100644 --- a/dovetail/conf/dovetail_config.yml +++ b/dovetail/conf/dovetail_config.yml @@ -5,6 +5,18 @@ report_file: 'dovetail_report.txt' cli_file_name: 'cmd_config.yml' # TO DO: once version scheme settled, adjust accordingly repo: 'https://github.com/opnfv/dovetail/tree/master/' +COMPLIANCE_PATH: ./compliance/ +TESTCASE_PATH: ./testcase/ +# testsuite supported, should adjust accordingly +testsuite_supported: + - compliance_set + - proposed_tests + - debug +# testarea supported, should adjust accordingly +testarea_supported: + - vimops + - nfvi + - ipv6 # 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 2716a089..6174e313 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -10,7 +10,7 @@ import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils -from conf.dovetail_config import DovetailConfig as dt_config +from conf.dovetail_config import DovetailConfig as dt_cfg class Container: @@ -36,17 +36,16 @@ class Container: @staticmethod def get_docker_image(type): - return '%s:%s' % (dt_config.dovetail_config[type]['image_name'], - dt_config.dovetail_config[type]['docker_tag']) + return '%s:%s' % (dt_cfg.dovetail_config[type]['image_name'], + dt_cfg.dovetail_config[type]['docker_tag']) @classmethod def create(cls, type): - # sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa " - dovetail_config = dt_config.dovetail_config + sshkey = "-v /root/.ssh/id_rsa:/root/.ssh/id_rsa " + dovetail_config = dt_cfg.dovetail_config docker_image = cls.get_docker_image(type) envs = dovetail_config[type]['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' % \ diff --git a/dovetail/parser.py b/dovetail/parser.py index d8f9fa0a..44cb7fcb 100644 --- a/dovetail/parser.py +++ b/dovetail/parser.py @@ -12,7 +12,7 @@ import jinja2 import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils -from conf.dovetail_config import DovetailConfig as dt_config +from conf.dovetail_config import DovetailConfig as dt_cfg class Parser: @@ -30,7 +30,7 @@ class Parser: try: template = jinja2.Template(cmd, undefined=jinja2.StrictUndefined) kwargs = {} - for arg in dt_config.dovetail_config['parameters']: + for arg in dt_cfg.dovetail_config['parameters']: path = eval(arg['path']) cls.logger.debug('name: %s, eval path: %s ' % (arg['name'], path)) diff --git a/dovetail/report.py b/dovetail/report.py index 7fd4076d..a58c560f 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -106,7 +106,7 @@ class Report: sub_report = {} testcase_num = {} testcase_passnum = {} - for area in dt_cfg.testarea_supported: + for area in dt_cfg.dovetail_config['testarea_supported']: sub_report[area] = '' testcase_num[area] = 0 testcase_passnum[area] = 0 @@ -114,7 +114,8 @@ class Report: # TO DO: once version scheme settled, adjust accordingly spec_link = dt_cfg.dovetail_config['repo'] + 'dovetail/testcase' for testcase in report_data['testcases_list']: - pattern = re.compile('|'.join(dt_cfg.testarea_supported)) + pattern = re.compile( + '|'.join(dt_cfg.dovetail_config['testarea_supported'])) area = pattern.findall(testcase['name'])[0] result_dir = dt_cfg.dovetail_config['result_dir'] sub_report[area] += '- <%s> %s result: <%s>\n' %\ diff --git a/dovetail/run.py b/dovetail/run.py index 17f476b6..d9bc0aaa 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -23,7 +23,7 @@ from testcase import Testsuite from report import Report from report import FunctestCrawler, YardstickCrawler from report import FunctestChecker, YardstickChecker -from conf.dovetail_config import DovetailConfig as dt_config +from conf.dovetail_config import DovetailConfig as dt_cfg def load_testsuite(testsuite): @@ -36,7 +36,7 @@ def set_container_tags(option_str): option_str = script_tag_opt.split(':') script_type = option_str[0].strip() script_tag = option_str[1].strip() - dt_config.dovetail_config[script_type]['docker_tag'] = script_tag + dt_cfg.dovetail_config[script_type]['docker_tag'] = script_tag def load_testcase(): @@ -110,7 +110,7 @@ def filter_env_options(input_dict): envs_options = {} for key, value in input_dict.items(): key = key.upper() - if key in dt_config.dovetail_config['cli']['options']['envs']: + if key in dt_cfg.dovetail_config['cli']['options']['envs']: envs_options[key] = value return envs_options @@ -128,7 +128,7 @@ def create_logs(): def clean_results_dir(): - result_path = dt_config.dovetail_config['result_dir'] + result_path = dt_cfg.dovetail_config['result_dir'] if os.path.exists(result_path): if os.path.isdir(result_path): cmd = 'sudo rm -rf %s/*' % (result_path) @@ -150,11 +150,11 @@ def main(*args, **kwargs): logger.info('================================================') validate_options(kwargs, logger) envs_options = filter_env_options(kwargs) - dt_config.update_envs(envs_options) + dt_cfg.update_envs(envs_options) logger.info('Your new envs for functest: %s' % - dt_config.dovetail_config['functest']['envs']) + dt_cfg.dovetail_config['functest']['envs']) logger.info('Your new envs for yardstick: %s' % - dt_config.dovetail_config['yardstick']['envs']) + dt_cfg.dovetail_config['yardstick']['envs']) if 'tag' in kwargs and kwargs['tag'] is not None: set_container_tags(kwargs['tag']) @@ -162,9 +162,10 @@ def main(*args, **kwargs): testarea = kwargs['testarea'] testsuite_validation = False testarea_validation = False - if (testarea == 'full') or (testarea in dt_config.testarea_supported): + if (testarea == 'full') or \ + (testarea in dt_cfg.dovetail_config['testarea_supported']): testarea_validation = True - if kwargs['testsuite'] in dt_config.testsuite_supported: + if kwargs['testsuite'] in dt_cfg.dovetail_config['testsuite_supported']: testsuite_validation = True if testsuite_validation and testarea_validation: testsuite_yaml = load_testsuite(kwargs['testsuite']) @@ -176,18 +177,18 @@ def main(*args, **kwargs): (kwargs['testsuite'], testarea)) -dt_config.load_config_files() +dt_cfg.load_config_files() CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) -if dt_config.dovetail_config['cli']['options'] is not None: - for key, value in dt_config.dovetail_config['cli']['options'].items(): +if dt_cfg.dovetail_config['cli']['options'] is not None: + for key, value in dt_cfg.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 dt_config.dovetail_config['cli']['arguments'] is not None: - for key, value in dt_config.dovetail_config['cli']['arguments'].items(): +if dt_cfg.dovetail_config['cli']['arguments'] is not None: + for key, value in dt_cfg.dovetail_config['cli']['arguments'].items(): if value is not None: for k, v in value.items(): flags = v['flags'] diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 60ce2b28..77669ce1 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -13,7 +13,7 @@ import yaml import utils.dovetail_logger as dt_logger from parser import Parser -from conf.dovetail_config import DovetailConfig as dt_config +from conf.dovetail_config import DovetailConfig as dt_cfg class Testcase: @@ -34,7 +34,7 @@ class Testcase: def prepare_cmd(self): script_type = self.script_type() - for cmd in dt_config.dovetail_config[script_type]['testcase']['cmds']: + for cmd in dt_cfg.dovetail_config[script_type]['testcase']['cmds']: cmd_lines = Parser.parse_cmd(cmd, self) if not cmd_lines: return False @@ -111,11 +111,11 @@ class Testcase: @staticmethod def pre_condition_cls(script_type): - return dt_config.dovetail_config[script_type]['pre_condition'] + return dt_cfg.dovetail_config[script_type]['pre_condition'] @staticmethod def post_condition_cls(script_type): - return dt_config.dovetail_config[script_type]['post_condition'] + return dt_cfg.dovetail_config[script_type]['post_condition'] @classmethod def update_script_testcase(cls, script_type, script_testcase): @@ -144,7 +144,8 @@ class Testcase: @classmethod def load(cls): - for root, dirs, files in os.walk(dt_config.TESTCASE_PATH): + for root, dirs, files in \ + os.walk(dt_cfg.dovetail_config['TESTCASE_PATH']): for testcase_file in files: with open(os.path.join(root, testcase_file)) as f: testcase_yaml = yaml.safe_load(f) @@ -180,7 +181,8 @@ class Testsuite: @classmethod def load(cls): - for root, dirs, files in os.walk(dt_config.COMPLIANCE_PATH): + for root, dirs, files in \ + os.walk(dt_cfg.dovetail_config['COMPLIANCE_PATH']): for testsuite_yaml in files: with open(os.path.join(root, testsuite_yaml)) as f: testsuite_yaml = yaml.safe_load(f) diff --git a/dovetail/tests/unit/test_parser.py b/dovetail/tests/unit/test_parser.py index b4331ea1..8d32995c 100644 --- a/dovetail/tests/unit/test_parser.py +++ b/dovetail/tests/unit/test_parser.py @@ -14,7 +14,6 @@ Test 'parser' module import logging import os import unittest - import yaml import parser as dovetail_parser @@ -26,8 +25,10 @@ class TestParser(unittest.TestCase): def setUp(self): """Test case setup""" - logging.disable(logging.CRITICAL) + from conf.dovetail_config import DovetailConfig as dt_cfg + dt_cfg.load_config_files() dovetail_parser.Parser.create_log() + logging.disable(logging.CRITICAL) def test_parser_cmd(self): """Test whether the command is correctly parsed.""" diff --git a/dovetail/utils/dovetail_logger.py b/dovetail/utils/dovetail_logger.py index 8afa08a1..bb09a7b1 100644 --- a/dovetail/utils/dovetail_logger.py +++ b/dovetail/utils/dovetail_logger.py @@ -24,7 +24,7 @@ import logging import os -from conf.dovetail_config import DovetailConfig as dt_config +from conf.dovetail_config import DovetailConfig as dt_cfg class Logger: @@ -46,7 +46,7 @@ class Logger: ch.setLevel(logging.INFO) self.logger.addHandler(ch) - result_path = dt_config.dovetail_config['result_dir'] + result_path = dt_cfg.dovetail_config['result_dir'] if not os.path.exists(result_path): os.makedirs(result_path) hdlr = logging.FileHandler(os.path.join(result_path, 'dovetail.log')) diff --git a/unittests/unittest.sh b/unittests/unittest.sh index 1560a90d..215d0ebd 100755 --- a/unittests/unittest.sh +++ b/unittests/unittest.sh @@ -35,4 +35,26 @@ run_flake8() { fi } +run_tests() { + echo "Running unittest ..." + cd dovetail/ + if [ $FILE_OPTION == "f" ]; then + python -m unittest discover -v -s tests/unit > $logfile 2>&1 + else + python -m unittest discover -v -s tests/unit + fi + + if [ $? -ne 0 ]; then + if [ $FILE_OPTION == "f" ]; then + echo "FAILED, results in $logfile" + fi + exit 1 + else + if [ $FILE_OPTION == "f" ]; then + echo "OK, results in $logfile" + fi + fi +} + run_flake8 +run_tests |