Merge "Log required troubleshooting info on image dl fail"

This commit is contained in:
Jenkins 2015-02-13 02:17:15 +00:00 committed by Gerrit Code Review
commit ee93744b9a
3 changed files with 17 additions and 10 deletions
ironic_python_agent

@ -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)

@ -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,

@ -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'),