diff options
author | Joshua Powers <josh.powers@canonical.com> | 2017-07-11 14:28:11 -0700 |
---|---|---|
committer | Joshua Powers <josh.powers@canonical.com> | 2017-09-14 11:53:55 -0700 |
commit | 376168e251a1d4f2ee3643fed6092b8907f057ec (patch) | |
tree | f49b6f01b46bb7c84d54c42d7b6da6ebf1a30e97 /tests/cloud_tests/setup_image.py | |
parent | 29a9296cd68516e76d0bd8da320754a222c4ee45 (diff) | |
download | vyos-cloud-init-376168e251a1d4f2ee3643fed6092b8907f057ec.tar.gz vyos-cloud-init-376168e251a1d4f2ee3643fed6092b8907f057ec.zip |
tests: Enable the NoCloud KVM platform
The NoCloud KVM platform includes:
* Downloads daily Ubuntu images using streams and store in
/srv/images
* Image customization, if required, is done using
mount-image-callback otherwise image is untouched
* Launches KVM via the xkvm script, a wrapper around
qemu-system, and sets custom port for SSH
* Generation and inject an SSH (RSA 4096) key pair to use for
communication with the guest to collect test artifacts
* Add method to produce safe shell strings by base64 encoding
the command
Additional Changes:
* Set default backend to use LXD
* Verify not running script as root in order to prevent images
from becoming owned by root
* Removed extra quotes around that were added when collecting
the cloud-init version from the image
* Added info about each release as previously the lxd backend
was able to query that information from pylxd image info,
however, other backends will not be able to obtain the same
information as easily
Diffstat (limited to 'tests/cloud_tests/setup_image.py')
-rw-r--r-- | tests/cloud_tests/setup_image.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/cloud_tests/setup_image.py b/tests/cloud_tests/setup_image.py index 3c0fff62..6672ffb3 100644 --- a/tests/cloud_tests/setup_image.py +++ b/tests/cloud_tests/setup_image.py @@ -5,6 +5,7 @@ from functools import partial import os +from cloudinit import util as c_util from tests.cloud_tests import LOG from tests.cloud_tests import stage, util @@ -19,7 +20,7 @@ def installed_package_version(image, package, ensure_installed=True): """ os_family = util.get_os_family(image.properties['os']) if os_family == 'debian': - cmd = ['dpkg-query', '-W', "--showformat='${Version}'", package] + cmd = ['dpkg-query', '-W', "--showformat=${Version}", package] elif os_family == 'redhat': cmd = ['rpm', '-q', '--queryformat', "'%{VERSION}'", package] else: @@ -53,7 +54,7 @@ def install_deb(args, image): image.execute(cmd, description=msg) # check installed deb version matches package - fmt = ['-W', "--showformat='${Version}'"] + fmt = ['-W', "--showformat=${Version}"] (out, err, exit) = image.execute(['dpkg-deb'] + fmt + [remote_path]) expected_version = out.strip() found_version = installed_package_version(image, 'cloud-init') @@ -191,6 +192,20 @@ def enable_repo(args, image): image.execute(cmd, description=msg) +def generate_ssh_keys(data_dir): + """Generate SSH keys to be used with image.""" + LOG.info('generating SSH keys') + filename = os.path.join(data_dir, 'id_rsa') + + if os.path.exists(filename): + c_util.del_file(filename) + + c_util.subp(['ssh-keygen', '-t', 'rsa', '-b', '4096', + '-f', filename, '-P', '', + '-C', 'ubuntu@cloud_test'], + capture=True) + + def setup_image(args, image): """Set up image as specified in args. @@ -226,6 +241,7 @@ def setup_image(args, image): 'set up for {}'.format(image), calls, continue_after_error=False) LOG.debug('after setup complete, installed cloud-init version is: %s', installed_package_version(image, 'cloud-init')) + generate_ssh_keys(args.data_dir) return res # vi: ts=4 expandtab |