diff options
author | Wesley Wiedenmeier <wesley.wiedenmeier@gmail.com> | 2017-06-08 18:23:31 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-06-08 18:24:17 -0400 |
commit | 76d58265e34851b78e952a7f275340863c90a9f5 (patch) | |
tree | 91bf17879724b180e43bff07e428bb9089cbb395 /tests/cloud_tests/platforms | |
parent | ad2680a689ab78847ccce7766d6591797d99e219 (diff) | |
download | vyos-cloud-init-76d58265e34851b78e952a7f275340863c90a9f5.tar.gz vyos-cloud-init-76d58265e34851b78e952a7f275340863c90a9f5.zip |
Integration Testing: tox env, pyxld 2.2.3, and revamp framework
Massive update to clean up and greatly enhance the integration testing
framework developed by Wesley Wiedenmeier.
- Updated tox environment to run integration test 'citest' to utilize
pylxd 2.2.3
- Add support for distro feature flags
- add framework for feature flags to release config with feature groups
and overrides allowed in any release conf override level
- add support for feature flags in platform and config handling
- during collect, skip testcases that require features not supported by
the image with a warning message
- Enable additional distros (i.e. centos, debian)
- Add 'bddeb' command to build a deb from the current working tree
cleanly in a container, so deps do not have to be installed on host
- Adds a command line option '--preserve-data' that ensures that
collected data will be left after tests run. This also allows the
directory to store collected data in during the run command to be
specified using '--data-dir'.
- Updated Read the Docs testing page and doc strings for pep 257
compliance
Diffstat (limited to 'tests/cloud_tests/platforms')
-rw-r--r-- | tests/cloud_tests/platforms/__init__.py | 6 | ||||
-rw-r--r-- | tests/cloud_tests/platforms/base.py | 44 | ||||
-rw-r--r-- | tests/cloud_tests/platforms/lxd.py | 97 |
3 files changed, 66 insertions, 81 deletions
diff --git a/tests/cloud_tests/platforms/__init__.py b/tests/cloud_tests/platforms/__init__.py index f9f56035..443f6d44 100644 --- a/tests/cloud_tests/platforms/__init__.py +++ b/tests/cloud_tests/platforms/__init__.py @@ -1,5 +1,7 @@ # This file is part of cloud-init. See LICENSE file for license information. +"""Main init.""" + from tests.cloud_tests.platforms import lxd PLATFORMS = { @@ -8,9 +10,7 @@ PLATFORMS = { def get_platform(platform_name, config): - """ - Get the platform object for 'platform_name' and init - """ + """Get the platform object for 'platform_name' and init.""" platform_cls = PLATFORMS.get(platform_name) if not platform_cls: raise ValueError('invalid platform name: {}'.format(platform_name)) diff --git a/tests/cloud_tests/platforms/base.py b/tests/cloud_tests/platforms/base.py index 615e2e06..28975368 100644 --- a/tests/cloud_tests/platforms/base.py +++ b/tests/cloud_tests/platforms/base.py @@ -1,53 +1,27 @@ # This file is part of cloud-init. See LICENSE file for license information. +"""Base platform class.""" + class Platform(object): - """ - Base class for platforms - """ + """Base class for platforms.""" + platform_name = None def __init__(self, config): - """ - Set up platform - """ + """Set up platform.""" self.config = config def get_image(self, img_conf): - """ - Get image using 'img_conf', where img_conf is a dict containing all - image configuration parameters - - in this dict there must be a 'platform_ident' key containing - configuration for identifying each image on a per platform basis - - see implementations for get_image() for details about the contents - of the platform's config entry + """Get image using specified image configuration. - note: see 'releases' main_config.yaml for example entries - - img_conf: configuration for image - return_value: cloud_tests.images instance + @param img_conf: configuration for image + @return_value: cloud_tests.images instance """ raise NotImplementedError def destroy(self): - """ - Clean up platform data - """ + """Clean up platform data.""" pass - def _extract_img_platform_config(self, img_conf): - """ - extract platform configuration for current platform from img_conf - """ - platform_ident = img_conf.get('platform_ident') - if not platform_ident: - raise ValueError('invalid img_conf, missing \'platform_ident\'') - ident = platform_ident.get(self.platform_name) - if not ident: - raise ValueError('img_conf: {} missing config for platform {}' - .format(img_conf, self.platform_name)) - return ident - # vi: ts=4 expandtab diff --git a/tests/cloud_tests/platforms/lxd.py b/tests/cloud_tests/platforms/lxd.py index 847cc549..ead0955b 100644 --- a/tests/cloud_tests/platforms/lxd.py +++ b/tests/cloud_tests/platforms/lxd.py @@ -1,5 +1,7 @@ # This file is part of cloud-init. See LICENSE file for license information. +"""Base LXD platform.""" + from pylxd import (Client, exceptions) from tests.cloud_tests.images import lxd as lxd_image @@ -11,48 +13,49 @@ DEFAULT_SSTREAMS_SERVER = "https://images.linuxcontainers.org:8443" class LXDPlatform(base.Platform): - """ - Lxd test platform - """ + """LXD test platform.""" + platform_name = 'lxd' def __init__(self, config): - """ - Set up platform - """ + """Set up platform.""" super(LXDPlatform, self).__init__(config) # TODO: allow configuration of remote lxd host via env variables # set up lxd connection self.client = Client() def get_image(self, img_conf): + """Get image using specified image configuration. + + @param img_conf: configuration for image + @return_value: cloud_tests.images instance """ - Get image - img_conf: dict containing config for image. platform_ident must have: - alias: alias to use for simplestreams server - sstreams_server: simplestreams server to use, or None for default - return_value: cloud_tests.images instance - """ - lxd_conf = self._extract_img_platform_config(img_conf) - image = self.client.images.create_from_simplestreams( - lxd_conf.get('sstreams_server', DEFAULT_SSTREAMS_SERVER), - lxd_conf['alias']) - return lxd_image.LXDImage( - image.properties['description'], img_conf, self, image) - - def launch_container(self, image=None, container=None, ephemeral=False, - config=None, block=True, - image_desc=None, use_desc=None): - """ - launch a container - image: image fingerprint to launch from - container: container to copy - ephemeral: delete image after first shutdown - config: config options for instance as dict - block: wait until container created - image_desc: description of image being launched - use_desc: description of container's use - return_value: cloud_tests.instances instance + pylxd_image = self.client.images.create_from_simplestreams( + img_conf.get('sstreams_server', DEFAULT_SSTREAMS_SERVER), + img_conf['alias']) + image = lxd_image.LXDImage(self, img_conf, pylxd_image) + if img_conf.get('override_templates', False): + image.update_templates(self.config.get('template_overrides', {}), + self.config.get('template_files', {})) + return image + + def launch_container(self, properties, config, features, + image=None, container=None, ephemeral=False, + container_config=None, block=True, image_desc=None, + use_desc=None): + """Launch a container. + + @param properties: image properties + @param config: image configuration + @param features: image features + @param image: image fingerprint to launch from + @param container: container to copy + @param ephemeral: delete image after first shutdown + @param container_config: config options for instance as dict + @param block: wait until container created + @param image_desc: description of image being launched + @param use_desc: description of container's use + @return_value: cloud_tests.instances instance """ if not (image or container): raise ValueError("either image or container must be specified") @@ -61,16 +64,18 @@ class LXDPlatform(base.Platform): use_desc=use_desc, used_list=self.list_containers()), 'ephemeral': bool(ephemeral), - 'config': config if isinstance(config, dict) else {}, + 'config': (container_config + if isinstance(container_config, dict) else {}), 'source': ({'type': 'image', 'fingerprint': image} if image else {'type': 'copy', 'source': container}) }, wait=block) - return lxd_instance.LXDInstance(container.name, self, container) + return lxd_instance.LXDInstance(self, container.name, properties, + config, features, container) def container_exists(self, container_name): - """ - check if container with name 'container_name' exists - return_value: True if exists else False + """Check if container with name 'container_name' exists. + + @return_value: True if exists else False """ res = True try: @@ -82,16 +87,22 @@ class LXDPlatform(base.Platform): return res def list_containers(self): - """ - list names of all containers - return_value: list of names + """List names of all containers. + + @return_value: list of names """ return [container.name for container in self.client.containers.all()] - def destroy(self): - """ - Clean up platform data + def query_image_by_alias(self, alias): + """Get image by alias in local image store. + + @param alias: alias of image + @return_value: pylxd image (not cloud_tests.images instance) """ + return self.client.images.get_by_alias(alias) + + def destroy(self): + """Clean up platform data.""" super(LXDPlatform, self).destroy() # vi: ts=4 expandtab |