Fix the error responses from lorax-composer

They are now all consistent, returning status 400, including a json
object with status=flase, and an error message inside the error object.
This commit is contained in:
Brian C. Lane 2018-03-13 14:35:21 -07:00
parent 60874d0197
commit 2e61bc8bf9

View File

@ -949,7 +949,7 @@ def v0_api(api):
limit = int(request.args.get("limit", "20"))
offset = int(request.args.get("offset", "0"))
except ValueError as e:
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
with api.config["GITLOCK"].lock:
recipes = take_limits(map(lambda f: f[:-5], list_branch_files(api.config["GITLOCK"].repo, branch)), offset, limit)
@ -1020,7 +1020,7 @@ def v0_api(api):
limit = int(request.args.get("limit", "20"))
offset = int(request.args.get("offset", "0"))
except ValueError as e:
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
recipes = []
errors = []
@ -1156,7 +1156,7 @@ def v0_api(api):
old_recipe = read_recipe_commit(api.config["GITLOCK"].repo, branch, recipe_name, from_commit)
except Exception as e:
log.error("(v0_recipes_diff) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
try:
if to_commit == "WORKSPACE":
@ -1174,7 +1174,7 @@ def v0_api(api):
new_recipe = read_recipe_commit(api.config["GITLOCK"].repo, branch, recipe_name, to_commit)
except Exception as e:
log.error("(v0_recipes_diff) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
diff = recipe_diff(old_recipe, new_recipe)
return jsonify(diff=diff)
@ -1295,14 +1295,14 @@ def v0_api(api):
limit = int(request.args.get("limit", "20"))
offset = int(request.args.get("offset", "0"))
except ValueError as e:
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
try:
with api.config["YUMLOCK"].lock:
available = projects_list(api.config["YUMLOCK"].yb)
except ProjectsError as e:
log.error("(v0_projects_list) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
projects = take_limits(available, offset, limit)
return jsonify(projects=projects, offset=offset, limit=limit, total=len(available))
@ -1316,7 +1316,7 @@ def v0_api(api):
projects = projects_info(api.config["YUMLOCK"].yb, project_names.split(","))
except ProjectsError as e:
log.error("(v0_projects_info) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
return jsonify(projects=projects)
@ -1329,7 +1329,7 @@ def v0_api(api):
deps = projects_depsolve(api.config["YUMLOCK"].yb, project_names.split(","))
except ProjectsError as e:
log.error("(v0_projects_depsolve) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
return jsonify(projects=deps)
@ -1342,7 +1342,7 @@ def v0_api(api):
limit = int(request.args.get("limit", "20"))
offset = int(request.args.get("offset", "0"))
except ValueError as e:
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
if module_names:
module_names = module_names.split(",")
@ -1352,7 +1352,7 @@ def v0_api(api):
available = modules_list(api.config["YUMLOCK"].yb, module_names)
except ProjectsError as e:
log.error("(v0_modules_list) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
modules = take_limits(available, offset, limit)
return jsonify(modules=modules, offset=offset, limit=limit, total=len(available))
@ -1366,7 +1366,7 @@ def v0_api(api):
modules = modules_info(api.config["YUMLOCK"].yb, module_names.split(","))
except ProjectsError as e:
log.error("(v0_modules_info) %s", str(e))
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
return jsonify(modules=modules)
@ -1465,7 +1465,7 @@ def v0_api(api):
"""Cancel a running compose and delete its results directory"""
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
return jsonify(status=False, msg="%s is not a valid build uuid" % uuid), 400
return jsonify(status=False, error={"msg":"%s is not a valid build uuid" % uuid}), 400
if status["queue_status"] not in ["WAITING", "RUNNING"]:
return jsonify(status=False, uuid=uuid, msg="Cannot cancel a build that is in the %s state" % status["queue_status"])
@ -1515,9 +1515,9 @@ def v0_api(api):
"""Return a tar of the metadata for the build"""
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
return jsonify(status=False, msg="%s is not a valid build uuid" % uuid), 400
return jsonify(status=False, error={"msg":"%s is not a valid build uuid" % uuid}), 400
if status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, uuid=uuid, msg="Build not in FINISHED or FAILED.")
return jsonify(status=False, error={"msg":"Build %s not in FINISHED or FAILED state." % uuid}), 400
else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=False, logs=False),
mimetype="application/x-tar",
@ -1530,9 +1530,9 @@ def v0_api(api):
"""Return a tar of the metadata and the results for the build"""
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
return jsonify(status=False, msg="%s is not a valid build uuid" % uuid), 400
return jsonify(status=False, error={"msg":"%s is not a valid build uuid" % uuid}), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, uuid=uuid, msg="Build not in FINISHED or FAILED.")
return jsonify(status=False, error={"msg":"Build %s not in FINISHED or FAILED state." % uuid}), 400
else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=True, logs=True),
mimetype="application/x-tar",
@ -1545,9 +1545,9 @@ def v0_api(api):
"""Return a tar of the metadata for the build"""
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
return jsonify(status=False, msg="%s is not a valid build uuid"), 400
return jsonify(status=False, error={"msg":"%s is not a valid build uuid" % uuid}), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, uuid=uuid, msg="Build not in FINISHED or FAILED.")
return jsonify(status=False, error={"msg":"Build %s not in FINISHED or FAILED state." % uuid}), 400
else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=False, image=False, logs=True),
mimetype="application/x-tar",
@ -1560,15 +1560,15 @@ def v0_api(api):
"""Return the output image for the build"""
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None:
return jsonify(status=False, msg="%s is not a valid build uuid" % uuid), 400
return jsonify(status=False, error={"msg":"%s is not a valid build uuid" % uuid}), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, uuid=uuid, msg="Build not in FINISHED or FAILED.")
return jsonify(status=False, error={"msg":"Build %s not in FINISHED or FAILED state." % uuid}), 400
else:
image_name, image_path = uuid_image(api.config["COMPOSER_CFG"], uuid)
# 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
return jsonify(status=False, error={"msg":"Build %s is missing image file %s" % (uuid, image_name)}), 400
# Make the image name unique
image_name = uuid + "-" + image_name
@ -1582,7 +1582,7 @@ def v0_api(api):
try:
size = int(request.args.get("size", "1024"))
except ValueError as e:
return jsonify(error={"msg":str(e)}), 400
return jsonify(status=False, error={"msg":str(e)}), 400
status = uuid_status(api.config["COMPOSER_CFG"], uuid)
if status is None or status["queue_status"] == "WAITING":