summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/snapshots/nocloudkvm.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-11-29 15:26:38 -0500
committerScott Moser <smoser@brickies.net>2017-11-29 15:26:38 -0500
commit88368f9851b29dddb5a12e4b21868cbdef906c5c (patch)
treebc82164948ace765b43dd2edbc7054331de2c7ca /tests/cloud_tests/snapshots/nocloudkvm.py
parent4964fb38f11c15ed119ff4c7f4379ae3c8785a9a (diff)
downloadvyos-cloud-init-88368f9851b29dddb5a12e4b21868cbdef906c5c.tar.gz
vyos-cloud-init-88368f9851b29dddb5a12e4b21868cbdef906c5c.zip
tests: NoCloudKVMImage do not modify the original local cache image.
The NoCloudKVMImage.execute() would modify the image in /srv/citest that meant that after the first time you ran a test, the image was dirty. The change here is to make the image operate on a qcow backed image. Also modify Snapshot to then copy the qcow rather than creating another chained qcow. The reason being that the image might go away or change after the snapshot has been returned. Also * drop use of 'override_templates' which was only relevant to LXD. * NoCloudKVM.create_image() returned an instance before now it has create_instance which creates an instance. * NoCloudKVMInstance has a 'disk' attribute separate from 'name'
Diffstat (limited to 'tests/cloud_tests/snapshots/nocloudkvm.py')
-rw-r--r--tests/cloud_tests/snapshots/nocloudkvm.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/cloud_tests/snapshots/nocloudkvm.py b/tests/cloud_tests/snapshots/nocloudkvm.py
index 09998349..21e908da 100644
--- a/tests/cloud_tests/snapshots/nocloudkvm.py
+++ b/tests/cloud_tests/snapshots/nocloudkvm.py
@@ -2,6 +2,8 @@
"""Base NoCloud KVM snapshot."""
import os
+import shutil
+import tempfile
from tests.cloud_tests.snapshots import base
@@ -11,16 +13,19 @@ class NoCloudKVMSnapshot(base.Snapshot):
platform_name = "nocloud-kvm"
- def __init__(self, platform, properties, config, features,
- instance):
+ def __init__(self, platform, properties, config, features, image_path):
"""Set up snapshot.
@param platform: platform object
@param properties: image properties
@param config: image config
@param features: supported feature flags
+ @param image_path: image file to snapshot.
"""
- self.instance = instance
+ self._workd = tempfile.mkdtemp(prefix='NoCloudKVMSnapshot')
+ snapshot = os.path.join(self._workd, 'snapshot')
+ shutil.copyfile(image_path, snapshot)
+ self._image_path = snapshot
super(NoCloudKVMSnapshot, self).__init__(
platform, properties, config, features)
@@ -40,9 +45,9 @@ class NoCloudKVMSnapshot(base.Snapshot):
self.platform.config['public_key'])
user_data = self.inject_ssh_key(user_data, key_file)
- instance = self.platform.create_image(
+ instance = self.platform.create_instance(
self.properties, self.config, self.features,
- self.instance.name, image_desc=str(self), use_desc=use_desc,
+ self._image_path, image_desc=str(self), use_desc=use_desc,
user_data=user_data, meta_data=meta_data)
if start:
@@ -68,7 +73,7 @@ class NoCloudKVMSnapshot(base.Snapshot):
def destroy(self):
"""Clean up snapshot data."""
- self.instance.destroy()
+ shutil.rmtree(self._workd)
super(NoCloudKVMSnapshot, self).destroy()
# vi: ts=4 expandtab