Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ matrix:
- sudo usermod -a -G lxd $USER
- sudo sbuild-adduser $USER
- cp /usr/share/doc/sbuild/examples/example.sbuildrc /home/$USER/.sbuildrc
- echo "[lxd]" > /home/$USER/.config/pycloudlib.toml
script:
# Ubuntu LTS: Build
- ./packages/bddeb -S -d --release bionic
Expand Down
109 changes: 63 additions & 46 deletions doc/rtd/topics/integration_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,69 @@ laid out in :ref:`testing` should be followed for integration tests.
Setup is accomplished via a set of fixtures located in
``tests/integration_tests/conftest.py``.

Test Definition
===============
Tests are defined like any other pytest test. The ``user_data``
mark can be used to supply the cloud-config user data. Platform specific
marks can be used to limit tests to particular platforms. The
client fixture can be used to interact with the launched
test instance.

A basic example:

.. code-block:: python

USER_DATA = """#cloud-config
bootcmd:
- echo 'hello config!' > /tmp/user_data.txt"""


class TestSimple:
@pytest.mark.user_data(USER_DATA)
@pytest.mark.ec2
def test_simple(self, client):
print(client.exec('cloud-init -v'))

Test Execution
==============
Test execution happens via pytest. To run all integration tests,
you would run:

.. code-block:: bash

pytest tests/integration_tests/


Configuration
=============

All possible configuration values are defined in
`tests/integration_tests/integration_settings.py <https://github.com/canonical/cloud-init/blob/main/tests/integration_tests/integration_settings.py>`_.
Defaults can be
overridden by supplying values in ``tests/integration_tests/user_settings.py``
or by providing an environment variable of the same name prepended with
``CLOUD_INIT_``. For example, to set the ``PLATFORM`` setting:

.. code-block:: bash

CLOUD_INIT_PLATFORM='ec2' pytest tests/integration_tests/


Cloud Interation
================
Cloud interaction happens via the
`pycloudlib <https://pycloudlib.readthedocs.io/en/latest/index.html>`_ library.
In order to run integration tests, pycloudlib must first be
`configured <https://pycloudlib.readthedocs.io/en/latest/configuration.html#configuration>`_.

For a minimal setup using LXD, write the following to
``~/.config/pycloudlib.toml``:

.. code-block:: toml

[lxd]


Image Selection
===============

Expand Down Expand Up @@ -63,49 +126,3 @@ Test setup occurs between image setup and test execution. Test setup
is implemented via one of the ``client`` fixtures. When a client fixture
is used, a test instance from which to run tests is launched prior to
test execution and torn down after.

Test Definition
===============
Tests are defined like any other pytest test. The ``user_data``
mark can be used to supply the cloud-config user data. Platform specific
marks can be used to limit tests to particular platforms. The
client fixture can be used to interact with the launched
test instance.

A basic example:

.. code-block:: python

USER_DATA = """#cloud-config
bootcmd:
- echo 'hello config!' > /tmp/user_data.txt"""


class TestSimple:
@pytest.mark.user_data(USER_DATA)
@pytest.mark.ec2
def test_simple(self, client):
print(client.exec('cloud-init -v'))

Test Execution
==============
Test execution happens via pytest. To run all integration tests,
you would run:

.. code-block:: bash

pytest tests/integration_tests/


Configuration
=============

All possible configuration values are defined in
``tests/integration_tests/integration_settings.py``. Defaults can be
overridden by supplying values in ``tests/integration_tests/user_settings.py``
or by providing an environment variable of the same name prepended with
``CLOUD_INIT_``. For example, to set the ``PLATFORM`` setting:

.. code-block:: bash

CLOUD_INIT_PLATFORM='ec2' pytest tests/integration_tests/
2 changes: 1 addition & 1 deletion integration-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PyPI requirements for cloud-init integration testing
# https://cloudinit.readthedocs.io/en/latest/topics/integration_tests.html
#
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@4c4543b5b2c1b51b5875704d21c73eea1c9d3c50
pycloudlib @ git+https://github.com/canonical/pycloudlib.git@e52cc257c5467bb16442a8ef943ca1931c4e1757
pytest
24 changes: 0 additions & 24 deletions tests/integration_tests/clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ class IntegrationCloud(ABC):
def __init__(self, settings=integration_settings):
self.settings = settings
self.cloud_instance = self._get_cloud_instance()
if settings.PUBLIC_SSH_KEY is not None:
# If we have a non-default key, use it.
self.cloud_instance.use_key(
settings.PUBLIC_SSH_KEY, name=settings.KEYPAIR_NAME
)
elif settings.KEYPAIR_NAME is not None:
# Even if we're using the default key, it may still have a
# different name in the clouds, so we need to set it separately.
self.cloud_instance.key_pair.name = settings.KEYPAIR_NAME
self.released_image_id = self._get_initial_image()
self.snapshot_id = None

Expand Down Expand Up @@ -260,17 +251,8 @@ class OciCloud(IntegrationCloud):
integration_instance_cls = IntegrationOciInstance

def _get_cloud_instance(self):
if not integration_settings.ORACLE_AVAILABILITY_DOMAIN:
raise Exception(
"ORACLE_AVAILABILITY_DOMAIN must be set to a valid "
"availability domain. If using the oracle CLI, "
"try `oci iam availability-domain list`"
)
return OCI(
tag="oci-integration-test",
availability_domain=(
integration_settings.ORACLE_AVAILABILITY_DOMAIN,
),
)


Expand Down Expand Up @@ -373,14 +355,8 @@ class OpenstackCloud(IntegrationCloud):
integration_instance_cls = IntegrationInstance

def _get_cloud_instance(self):
if not integration_settings.OPENSTACK_NETWORK:
raise Exception(
"OPENSTACK_NETWORK must be set to a valid Openstack network. "
"If using the openstack CLI, try `openstack network list`"
)
return Openstack(
tag="openstack-integration-test",
network=integration_settings.OPENSTACK_NETWORK,
)

def _get_initial_image(self):
Expand Down
26 changes: 0 additions & 26 deletions tests/integration_tests/integration_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@
COLLECT_LOGS = "ON_ERROR"
LOCAL_LOG_PATH = "/tmp/cloud_init_test_logs"

##################################################################
# SSH KEY SETTINGS
##################################################################

# A path to the public SSH key to use for test runs. (Defaults to pycloudlib's
# default behaviour, using ~/.ssh/id_rsa.pub.)
PUBLIC_SSH_KEY = None

# For clouds which use named keypairs for SSH connection, the name that is used
# for the keypair. (Defaults to pycloudlib's default behaviour.)
KEYPAIR_NAME = None

##################################################################
# OPENSTACK SETTINGS
##################################################################
# Network to use for Openstack. Should be one of the names/ids found
# in `openstack network list`
OPENSTACK_NETWORK = None

##################################################################
# OCI SETTINGS
##################################################################
# Availability domain to use for Oracle. Should be one of the namess found
# in `oci iam availability-domain list`
ORACLE_AVAILABILITY_DOMAIN = None

##################################################################
# USER SETTINGS OVERRIDES
##################################################################
Expand Down