Add error IDs for bad state conditions.

This commit is contained in:
Chris Lumens 2018-08-08 10:31:14 -04:00
parent 9677b012da
commit d76e24053a
2 changed files with 12 additions and 7 deletions

View File

@ -19,3 +19,8 @@
# Returned from the API when ?limit= or ?offset= is given something that does # Returned from the API when ?limit= or ?offset= is given something that does
# not convert into an integer. # not convert into an integer.
BAD_LIMIT_OR_OFFSET = "BadLimitOrOffset" BAD_LIMIT_OR_OFFSET = "BadLimitOrOffset"
# Returned from the API when it expected a build to be in a state other than
# what it currently is. This most often happens when asking for results from
# a build that is not yet done.
BUILD_IN_WRONG_STATE = "BuildInWrongState"

View File

@ -1819,7 +1819,7 @@ def v0_api(api):
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
if status["queue_status"] not in ["WAITING", "RUNNING"]: if status["queue_status"] not in ["WAITING", "RUNNING"]:
return jsonify(status=False, errors=["Build %s is not in WAITING or RUNNING." % uuid]) return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s is not in WAITING or RUNNING." % uuid}])
try: try:
uuid_cancel(api.config["COMPOSER_CFG"], uuid) uuid_cancel(api.config["COMPOSER_CFG"], uuid)
@ -1844,7 +1844,7 @@ def v0_api(api):
if status is None: if status is None:
errors.append("%s is not a valid build uuid" % uuid) errors.append("%s is not a valid build uuid" % uuid)
elif status["queue_status"] not in ["FINISHED", "FAILED"]: elif status["queue_status"] not in ["FINISHED", "FAILED"]:
errors.append("Build %s is not in FINISHED or FAILED." % uuid) errors.append({"id": BUILD_IN_WRONG_STATE, "msg": "Build %s is not in FINISHED or FAILED." % uuid})
else: else:
try: try:
uuid_delete(api.config["COMPOSER_CFG"], uuid) uuid_delete(api.config["COMPOSER_CFG"], uuid)
@ -1883,7 +1883,7 @@ def v0_api(api):
if status is None: if status is None:
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
if status["queue_status"] not in ["FINISHED", "FAILED"]: if status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, errors=["Build %s not in FINISHED or FAILED state." % uuid]), 400 return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s not in FINISHED or FAILED state." % uuid}]), 400
else: else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=False, logs=False), return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=False, logs=False),
mimetype="application/x-tar", mimetype="application/x-tar",
@ -1903,7 +1903,7 @@ def v0_api(api):
if status is None: if status is None:
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]: elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, errors=["Build %s not in FINISHED or FAILED state." % uuid]), 400 return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s not in FINISHED or FAILED state." % uuid}]), 400
else: else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=True, logs=True), return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=True, image=True, logs=True),
mimetype="application/x-tar", mimetype="application/x-tar",
@ -1923,7 +1923,7 @@ def v0_api(api):
if status is None: if status is None:
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]: elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, errors=["Build %s not in FINISHED or FAILED state." % uuid]), 400 return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s not in FINISHED or FAILED state." % uuid}]), 400
else: else:
return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=False, image=False, logs=True), return Response(uuid_tar(api.config["COMPOSER_CFG"], uuid, metadata=False, image=False, logs=True),
mimetype="application/x-tar", mimetype="application/x-tar",
@ -1943,7 +1943,7 @@ def v0_api(api):
if status is None: if status is None:
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
elif status["queue_status"] not in ["FINISHED", "FAILED"]: elif status["queue_status"] not in ["FINISHED", "FAILED"]:
return jsonify(status=False, errors=["Build %s not in FINISHED or FAILED state." % uuid]), 400 return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s not in FINISHED or FAILED state." % uuid}]), 400
else: else:
image_name, image_path = uuid_image(api.config["COMPOSER_CFG"], uuid) image_name, image_path = uuid_image(api.config["COMPOSER_CFG"], uuid)
@ -1974,7 +1974,7 @@ def v0_api(api):
if status is None: if status is None:
return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400 return jsonify(status=False, errors=["%s is not a valid build uuid" % uuid]), 400
elif status["queue_status"] == "WAITING": elif status["queue_status"] == "WAITING":
return jsonify(status=False, errors=["Build %s has not started yet. No logs to view" % uuid]) return jsonify(status=False, errors=[{"id": BUILD_IN_WRONG_STATE, "msg": "Build %s has not started yet. No logs to view" % uuid}])
try: try:
return Response(uuid_log(api.config["COMPOSER_CFG"], uuid, size), direct_passthrough=True) return Response(uuid_log(api.config["COMPOSER_CFG"], uuid, size), direct_passthrough=True)
except RuntimeError as e: except RuntimeError as e: