summaryrefslogtreecommitdiff
path: root/tests/integration_tests/conftest.py
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2020-10-26 11:16:20 -0500
committerGitHub <noreply@github.com>2020-10-26 12:16:20 -0400
commit404f0a4a6542cdc721901d149ac981a81199aa79 (patch)
tree18be4a03684f24559d2b250c9fc2a24f577b74d0 /tests/integration_tests/conftest.py
parentf5b3ad741679cd42d2c145e574168dafe3ac15c1 (diff)
downloadvyos-cloud-init-404f0a4a6542cdc721901d149ac981a81199aa79.tar.gz
vyos-cloud-init-404f0a4a6542cdc721901d149ac981a81199aa79.zip
refactor integration testing infrastructure (#610)
* Separated IntegrationClient into separate cloud and instance abstractions. This makes it easier to control the lifetime of the pycloudlib's cloud and instance abstractions separately. * Created new cloud-specific subclasses accordingly * Moved platform parsing and initialization code into its own file * Created new session-wide autorun fixture to automatically initialize and destroy the dynamic cloud
Diffstat (limited to 'tests/integration_tests/conftest.py')
-rw-r--r--tests/integration_tests/conftest.py75
1 files changed, 52 insertions, 23 deletions
diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py
index 9c4eb03a..9163ac66 100644
--- a/tests/integration_tests/conftest.py
+++ b/tests/integration_tests/conftest.py
@@ -1,21 +1,32 @@
# This file is part of cloud-init. See LICENSE file for license information.
-import os
import logging
+import os
import pytest
import sys
from contextlib import contextmanager
from tests.integration_tests import integration_settings
-from tests.integration_tests.platforms import (
- dynamic_client,
- LxdContainerClient,
- client_name_to_class
+from tests.integration_tests.clouds import (
+ Ec2Cloud,
+ GceCloud,
+ AzureCloud,
+ OciCloud,
+ LxdContainerCloud,
)
+
log = logging.getLogger('integration_testing')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.INFO)
+platforms = {
+ 'ec2': Ec2Cloud,
+ 'gce': GceCloud,
+ 'azure': AzureCloud,
+ 'oci': OciCloud,
+ 'lxd_container': LxdContainerCloud,
+}
+
def pytest_runtest_setup(item):
"""Skip tests on unsupported clouds.
@@ -25,7 +36,7 @@ def pytest_runtest_setup(item):
platform, then skip the test. If platform specific marks are not
specified, then we assume the test can be run anywhere.
"""
- all_platforms = client_name_to_class.keys()
+ all_platforms = platforms.keys()
supported_platforms = set(all_platforms).intersection(
mark.name for mark in item.iter_markers())
current_platform = integration_settings.PLATFORM
@@ -40,33 +51,51 @@ def disable_subp_usage(request):
pass
+@pytest.yield_fixture(scope='session')
+def session_cloud():
+ if integration_settings.PLATFORM not in platforms.keys():
+ raise ValueError(
+ "{} is an invalid PLATFORM specified in settings. "
+ "Must be one of {}".format(
+ integration_settings.PLATFORM, list(platforms.keys())
+ )
+ )
+
+ cloud = platforms[integration_settings.PLATFORM]()
+ yield cloud
+ cloud.destroy()
+
+
@pytest.fixture(scope='session', autouse=True)
-def setup_image():
+def setup_image(session_cloud):
"""Setup the target environment with the correct version of cloud-init.
So we can launch instances / run tests with the correct image
"""
- client = dynamic_client()
- log.info('Setting up environment for %s', client.datasource)
- client.emit_settings_to_log()
+ client = None
+ log.info('Setting up environment for %s', session_cloud.datasource)
if integration_settings.CLOUD_INIT_SOURCE == 'NONE':
pass # that was easy
elif integration_settings.CLOUD_INIT_SOURCE == 'IN_PLACE':
- if not isinstance(client, LxdContainerClient):
+ if session_cloud.datasource != 'lxd_container':
raise ValueError(
'IN_PLACE as CLOUD_INIT_SOURCE only works for LXD')
# The mount needs to happen after the instance is launched, so
# no further action needed here
elif integration_settings.CLOUD_INIT_SOURCE == 'PROPOSED':
- client.launch()
+ client = session_cloud.launch()
client.install_proposed_image()
elif integration_settings.CLOUD_INIT_SOURCE.startswith('ppa:'):
- client.launch()
+ client = session_cloud.launch()
client.install_ppa(integration_settings.CLOUD_INIT_SOURCE)
elif os.path.isfile(str(integration_settings.CLOUD_INIT_SOURCE)):
- client.launch()
+ client = session_cloud.launch()
client.install_deb()
- if client.instance:
+ else:
+ raise ValueError(
+ 'Invalid value for CLOUD_INIT_SOURCE setting: {}'.format(
+ integration_settings.CLOUD_INIT_SOURCE))
+ if client:
# Even if we're keeping instances, we don't want to keep this
# one around as it was just for image creation
client.destroy()
@@ -74,7 +103,7 @@ def setup_image():
@contextmanager
-def _client(request, fixture_utils):
+def _client(request, fixture_utils, session_cloud):
"""Fixture implementation for the client fixtures.
Launch the dynamic IntegrationClient instance using any provided
@@ -82,28 +111,28 @@ def _client(request, fixture_utils):
"""
user_data = fixture_utils.closest_marker_first_arg_or(
request, 'user_data', None)
- with dynamic_client(user_data=user_data) as instance:
+ with session_cloud.launch(user_data=user_data) as instance:
yield instance
@pytest.yield_fixture
-def client(request, fixture_utils):
+def client(request, fixture_utils, session_cloud):
"""Provide a client that runs for every test."""
- with _client(request, fixture_utils) as client:
+ with _client(request, fixture_utils, session_cloud) as client:
yield client
@pytest.yield_fixture(scope='module')
-def module_client(request, fixture_utils):
+def module_client(request, fixture_utils, session_cloud):
"""Provide a client that runs once per module."""
- with _client(request, fixture_utils) as client:
+ with _client(request, fixture_utils, session_cloud) as client:
yield client
@pytest.yield_fixture(scope='class')
-def class_client(request, fixture_utils):
+def class_client(request, fixture_utils, session_cloud):
"""Provide a client that runs once per class."""
- with _client(request, fixture_utils) as client:
+ with _client(request, fixture_utils, session_cloud) as client:
yield client