summaryrefslogtreecommitdiffstats
path: root/dovetail
diff options
context:
space:
mode:
Diffstat (limited to 'dovetail')
-rw-r--r--dovetail/conf/cmd_config.yml45
-rw-r--r--dovetail/conf/dovetail_config.py36
-rw-r--r--dovetail/conf/dovetail_config.yml1
-rw-r--r--dovetail/conf/functest_config.yml4
-rw-r--r--dovetail/container.py10
-rw-r--r--dovetail/prepare_env.py40
-rw-r--r--dovetail/report.py8
-rwxr-xr-xdovetail/run.py44
-rw-r--r--dovetail/tests/__init__.py0
-rw-r--r--dovetail/tests/unit/__init__.py0
-rw-r--r--dovetail/tests/unit/test_parser.py57
-rw-r--r--dovetail/tests/unit/test_testcase.yaml10
12 files changed, 233 insertions, 22 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/conf/functest_config.yml b/dovetail/conf/functest_config.yml
index cd33dc59..ef2b7fb8 100644
--- a/dovetail/conf/functest_config.yml
+++ b/dovetail/conf/functest_config.yml
@@ -5,14 +5,10 @@ functest:
-e NODE_NAME=dovetail-pod -e DEPLOY_SCENARIO=ha_nosdn
-e BUILD_TAG=dovetail -e CI_DEBUG=true -e DEPLOY_TYPE=baremetal'
opts: '-id --privileged=true'
- result_dir: '/home/opnfv/functest/results'
pre_condition:
cmds:
- 'echo test for precondition'
testcase:
- pre_cmd: 'python /home/opnfv/repos/functest/ci/prepare_env.py start'
- exec_cmd: 'python /home/opnfv/repos/functest/ci/run_tests.py -t {{script_testcase}} -r'
- post_cmd: ''
cmds:
- 'python /home/opnfv/repos/functest/ci/prepare_env.py start'
- 'python /home/opnfv/repos/functest/ci/run_tests.py -t {{script_testcase}} -r'
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/prepare_env.py b/dovetail/prepare_env.py
index 785d5c3d..3e4d6964 100644
--- a/dovetail/prepare_env.py
+++ b/dovetail/prepare_env.py
@@ -7,13 +7,51 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
+import platform
import utils.dovetail_logger as dt_logger
import utils.dovetail_utils as dt_utils
+def get_os():
+ """Get distro name.
+
+ :returns: return distro name as a string
+ """
+ return platform.dist()[0]
+
+
+def get_install_bin(os):
+ """Get install command binary.
+
+ :returns: return install command according to distro
+ """
+ if os in ['centos', 'redhat']:
+ return 'yum'
+ elif os == 'fedora':
+ return 'dnf'
+ elif os == 'ubuntu':
+ return 'apt-get'
+ else:
+ return None
+
+
+def get_docker_pkgname(os):
+ """Get docker package name.
+
+ :returns: return docker package name according to distro
+ """
+ if os in ['centos', 'fedora', 'redhat']:
+ return 'docker'
+ elif os == 'ubuntu':
+ return 'docker.io'
+ else:
+ return None
+
logger = dt_logger.Logger('prepare_env.py').getLogger()
-cmd = "sudo apt-get -y install docker.io python-pip"
+os_name = get_os()
+cmd = "sudo %s -y install %s python-pip" \
+ % (get_install_bin(os_name), get_docker_pkgname(os_name))
dt_utils.exec_cmd(cmd, logger)
cmd = "sudo pip install click pyyaml jinja2"
diff --git a/dovetail/report.py b/dovetail/report.py
index c937011f..9ea90231 100644
--- a/dovetail/report.py
+++ b/dovetail/report.py
@@ -64,14 +64,14 @@ class Report:
# save to disk as default
@classmethod
def save(cls, report):
- report_file_path = dovetail_config['report_file']
+ report_file_name = dovetail_config['report_file']
try:
with open(os.path.join(dovetail_config['result_dir'],
- report_file_path), 'w') as report_file:
+ report_file_name), 'w') as report_file:
report_file.write(report)
- logger.info('save report to %s' % report_file_path)
+ logger.info('save report to %s' % report_file_name)
except Exception:
- logger.error('Failed to save: %s' % report_file_path)
+ logger.error('Failed to save: %s' % report_file_name)
@classmethod
def get_result(cls, testcase):
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()
diff --git a/dovetail/tests/__init__.py b/dovetail/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dovetail/tests/__init__.py
diff --git a/dovetail/tests/unit/__init__.py b/dovetail/tests/unit/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dovetail/tests/unit/__init__.py
diff --git a/dovetail/tests/unit/test_parser.py b/dovetail/tests/unit/test_parser.py
new file mode 100644
index 00000000..5b003d1a
--- /dev/null
+++ b/dovetail/tests/unit/test_parser.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+#
+# lingui.zeng@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
+#
+"""
+Test 'parser' module
+
+"""
+
+import logging
+import os
+import unittest
+
+import yaml
+
+import dovetail.parser as dovetail_parser
+
+
+class TestParser(unittest.TestCase):
+
+ test_path = os.path.dirname(os.path.realpath(__file__))
+
+ def setUp(self):
+ """Test case setup"""
+ logging.disable(logging.CRITICAL)
+
+ def test_parser_cmd(self):
+ """Test whether the command is correctly parsed."""
+ mock_cmd = "python /functest/ci/run_tests.py -t {{script_testcase}} -r"
+ with open(os.path.join(self.test_path, 'test_testcase.yaml')) as f:
+ mock_testcase_yaml = yaml.safe_load(f)
+ MockTestcase = type('Testcase', (object,), {})
+ mock_testcase = MockTestcase()
+ mock_testcase.testcase = mock_testcase_yaml.values()[0]
+ output = dovetail_parser.Parser.parse_cmd(mock_cmd, mock_testcase)
+ expected_output = ("python /functest/ci/run_tests.py -t "
+ "tempest_smoke_serial -r")
+ self.assertEqual(expected_output, output)
+
+ def test_parser_cmd_fail(self):
+ """Test whether the command is correctly parsed."""
+ mock_cmd = "python /functest/ci/run_tests.py -t {{script_testcase}} -r"
+ mock_testcase_yaml = {}
+ MockTestcase = type('Testcase', (object,), {})
+ mock_testcase = MockTestcase()
+ mock_testcase.testcase = mock_testcase_yaml.values()
+ output = dovetail_parser.Parser.parse_cmd(mock_cmd, mock_testcase)
+ expected_output = ("python /functest/ci/run_tests.py -t "
+ "None -r")
+ self.assertEqual(expected_output, output)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/dovetail/tests/unit/test_testcase.yaml b/dovetail/tests/unit/test_testcase.yaml
new file mode 100644
index 00000000..1b03262f
--- /dev/null
+++ b/dovetail/tests/unit/test_testcase.yaml
@@ -0,0 +1,10 @@
+dovetail.ipv6.tc001:
+ name: dovetail.ipv6.tc001
+ objective: VIM ipv6 operations, to create/delete network, port and subnet in bulk operation
+ scripts:
+ type: functest
+ testcase: tempest_smoke_serial
+ sub_testcase_list:
+ - tempest.api.network.test_networks.BulkNetworkOpsIpV6Test.test_bulk_create_delete_network
+ - tempest.api.network.test_networks.BulkNetworkOpsIpV7Test.test_bulk_create_delete_port
+ - tempest.api.network.test_networks.BulkNetworkOpsIpV6Test.test_bulk_create_delete_subnet