summaryrefslogtreecommitdiff
diff options
-rwxr-xr-xbin/virtualization104
-rw-r--r--jobs/virtualization.txt.in24
2 files changed, 57 insertions, 71 deletions
diff --git a/bin/virtualization b/bin/virtualization
index 65fee88..fe59656 100755
--- a/bin/virtualization
+++ b/bin/virtualization
@@ -44,13 +44,11 @@ import tempfile
import tarfile
import time
import urllib.request
+from urllib.parse import urlparse
DEFAULT_TIMEOUT = 500
-class XENTest(object):
- pass
-
# The "TAR" type is a tarball that contains both
# a disk image and a kernel binary. This is useful
# on architectures that don't (yet) have a bootloader
@@ -110,9 +108,9 @@ QEMU_ARCH_CONFIG = {
'qemu_bin': 'qemu-system-ppc64',
'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO,
'qemu_extra_args': [
- '-enable-kvm',
+ '-enable-kvm',
'-machine', 'pseries,usb=off',
- '-cpu', 'POWER8',
+ '-cpu', 'POWER8',
],
},
's390x': {
@@ -121,7 +119,7 @@ QEMU_ARCH_CONFIG = {
'qemu_bin': 'qemu-system-s390x',
'qemu_disk_type': QEMU_DISK_TYPE_VIRTIO,
'qemu_extra_args': [
- '-enable-kvm',
+ '-enable-kvm',
'-machine', 's390-ccw-virtio-2.5',
],
},
@@ -200,35 +198,68 @@ class KVMTest(object):
self.arch = check_output(['dpkg', '--print-architecture'],
universal_newlines=True).strip()
self.qemu_config = QEMU_ARCH_CONFIG[self.arch]
+ self.release = lsb_release.get_lsb_information()["CODENAME"]
- def download_image(self):
+ def url_to_path(self, image_path):
"""
- Downloads Cloud image for same release as host machine
+ Test the provided image path to determine if it's a URL or or a simple
+ file path
+ """
+ url = urlparse(image_path)
+ if url.scheme == '' or url.scheme == 'file':
+ # Gives us path wheter we specify a filesystem path or a file URL
+ logging.debug("Cloud image exists locally at %s" % url.path)
+ return url.path
+ elif url.scheme == 'http' or url.scheme == 'ftp':
+ # Gives us the stuff needed to build the URL to download the image
+ return self.download_image(image_path)
+
+ def construct_cloud_filename(self):
+ """
+ Build a URL for official Ubuntu images hosted either at
+ cloud-images.ubuntu.com or on a maas server hosting a mirror of
+ cloud-images.ubuntu.com
"""
-
- # Check Ubuntu release info. Example {quantal, precise}
- release = lsb_release.get_lsb_information()["CODENAME"]
-
- # Construct URL
- cloud_url = "http://cloud-images.ubuntu.com"
-
if self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_TAR:
cloud_iso = "%s-server-cloudimg-%s.tar.gz" % (
- release, self.qemu_config['cloudimg_arch'])
+ self.release, self.qemu_config['cloudimg_arch'])
elif self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_DISK:
cloud_iso = "%s-server-cloudimg-%s-disk1.img" % (
- release, self.qemu_config['cloudimg_arch'])
+ self.release, self.qemu_config['cloudimg_arch'])
else:
logging.error("Unknown cloud image type")
- return False
- image_url = "/".join((
- cloud_url, release, "current", cloud_iso))
+ sys.exit(1)
+ return cloud_iso
+ def download_image(self, image_url=None):
+ """
+ Downloads Cloud image for same release as host machine
+ """
+ if image_url is None:
+ # If we have not specified a URL to get our images from, default
+ # to ubuntu.com
+ cloud_url = "http://cloud-images.ubuntu.com"
+ cloud_iso = self.construct_cloud_filename()
+ full_url = "/".join((
+ cloud_url, self.release, "current", cloud_iso))
+ else:
+ url = urlparse(image_url)
+ if url.path.endswith('/') or url.path == '':
+ # If we have a relative URL (MAAS server mirror)
+ cloud_url = image_url
+ cloud_iso = self.construct_cloud_filename()
+ full_url = "/".join((
+ cloud_url, cloud_iso))
+ else:
+ # Assume anything else is an absolute URL to a remote server
+ cloud_iso = url.path.split('/')[-1]
+ cloud_url = "{}://{}".format(url.scheme, url.netloc)
+ full_url = image_url
logging.debug("Downloading {}, from {}".format(cloud_iso, cloud_url))
# Attempt download
try:
- resp = urllib.request.urlretrieve(image_url, cloud_iso)
+ resp = urllib.request.urlretrieve(full_url, cloud_iso)
except (IOError,
OSError,
urllib.error.HTTPError,
@@ -362,6 +393,10 @@ final_message: CERTIFICATION BOOT COMPLETE
logging.debug('No image specified, downloading one now.')
# Download cloud image
self.image = self.download_image()
+ else:
+ logging.debug('Cloud image location specified: %s.' %
+ self.image)
+ self.image = self.url_to_path(self.image)
if self.image and os.path.isfile(self.image):
@@ -410,35 +445,10 @@ final_message: CERTIFICATION BOOT COMPLETE
def test_kvm(args):
print("Executing KVM Test", file=sys.stderr)
- DEFAULT_CFG = "/etc/xdg/virtualization.cfg"
image = ""
timeout = ""
- # Configuration data can come from three sources.
- # Lowest priority is the config file.
- config_file = DEFAULT_CFG
- config = configparser.SafeConfigParser()
-
- try:
- config.readfp(open(config_file))
- except IOError:
- logging.warn("Config file %s was not found" % DEFAULT_CFG)
- logging.warn("Now looking for ENV variables and command line arguments instead")
- else:
- try:
- timeout = config.getfloat("KVM", "timeout")
- except ValueError:
- logging.warning('Invalid or Empty timeout in config file. '
- 'Falling back to default')
- except configparser.NoSectionError as e:
- logging.exception(e)
-
- try:
- image = config.get("KVM", "image")
- except configparser.NoSectionError:
- logging.exception('Invalid or Empty image in config file.')
-
- # Next in priority are environment variables.
+ # First in priority are environment variables.
if 'KVM_TIMEOUT' in os.environ:
try:
timeout = float(os.environ['KVM_TIMEOUT'])
diff --git a/jobs/virtualization.txt.in b/jobs/virtualization.txt.in
index 70b6655..919691b 100644
--- a/jobs/virtualization.txt.in
+++ b/jobs/virtualization.txt.in
@@ -14,27 +14,3 @@ _description:
cloud image.
_summary:
Verify KVM guest boots
-
-plugin: shell
-category_id: 2013.com.canonical.plainbox::virtualization
-id: virtualization/xen_ok
-requires: package.name == 'libvirt-bin'
-user: root
-estimated_duration: 1.0
-command: virsh -c xen:/// domstate Domain-0
-_description:
- Test to verify that the Xen Hypervisor is running.
-_summary:
- Verify Xen is running
-
-plugin: shell
-category_id: 2013.com.canonical.plainbox::virtualization
-id: virtualization/xen_check_vm
-depends: virtualization/xen_ok
-user: root
-estimated_duration: 300.0
-command: xen_test /images/xentest.img /images/xentest.xml
-_description:
- Test to check that a Xen domU image can boot and run on Xen on Ubuntu
-_summary:
- Verify Xen domU can boot