summaryrefslogtreecommitdiff
path: root/tests/integration_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration_tests')
-rw-r--r--tests/integration_tests/clouds.py78
-rw-r--r--tests/integration_tests/conftest.py4
-rw-r--r--tests/integration_tests/instances.py2
3 files changed, 59 insertions, 25 deletions
diff --git a/tests/integration_tests/clouds.py b/tests/integration_tests/clouds.py
index 2841261b..88ac4408 100644
--- a/tests/integration_tests/clouds.py
+++ b/tests/integration_tests/clouds.py
@@ -2,7 +2,8 @@
from abc import ABC, abstractmethod
import logging
-from pycloudlib import EC2, GCE, Azure, OCI, LXD
+from pycloudlib import EC2, GCE, Azure, OCI, LXDContainer, LXDVirtualMachine
+from pycloudlib.lxd.instance import LXDInstance
import cloudinit
from cloudinit.subp import subp
@@ -12,7 +13,7 @@ from tests.integration_tests.instances import (
IntegrationGceInstance,
IntegrationAzureInstance, IntegrationInstance,
IntegrationOciInstance,
- IntegrationLxdContainerInstance,
+ IntegrationLxdInstance,
)
try:
@@ -143,20 +144,48 @@ class OciCloud(IntegrationCloud):
)
-class LxdContainerCloud(IntegrationCloud):
- datasource = 'lxd_container'
- integration_instance_cls = IntegrationLxdContainerInstance
+class _LxdIntegrationCloud(IntegrationCloud):
+ integration_instance_cls = IntegrationLxdInstance
def _get_cloud_instance(self):
- return LXD(tag='lxd-integration-test')
+ return self.pycloudlib_instance_cls(tag=self.instance_tag)
+
+ @staticmethod
+ def _get_or_set_profile_list(release):
+ return None
+
+ @staticmethod
+ def _mount_source(instance: LXDInstance):
+ target_path = '/usr/lib/python3/dist-packages/cloudinit'
+ format_variables = {
+ 'name': instance.name,
+ 'source_path': cloudinit.__path__[0],
+ 'container_path': target_path,
+ }
+ log.info(
+ 'Mounting source {source_path} directly onto LXD container/vm '
+ 'named {name} at {container_path}'.format(**format_variables))
+ command = (
+ 'lxc config device add {name} host-cloud-init disk '
+ 'source={source_path} '
+ 'path={container_path}'
+ ).format(**format_variables)
+ subp(command.split())
def _perform_launch(self, launch_kwargs):
launch_kwargs['inst_type'] = launch_kwargs.pop('instance_type', None)
launch_kwargs.pop('wait')
+ release = launch_kwargs.pop('image_id')
+
+ try:
+ profile_list = launch_kwargs['profile_list']
+ except KeyError:
+ profile_list = self._get_or_set_profile_list(release)
pycloudlib_instance = self.cloud_instance.init(
launch_kwargs.pop('name', None),
- launch_kwargs.pop('image_id'),
+ release,
+ profile_list=profile_list,
**launch_kwargs
)
if self.settings.CLOUD_INIT_SOURCE == 'IN_PLACE':
@@ -165,19 +194,22 @@ class LxdContainerCloud(IntegrationCloud):
pycloudlib_instance.wait(raise_on_cloudinit_failure=False)
return pycloudlib_instance
- def _mount_source(self, instance):
- container_path = '/usr/lib/python3/dist-packages/cloudinit'
- format_variables = {
- 'name': instance.name,
- 'cloudinit_path': cloudinit.__path__[0],
- 'container_path': container_path,
- }
- log.info(
- 'Mounting source {cloudinit_path} directly onto LXD container/vm '
- 'named {name} at {container_path}'.format(**format_variables))
- command = (
- 'lxc config device add {name} host-cloud-init disk '
- 'source={cloudinit_path} '
- 'path={container_path}'
- ).format(**format_variables)
- subp(command.split())
+
+class LxdContainerCloud(_LxdIntegrationCloud):
+ datasource = 'lxd_container'
+ pycloudlib_instance_cls = LXDContainer
+ instance_tag = 'lxd-container-integration-test'
+
+
+class LxdVmCloud(_LxdIntegrationCloud):
+ datasource = 'lxd_vm'
+ pycloudlib_instance_cls = LXDVirtualMachine
+ instance_tag = 'lxd-vm-integration-test'
+ _profile_list = None
+
+ def _get_or_set_profile_list(self, release):
+ if self._profile_list:
+ return self._profile_list
+ self._profile_list = self.cloud_instance.build_necessary_profiles(
+ release)
+ return self._profile_list
diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py
index 54867096..73b44bfc 100644
--- a/tests/integration_tests/conftest.py
+++ b/tests/integration_tests/conftest.py
@@ -12,6 +12,7 @@ from tests.integration_tests.clouds import (
AzureCloud,
OciCloud,
LxdContainerCloud,
+ LxdVmCloud,
)
@@ -25,6 +26,7 @@ platforms = {
'azure': AzureCloud,
'oci': OciCloud,
'lxd_container': LxdContainerCloud,
+ 'lxd_vm': LxdVmCloud,
}
@@ -87,7 +89,7 @@ def setup_image(session_cloud):
if integration_settings.CLOUD_INIT_SOURCE == 'NONE':
pass # that was easy
elif integration_settings.CLOUD_INIT_SOURCE == 'IN_PLACE':
- if session_cloud.datasource != 'lxd_container':
+ if session_cloud.datasource not in ['lxd_container', 'lxd_vm']:
raise ValueError(
'IN_PLACE as CLOUD_INIT_SOURCE only works for LXD')
# The mount needs to happen after the instance is created, so
diff --git a/tests/integration_tests/instances.py b/tests/integration_tests/instances.py
index 67a6fb92..ca0b38d5 100644
--- a/tests/integration_tests/instances.py
+++ b/tests/integration_tests/instances.py
@@ -125,5 +125,5 @@ class IntegrationOciInstance(IntegrationInstance):
pass
-class IntegrationLxdContainerInstance(IntegrationInstance):
+class IntegrationLxdInstance(IntegrationInstance):
use_sudo = False