Merge "Log required troubleshooting info on image dl fail"
This commit is contained in:
commit
ee93744b9a
ironic_python_agent
@ -137,8 +137,8 @@ class ImageDownloadError(RESTError):
|
|||||||
|
|
||||||
message = 'Error downloading image.'
|
message = 'Error downloading image.'
|
||||||
|
|
||||||
def __init__(self, image_id):
|
def __init__(self, image_id, msg):
|
||||||
details = 'Could not download image with id {0}.'.format(image_id)
|
details = 'Download of image id {0} failed: {1}'.format(image_id, msg)
|
||||||
super(ImageDownloadError, self).__init__(details)
|
super(ImageDownloadError, self).__init__(details)
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,7 +119,9 @@ def _write_configdrive_to_partition(configdrive, device):
|
|||||||
def _request_url(image_info, url):
|
def _request_url(image_info, url):
|
||||||
resp = requests.get(url, stream=True)
|
resp = requests.get(url, stream=True)
|
||||||
if resp.status_code != 200:
|
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
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@ -130,23 +132,27 @@ def _download_image(image_info):
|
|||||||
try:
|
try:
|
||||||
LOG.info("Attempting to download image from {0}".format(url))
|
LOG.info("Attempting to download image from {0}".format(url))
|
||||||
resp = _request_url(image_info, url)
|
resp = _request_url(image_info, url)
|
||||||
except errors.ImageDownloadError:
|
except errors.ImageDownloadError as e:
|
||||||
failtime = time.time() - starttime
|
failtime = time.time() - starttime
|
||||||
log_msg = "Image download failed. URL: {0}; time: {1} seconds"
|
log_msg = ('Image download failed. URL: {0}; time: {1} seconds. '
|
||||||
LOG.warning(log_msg.format(url, failtime))
|
'Error: {2}')
|
||||||
|
LOG.warning(log_msg.format(url, failtime, e.details))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if resp is None:
|
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)
|
image_location = _image_location(image_info)
|
||||||
with open(image_location, 'wb') as f:
|
with open(image_location, 'wb') as f:
|
||||||
try:
|
try:
|
||||||
for chunk in resp.iter_content(IMAGE_CHUNK_SIZE):
|
for chunk in resp.iter_content(IMAGE_CHUNK_SIZE):
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
raise errors.ImageDownloadError(image_info['id'])
|
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
|
totaltime = time.time() - starttime
|
||||||
LOG.info("Image downloaded from {0} in {1} seconds".format(image_location,
|
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.LookupNodeError(DETAILS), SAME_DETAILS),
|
||||||
(errors.LookupAgentIPError(DETAILS), SAME_DETAILS),
|
(errors.LookupAgentIPError(DETAILS), SAME_DETAILS),
|
||||||
(errors.LookupAgentInterfaceError(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.ImageChecksumError('image_id'), DIFF_CL_DETAILS),
|
||||||
(errors.ImageWriteError('device', 'exit_code', 'stdout',
|
(errors.ImageWriteError('device', 'exit_code', 'stdout',
|
||||||
'stderr'),
|
'stderr'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user