diff options
Diffstat (limited to 'dovetail')
-rw-r--r-- | dovetail/prepare_env.py | 40 | ||||
-rw-r--r-- | dovetail/tests/__init__.py | 0 | ||||
-rw-r--r-- | dovetail/tests/unit/__init__.py | 0 | ||||
-rw-r--r-- | dovetail/tests/unit/test_parser.py | 57 | ||||
-rw-r--r-- | dovetail/tests/unit/test_testcase.yaml | 10 |
5 files changed, 106 insertions, 1 deletions
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/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 |