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
This commit is contained in:
parent
6881726cb7
commit
e5d88be8cb
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'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user