summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/images/nocloudkvm.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-11-06 17:39:00 -0500
committerScott Moser <smoser@brickies.net>2017-11-06 17:39:00 -0500
commit8622491c29f30862a1a1d7ad2cba023981acc8ce (patch)
tree597b08c4ca66575cc9567263030876814999beeb /tests/cloud_tests/images/nocloudkvm.py
parentbe8e3d3c5b5d3d6a3d222383a58fd5feecead7b7 (diff)
downloadvyos-cloud-init-8622491c29f30862a1a1d7ad2cba023981acc8ce.tar.gz
vyos-cloud-init-8622491c29f30862a1a1d7ad2cba023981acc8ce.zip
tests: integration test cleanup and full pass of nocloud-kvm.
Integration test harness changes: * Enable collection of console log in nocloud-kvm and lxd. * Collect the console log to results for all test runs. * change 'tmpfile' to pick name locally instead of using 'mktemp'. * drop the 'instance' attribute from nocloud-kvm Image and demote LXDImage.instance to a private attribute. This is because Images do not actually have instances. (LXDImage internally uses a booted system to modify the image). * Add 'TargetBase' as a superclass of Image and Instance providing implementations of execute, read_data, write_data, pull_file, and push_file. These all depend on an implementation of _execute. * Improve '_execute' implementations to support accepting stdin. * execute supports 'rcs=False' meaning 'do not raise exception'. * Drop support for pylxd < 2.2. older versions cannot determine exit code of 'execute', which makes them unusable. * make NoCloudKVMInstance._execute run as root via sudo. This required some changes so that 'hostname' could be reverse-looked up in order to avoid sudo taking a long time (~20 seconds). * re-use existing ssh connection in nocloud-kvm. Test changes here: * do not use /tmp, but rather /var/tmp (LP: #1707222) * make keys_to_console assertions more strict. * change user test cases to always add default (ubuntu) user so that nocloud-kvm's execute which operates over ssh can work.
Diffstat (limited to 'tests/cloud_tests/images/nocloudkvm.py')
-rw-r--r--tests/cloud_tests/images/nocloudkvm.py42
1 files changed, 18 insertions, 24 deletions
diff --git a/tests/cloud_tests/images/nocloudkvm.py b/tests/cloud_tests/images/nocloudkvm.py
index a7af0e59..1e7962cb 100644
--- a/tests/cloud_tests/images/nocloudkvm.py
+++ b/tests/cloud_tests/images/nocloudkvm.py
@@ -2,6 +2,8 @@
"""NoCloud KVM Image Base Class."""
+from cloudinit import util as c_util
+
from tests.cloud_tests.images import base
from tests.cloud_tests.snapshots import nocloudkvm as nocloud_kvm_snapshot
@@ -19,24 +21,11 @@ class NoCloudKVMImage(base.Image):
@param img_path: path to the image
"""
self.modified = False
- self._instance = None
self._img_path = img_path
super(NoCloudKVMImage, self).__init__(platform, config)
@property
- def instance(self):
- """Returns an instance of an image."""
- if not self._instance:
- if not self._img_path:
- raise RuntimeError()
-
- self._instance = self.platform.create_image(
- self.properties, self.config, self.features, self._img_path,
- image_desc=str(self), use_desc='image-modification')
- return self._instance
-
- @property
def properties(self):
"""Dictionary containing: 'arch', 'os', 'version', 'release'."""
return {
@@ -46,20 +35,26 @@ class NoCloudKVMImage(base.Image):
'version': self.config['version'],
}
- def execute(self, *args, **kwargs):
+ def _execute(self, command, stdin=None, env=None):
"""Execute command in image, modifying image."""
- return self.instance.execute(*args, **kwargs)
+ return self.mount_image_callback(command, stdin=stdin, env=env)
- def push_file(self, local_path, remote_path):
- """Copy file at 'local_path' to instance at 'remote_path'."""
- return self.instance.push_file(local_path, remote_path)
+ def mount_image_callback(self, command, stdin=None, env=None):
+ """Run mount-image-callback."""
- def run_script(self, *args, **kwargs):
- """Run script in image, modifying image.
+ env_args = []
+ if env:
+ env_args = ['env'] + ["%s=%s" for k, v in env.items()]
- @return_value: script output
- """
- return self.instance.run_script(*args, **kwargs)
+ mic_chroot = ['sudo', 'mount-image-callback', '--system-mounts',
+ '--system-resolvconf', self._img_path,
+ '--', 'chroot', '_MOUNTPOINT_']
+ try:
+ out, err = c_util.subp(mic_chroot + env_args + list(command),
+ data=stdin, decode=False)
+ return (out, err, 0)
+ except c_util.ProcessExecutionError as e:
+ return (e.stdout, e.stderr, e.exit_code)
def snapshot(self):
"""Create snapshot of image, block until done."""
@@ -82,7 +77,6 @@ class NoCloudKVMImage(base.Image):
framework decide whether to keep or destroy everything.
"""
self._img_path = None
- self._instance.destroy()
super(NoCloudKVMImage, self).destroy()
# vi: ts=4 expandtab