diff options
author | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2016-12-22 17:27:37 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-12-22 17:41:39 -0500 |
commit | f53fc46aa732e3b29991b3e5e39da31a722945ee (patch) | |
tree | a301733aa9991b58b218f61b187240d275e44968 /tests/cloud_tests/config.py | |
parent | b2a9f33616c806ae6e052520a8589113308f567c (diff) | |
download | vyos-cloud-init-f53fc46aa732e3b29991b3e5e39da31a722945ee.tar.gz vyos-cloud-init-f53fc46aa732e3b29991b3e5e39da31a722945ee.zip |
integration test: initial commit of integration test framework
The adds in end-to-end testing of cloud-init. The framework utilizes
LXD and cloud images as a backend to test user-data passed in.
Arbitrary data is then captured from predefined commands specified
by the user. After collection, data verification is completed by
running a series of Python unit tests against the collected data.
Currently only the Ubuntu Trusty, Xenial, Yakkety, and Zesty
releases are supported. Test cases for 50% of the modules is
complete and available.
Additionally a Read the Docs file was created to guide test
writing and execution.
Diffstat (limited to 'tests/cloud_tests/config.py')
-rw-r--r-- | tests/cloud_tests/config.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/cloud_tests/config.py b/tests/cloud_tests/config.py new file mode 100644 index 00000000..f3a13c9a --- /dev/null +++ b/tests/cloud_tests/config.py @@ -0,0 +1,113 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +import glob +import os + +from cloudinit import util as c_util +from tests.cloud_tests import (BASE_DIR, TEST_CONF_DIR) + +# conf files +CONF_EXT = '.yaml' +VERIFY_EXT = '.py' +PLATFORM_CONF = os.path.join(BASE_DIR, 'platforms.yaml') +RELEASES_CONF = os.path.join(BASE_DIR, 'releases.yaml') +TESTCASE_CONF = os.path.join(BASE_DIR, 'testcases.yaml') + + +def path_to_name(path): + """ + convert abs or rel path to test config to path under configs/ + if already a test name, do nothing + """ + dir_path, file_name = os.path.split(os.path.normpath(path)) + name = os.path.splitext(file_name)[0] + return os.sep.join((os.path.basename(dir_path), name)) + + +def name_to_path(name): + """ + convert test config path under configs/ to full config path, + if already a full path, do nothing + """ + name = os.path.normpath(name) + if not name.endswith(CONF_EXT): + name = name + CONF_EXT + return name if os.path.isabs(name) else os.path.join(TEST_CONF_DIR, name) + + +def name_sanatize(name): + """ + sanatize test name to be used as a module name + """ + return name.replace('-', '_') + + +def name_to_module(name): + """ + convert test name to a loadable module name under testcases/ + """ + name = name_sanatize(path_to_name(name)) + return name.replace(os.path.sep, '.') + + +def merge_config(base, override): + """ + merge config and base + """ + res = base.copy() + res.update(override) + res.update({k: merge_config(base.get(k, {}), v) + for k, v in override.items() if isinstance(v, dict)}) + return res + + +def load_platform_config(platform): + """ + load configuration for platform + """ + main_conf = c_util.read_conf(PLATFORM_CONF) + return merge_config(main_conf.get('default_platform_config'), + main_conf.get('platforms')[platform]) + + +def load_os_config(os_name): + """ + load configuration for os + """ + main_conf = c_util.read_conf(RELEASES_CONF) + return merge_config(main_conf.get('default_release_config'), + main_conf.get('releases')[os_name]) + + +def load_test_config(path): + """ + load a test config file by either abs path or rel path + """ + return merge_config(c_util.read_conf(TESTCASE_CONF)['base_test_data'], + c_util.read_conf(name_to_path(path))) + + +def list_enabled_platforms(): + """ + list all platforms enabled for testing + """ + platforms = c_util.read_conf(PLATFORM_CONF).get('platforms') + return [k for k, v in platforms.items() if v.get('enabled')] + + +def list_enabled_distros(): + """ + list all distros enabled for testing + """ + releases = c_util.read_conf(RELEASES_CONF).get('releases') + return [k for k, v in releases.items() if v.get('enabled')] + + +def list_test_configs(): + """ + list all available test config files by abspath + """ + return [os.path.abspath(f) for f in + glob.glob(os.sep.join((TEST_CONF_DIR, '*', '*.yaml')))] + +# vi: ts=4 expandtab |