summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2020-11-23 12:12:52 -0600
committerGitHub <noreply@github.com>2020-11-23 13:12:52 -0500
commit8a493bf08d8b09d4f3a35dae725756d157844201 (patch)
treeac74240caa0206393ca875c997b7a9f23c262f90
parente454dea5855019a5acdd6acafdef2ae07d069235 (diff)
downloadvyos-cloud-init-8a493bf08d8b09d4f3a35dae725756d157844201.tar.gz
vyos-cloud-init-8a493bf08d8b09d4f3a35dae725756d157844201.zip
LXD VM support in integration tests (#678)
-rw-r--r--integration-requirements.txt2
-rw-r--r--tests/integration_tests/clouds.py78
-rw-r--r--tests/integration_tests/conftest.py4
-rw-r--r--tests/integration_tests/instances.py2
-rw-r--r--tox.ini1
5 files changed, 61 insertions, 26 deletions
diff --git a/integration-requirements.txt b/integration-requirements.txt
index 61d2e504..e8ddb648 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@e6b2b3732a2a17d48bdf1167f56eb14576215d3c
+pycloudlib @ git+https://github.com/canonical/pycloudlib.git@9211c0e5b34794595565d4626bc41ddbe14994f2
pytest
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
diff --git a/tox.ini b/tox.ini
index f08e0f03..30b11398 100644
--- a/tox.ini
+++ b/tox.ini
@@ -167,6 +167,7 @@ markers =
azure: test will only run on Azure platform
oci: test will only run on OCI platform
lxd_container: test will only run in LXD container
+ lxd_vm: test will only run in LXD VM
no_container: test cannot run in a container
user_data: the user data to be passed to the test instance
instance_name: the name to be used for the test instance