summaryrefslogtreecommitdiff
diff options
authorJeff Lane <jeffrey.lane@canonical.com>2017-02-13 14:08:19 -0500
committerJeff Lane <jeffrey.lane@canonical.com>2017-02-13 14:08:19 -0500
commitf4731f869fc726dca4ee5ec39e4c03a06b63ad32 (patch)
treed52ba0a328a8b42a3b8b903bfca33f7d0307a8d3
parent26823e56b9219fca3d0b8e6e8dcd79bb272009f7 (diff)
Fixes from review comments. Also fixed bug caught while testing other fixes when a bad URL is provided causing _test_url to traceback. Also a few PEP8 fixes.
-rwxr-xr-xbin/virtualization25
1 files changed, 16 insertions, 9 deletions
diff --git a/bin/virtualization b/bin/virtualization
index 5b70a54..ff11061 100755
--- a/bin/virtualization
+++ b/bin/virtualization
@@ -31,6 +31,7 @@ import re
import logging
import lsb_release
import requests
+from requests.packages.urllib3.exceptions import NewConnectionError
import shlex
import signal
from subprocess import (
@@ -215,7 +216,7 @@ class KVMTest(object):
# Gives us the stuff needed to build the URL to download the image
return self.download_image(image_path)
- def construct_cloud_url(self, image_url=None):
+ def get_image_name_and_url(self, image_url=None):
"""
Build a URL for official Ubuntu images hosted either at
cloud-images.ubuntu.com or on a maas server hosting a mirror of
@@ -232,7 +233,7 @@ class KVMTest(object):
elif self.qemu_config['cloudimg_type'] == CLOUD_IMAGE_TYPE_DISK:
cloud_iso = "%s-server-cloudimg-%s-disk1.img" % (
self.release, self.qemu_config['cloudimg_arch'])
- elif initial_url is not none:
+ elif initial_url:
# LP 1662580 - if we pass a full URL, assume the last piece is
# the filname and return that.
cloud_iso = initial_url.split('/')[-1]
@@ -247,7 +248,13 @@ class KVMTest(object):
def _test_cloud_url(url):
# test our URL to make sure it's reachable
- ret = requests.head(url)
+ try:
+ ret = requests.head(url)
+ except (OSError, NewConnectionError) as e:
+ logging.error("Unable to connect to {}".format(url))
+ logging.error(e)
+ return False
+
if ret.status_code is not 200:
return False
else:
@@ -279,10 +286,10 @@ class KVMTest(object):
else:
url = urlparse(image_url)
if (
- url.path.endswith('/') or
- url.path == '' or
+ url.path.endswith('/') or
+ url.path == '' or
not url.path.endswith(".img")
- ):
+ ):
# If we have a relative URL (local copies of official images)
# http://192.168.0.1/ or http://192.168.0.1/images/
cloud_iso = _construct_filename()
@@ -310,7 +317,7 @@ class KVMTest(object):
else:
full_url = image_url
cloud_iso = _construct_filename(initial_url=full_url)
-
+
return full_url, cloud_iso
def download_image(self, image_url=None):
@@ -318,9 +325,9 @@ class KVMTest(object):
Downloads Cloud image for same release as host machine
"""
if image_url is None:
- full_url, cloud_iso = self.construct_cloud_url()
+ full_url, cloud_iso = self.get_image_name_and_url()
else:
- full_url, cloud_iso = self.construct_cloud_url(image_url)
+ full_url, cloud_iso = self.get_image_name_and_url(image_url)
logging.debug("Acquiring cloud image from: {}".format(full_url))
# Attempt download