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/platforms/lxd.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/platforms/lxd.py')
-rw-r--r-- | tests/cloud_tests/platforms/lxd.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/cloud_tests/platforms/lxd.py b/tests/cloud_tests/platforms/lxd.py new file mode 100644 index 00000000..847cc549 --- /dev/null +++ b/tests/cloud_tests/platforms/lxd.py @@ -0,0 +1,97 @@ +# This file is part of cloud-init. See LICENSE file for license information. + +from pylxd import (Client, exceptions) + +from tests.cloud_tests.images import lxd as lxd_image +from tests.cloud_tests.instances import lxd as lxd_instance +from tests.cloud_tests.platforms import base +from tests.cloud_tests import util + +DEFAULT_SSTREAMS_SERVER = "https://images.linuxcontainers.org:8443" + + +class LXDPlatform(base.Platform): + """ + Lxd test platform + """ + platform_name = 'lxd' + + def __init__(self, config): + """ + 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 + 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 + """ + if not (image or container): + raise ValueError("either image or container must be specified") + container = self.client.containers.create({ + 'name': util.gen_instance_name(image_desc=image_desc, + use_desc=use_desc, + used_list=self.list_containers()), + 'ephemeral': bool(ephemeral), + 'config': config if isinstance(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) + + def container_exists(self, container_name): + """ + check if container with name 'container_name' exists + return_value: True if exists else False + """ + res = True + try: + self.client.containers.get(container_name) + except exceptions.LXDAPIException as e: + res = False + if e.response.status_code != 404: + raise + return res + + def list_containers(self): + """ + 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 + """ + super(LXDPlatform, self).destroy() + +# vi: ts=4 expandtab |