summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <james.falcon@canonical.com>2022-01-18 09:10:36 -0600
committerGitHub <noreply@github.com>2022-01-18 09:10:36 -0600
commit62f82651f2c29db5934f16afcb9f1e522f90588a (patch)
tree2ffbf41303f7016c5b9e28730302597c828ff750
parentb306633fd17e5ba0173ad3c41add59cb11884757 (diff)
downloadvyos-cloud-init-62f82651f2c29db5934f16afcb9f1e522f90588a.tar.gz
vyos-cloud-init-62f82651f2c29db5934f16afcb9f1e522f90588a.zip
testing: support pycloudlib config file (#1189)
https://pycloudlib.readthedocs.io/en/latest/configuration.html#configuration
-rw-r--r--.travis.yml1
-rw-r--r--doc/rtd/topics/integration_tests.rst109
-rw-r--r--integration-requirements.txt2
-rw-r--r--tests/integration_tests/clouds.py24
-rw-r--r--tests/integration_tests/integration_settings.py26
5 files changed, 65 insertions, 97 deletions
diff --git a/.travis.yml b/.travis.yml
index 208bed23..d10c912c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/doc/rtd/topics/integration_tests.rst b/doc/rtd/topics/integration_tests.rst
index 6c124ad9..2677a213 100644
--- a/doc/rtd/topics/integration_tests.rst
+++ b/doc/rtd/topics/integration_tests.rst
@@ -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
===============
@@ -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/
diff --git a/integration-requirements.txt b/integration-requirements.txt
index 53ea85f7..f6c52b28 100644
--- a/integration-requirements.txt
+++ b/integration-requirements.txt
@@ -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
diff --git a/tests/integration_tests/clouds.py b/tests/integration_tests/clouds.py
index d4670bac..e55093b1 100644
--- a/tests/integration_tests/clouds.py
+++ b/tests/integration_tests/clouds.py
@@ -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
@@ -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,
- ),
)
@@ -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):
diff --git a/tests/integration_tests/integration_settings.py b/tests/integration_tests/integration_settings.py
index 02037a88..f27e4f12 100644
--- a/tests/integration_tests/integration_settings.py
+++ b/tests/integration_tests/integration_settings.py
@@ -79,32 +79,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
##################################################################
# Bring in any user-file defined settings