summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorJay Faulkner <jay@jvf.cc>2015-02-11 14:20:02 -0800
committerJim Rollenhagen <jim@jimrollenhagen.com>2015-02-12 07:35:11 -0800
commite5d88be8cb98298323b4644dff08b38fc970f1cd (patch)
treec0cef4ef4761d1575d36f0b1e69b7eea5816cadb /ironic_python_agent
parent6881726cb771aa966afa92498c8616ec5d0b5862 (diff)
downloadironic-python-agent-e5d88be8cb98298323b4644dff08b38fc970f1cd.tar.gz
Log required troubleshooting info on image dl fail
Currently, we only log the image ID and attempted URL. Now, we log the status code recieved and detailed information about how and when things failed. Change-Id: I718c7facbe1500d98be78b7b6137e92fdfb2fdf1 Closes-bug: 1420981 Depends-On: I69f6f6eef4ad573f406d64d579a9811c70ac5d28
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/errors.py4
-rw-r--r--ironic_python_agent/extensions/standby.py20
-rw-r--r--ironic_python_agent/tests/errors.py3
3 files changed, 17 insertions, 10 deletions
diff --git a/ironic_python_agent/errors.py b/ironic_python_agent/errors.py
index 5ec2e3bf..f21678d4 100644
--- a/ironic_python_agent/errors.py
+++ b/ironic_python_agent/errors.py
@@ -137,8 +137,8 @@ class ImageDownloadError(RESTError):
message = 'Error downloading image.'
- def __init__(self, image_id):
- details = 'Could not download image with id {0}.'.format(image_id)
+ def __init__(self, image_id, msg):
+ details = 'Download of image id {0} failed: {1}'.format(image_id, msg)
super(ImageDownloadError, self).__init__(details)
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py
index 4b02f143..b792d177 100644
--- a/ironic_python_agent/extensions/standby.py
+++ b/ironic_python_agent/extensions/standby.py
@@ -119,7 +119,9 @@ def _write_configdrive_to_partition(configdrive, device):
def _request_url(image_info, url):
resp = requests.get(url, stream=True)
if resp.status_code != 200:
- raise errors.ImageDownloadError(image_info['id'])
+ msg = ('Received status code {0} from {1}, expected 200. Response '
+ 'body: {2}').format(resp.status_code, url, resp.text)
+ raise errors.ImageDownloadError(image_info['id'], msg)
return resp
@@ -130,23 +132,27 @@ def _download_image(image_info):
try:
LOG.info("Attempting to download image from {0}".format(url))
resp = _request_url(image_info, url)
- except errors.ImageDownloadError:
+ except errors.ImageDownloadError as e:
failtime = time.time() - starttime
- log_msg = "Image download failed. URL: {0}; time: {1} seconds"
- LOG.warning(log_msg.format(url, failtime))
+ log_msg = ('Image download failed. URL: {0}; time: {1} seconds. '
+ 'Error: {2}')
+ LOG.warning(log_msg.format(url, failtime, e.details))
continue
else:
break
if resp is None:
- raise errors.ImageDownloadError(image_info['id'])
+ msg = 'Image download failed for all URLs.'
+ raise errors.ImageDownloadError(image_info['id'], msg)
image_location = _image_location(image_info)
with open(image_location, 'wb') as f:
try:
for chunk in resp.iter_content(IMAGE_CHUNK_SIZE):
f.write(chunk)
- except Exception:
- raise errors.ImageDownloadError(image_info['id'])
+ except Exception as e:
+ msg = 'Unable to write image to {0}. Error: {1}'.format(
+ image_location, str(e))
+ raise errors.ImageDownloadError(image_info['id'], msg)
totaltime = time.time() - starttime
LOG.info("Image downloaded from {0} in {1} seconds".format(image_location,
diff --git a/ironic_python_agent/tests/errors.py b/ironic_python_agent/tests/errors.py
index b36cad86..b49ee67d 100644
--- a/ironic_python_agent/tests/errors.py
+++ b/ironic_python_agent/tests/errors.py
@@ -93,7 +93,8 @@ class TestErrors(test_base.BaseTestCase):
(errors.LookupNodeError(DETAILS), SAME_DETAILS),
(errors.LookupAgentIPError(DETAILS), SAME_DETAILS),
(errors.LookupAgentInterfaceError(DETAILS), SAME_DETAILS),
- (errors.ImageDownloadError('image_id'), DIFF_CL_DETAILS),
+ (errors.ImageDownloadError('image_id', DETAILS),
+ DIFF_CL_DETAILS),
(errors.ImageChecksumError('image_id'), DIFF_CL_DETAILS),
(errors.ImageWriteError('device', 'exit_code', 'stdout',
'stderr'),