Check to make sure image file exists for /compose/image/

Return an error 400 with an error message if it is missing.
This commit is contained in:
Brian C. Lane 2018-03-13 11:59:28 -07:00
parent 37c982b66e
commit 60874d0197
2 changed files with 9 additions and 2 deletions

View File

@ -898,6 +898,7 @@ DELETE `/api/v0/compose/delete/<uuids>`
import logging
log = logging.getLogger("lorax-composer")
import os
from flask import jsonify, request, Response, send_file
from pylorax.api.compose import start_build, compose_types
@ -1564,8 +1565,13 @@ def v0_api(api):
return jsonify(status=False, uuid=uuid, msg="Build not in FINISHED or FAILED.")
else:
image_name, image_path = uuid_image(api.config["COMPOSER_CFG"], uuid)
image_name = uuid + "-" + image_name
# Make sure it really exists
if not os.path.exists(image_path):
return jsonify(status=False, uuid=uuid, error={"msg":"Build %s is missing image file %s" % (uuid, image_name)}), 400
# Make the image name unique
image_name = uuid + "-" + image_name
# XXX - Will mime type guessing work for all our output?
return send_file(image_path, as_attachment=True, attachment_filename=image_name, add_etags=False)

View File

@ -433,7 +433,8 @@ def make_image(opts, ks, callback_func=None):
log.error("Install failed: %s", e)
if not opts.keep_image:
log.info("Removing bad disk image")
os.unlink(disk_img)
if os.path.exists(disk_img):
os.unlink(disk_img)
raise
log.info("Disk Image install successful")