summaryrefslogtreecommitdiff
path: root/tests/integration_tests/clouds.py
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2020-11-30 10:20:15 -0600
committerGitHub <noreply@github.com>2020-11-30 11:20:15 -0500
commit2bd34bda9543c1b66f53eaf26706f0de887db187 (patch)
treef22548313ac2d9c81a38502ed9bf855cebfbc29c /tests/integration_tests/clouds.py
parentde3183c1ff4660dda23f2624c1cc24bb76de5bf5 (diff)
downloadvyos-cloud-init-2bd34bda9543c1b66f53eaf26706f0de887db187.tar.gz
vyos-cloud-init-2bd34bda9543c1b66f53eaf26706f0de887db187.zip
Delete image snapshots created for integration tests (#682)
Integration tests have been leaving behind snapshot images, so now we clean them up. Also, in testing, found that in Azure, deleting a resource group will automatically delete the instance, so if KEEP_INSTANCE is True, we no longer delete the resource group. Co-authored-by: Daniel Watkins <oddbloke@ubuntu.com>
Diffstat (limited to 'tests/integration_tests/clouds.py')
-rw-r--r--tests/integration_tests/clouds.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/integration_tests/clouds.py b/tests/integration_tests/clouds.py
index 88ac4408..4d5c2c2a 100644
--- a/tests/integration_tests/clouds.py
+++ b/tests/integration_tests/clouds.py
@@ -32,7 +32,14 @@ class IntegrationCloud(ABC):
def __init__(self, settings=integration_settings):
self.settings = settings
self.cloud_instance = self._get_cloud_instance()
- self.image_id = self._get_initial_image()
+ self._released_image_id = self._get_initial_image()
+ self.snapshot_id = None
+
+ @property
+ def image_id(self):
+ if self.snapshot_id:
+ return self.snapshot_id
+ return self._released_image_id
def emit_settings_to_log(self) -> None:
log.info(
@@ -50,13 +57,13 @@ class IntegrationCloud(ABC):
raise NotImplementedError
def _get_initial_image(self):
- image_id = self.settings.OS_IMAGE
+ _released_image_id = self.settings.OS_IMAGE
try:
- image_id = self.cloud_instance.released_image(
+ _released_image_id = self.cloud_instance.released_image(
self.settings.OS_IMAGE)
except (ValueError, IndexError):
pass
- return image_id
+ return _released_image_id
def _perform_launch(self, launch_kwargs):
pycloudlib_instance = self.cloud_instance.launch(**launch_kwargs)
@@ -100,6 +107,14 @@ class IntegrationCloud(ABC):
def snapshot(self, instance):
return self.cloud_instance.snapshot(instance, clean=True)
+ def delete_snapshot(self):
+ if self.snapshot_id:
+ log.info(
+ 'Deleting snapshot image created for this testrun: %s',
+ self.snapshot_id
+ )
+ self.cloud_instance.delete_image(self.snapshot_id)
+
class Ec2Cloud(IntegrationCloud):
datasource = 'ec2'
@@ -130,7 +145,14 @@ class AzureCloud(IntegrationCloud):
return Azure(tag='azure-integration-test')
def destroy(self):
- self.cloud_instance.delete_resource_group()
+ if self.settings.KEEP_INSTANCE:
+ log.info(
+ 'NOT deleting resource group because KEEP_INSTANCE is true '
+ 'and deleting resource group would also delete instance. '
+ 'Instance and resource group must both be manually deleted.'
+ )
+ else:
+ self.cloud_instance.delete_resource_group()
class OciCloud(IntegrationCloud):