diff options
author | Scott Moser <smoser@brickies.net> | 2017-11-06 17:39:00 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-11-06 17:39:00 -0500 |
commit | 8622491c29f30862a1a1d7ad2cba023981acc8ce (patch) | |
tree | 597b08c4ca66575cc9567263030876814999beeb /tests/cloud_tests/images/lxd.py | |
parent | be8e3d3c5b5d3d6a3d222383a58fd5feecead7b7 (diff) | |
download | vyos-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/lxd.py')
-rw-r--r-- | tests/cloud_tests/images/lxd.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/tests/cloud_tests/images/lxd.py b/tests/cloud_tests/images/lxd.py index fd4e93c2..5caeba41 100644 --- a/tests/cloud_tests/images/lxd.py +++ b/tests/cloud_tests/images/lxd.py @@ -24,7 +24,7 @@ class LXDImage(base.Image): @param config: image configuration """ self.modified = False - self._instance = None + self._img_instance = None self._pylxd_image = None self.pylxd_image = pylxd_image super(LXDImage, self).__init__(platform, config) @@ -38,9 +38,9 @@ class LXDImage(base.Image): @pylxd_image.setter def pylxd_image(self, pylxd_image): - if self._instance: + if self._img_instance: self._instance.destroy() - self._instance = None + self._img_instance = None if (self._pylxd_image and (self._pylxd_image is not pylxd_image) and (not self.config.get('cache_base_image') or self.modified)): @@ -49,15 +49,19 @@ class LXDImage(base.Image): self._pylxd_image = pylxd_image @property - def instance(self): - """Property function.""" - if not self._instance: - self._instance = self.platform.launch_container( + def _instance(self): + """Internal use only, returns a instance + + This starts an lxc instance from the image, so it is "dirty". + Better would be some way to modify this "at rest". + lxc-pstart would be an option.""" + if not self._img_instance: + self._img_instance = self.platform.launch_container( self.properties, self.config, self.features, use_desc='image-modification', image_desc=str(self), image=self.pylxd_image.fingerprint) - self._instance.start() - return self._instance + self._img_instance.start() + return self._img_instance @property def properties(self): @@ -144,20 +148,20 @@ class LXDImage(base.Image): shutil.rmtree(export_dir) shutil.rmtree(extract_dir) - def execute(self, *args, **kwargs): + def _execute(self, *args, **kwargs): """Execute command in image, modifying image.""" - return self.instance.execute(*args, **kwargs) + return self._instance._execute(*args, **kwargs) 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) + return self._instance.push_file(local_path, remote_path) def run_script(self, *args, **kwargs): """Run script in image, modifying image. @return_value: script output """ - return self.instance.run_script(*args, **kwargs) + return self._instance.run_script(*args, **kwargs) def snapshot(self): """Create snapshot of image, block until done.""" @@ -169,7 +173,7 @@ class LXDImage(base.Image): # clone current instance instance = self.platform.launch_container( self.properties, self.config, self.features, - container=self.instance.name, image_desc=str(self), + container=self._instance.name, image_desc=str(self), use_desc='snapshot', container_config=conf) # wait for cloud-init before boot_clean_script is run to ensure # /var/lib/cloud is removed cleanly |