Expose placement exception code to end users
Attempting to create an existing host already in DB resulted in a 409 Conflict response status code in the Rocky release. However, on the current master, using the placement API support has changed it to return a 500 Internal Server Error. This patch changes it back to 409 by bubbling up the exception code occured in the placement resource provider creation. Change-Id: I5c02a8fe9a83adf83358062fcc5470e38e643550 Closes-Bug: #1812642
This commit is contained in:
parent
8192ac8f06
commit
2bd5b65118
|
@ -26,6 +26,7 @@ from blazar.db import exceptions as db_exceptions
|
||||||
from blazar import exceptions as ex
|
from blazar import exceptions as ex
|
||||||
from blazar.i18n import _
|
from blazar.i18n import _
|
||||||
from blazar.manager import exceptions as manager_exceptions
|
from blazar.manager import exceptions as manager_exceptions
|
||||||
|
from blazar.utils.openstack import exceptions as opst_exceptions
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -88,6 +89,8 @@ class Rest(flask.Blueprint):
|
||||||
# Get the exception from manager and common exceptions
|
# Get the exception from manager and common exceptions
|
||||||
cls = getattr(manager_exceptions, e.exc_type,
|
cls = getattr(manager_exceptions, e.exc_type,
|
||||||
getattr(ex, e.exc_type, None))
|
getattr(ex, e.exc_type, None))
|
||||||
|
cls = cls or getattr(opst_exceptions, e.exc_type,
|
||||||
|
getattr(ex, e.exc_type, None))
|
||||||
if cls is not None:
|
if cls is not None:
|
||||||
return render_error_message(cls.code, e.value,
|
return render_error_message(cls.code, e.value,
|
||||||
cls.code)
|
cls.code)
|
||||||
|
|
|
@ -23,6 +23,11 @@ class ResourceProviderCreationFailed(exceptions.BlazarException):
|
||||||
msg_fmt = _("Failed to create resource provider %(name)s")
|
msg_fmt = _("Failed to create resource provider %(name)s")
|
||||||
|
|
||||||
|
|
||||||
|
class ResourceProviderCreationConflict(exceptions.BlazarException):
|
||||||
|
code = 409
|
||||||
|
msg_fmt = _("Conflict on creating resource provider %(name)s ")
|
||||||
|
|
||||||
|
|
||||||
class ResourceProviderDeletionFailed(exceptions.BlazarException):
|
class ResourceProviderDeletionFailed(exceptions.BlazarException):
|
||||||
msg_fmt = _("Failed to delete resource provider %(uuid)s")
|
msg_fmt = _("Failed to delete resource provider %(uuid)s")
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,17 @@ class BlazarPlacementClient(object):
|
||||||
LOG.info(msg, args)
|
LOG.info(msg, args)
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
if resp.status_code == 409:
|
||||||
|
msg = ("Conflict on creating resource provider %(name)s in "
|
||||||
|
"placement API. Got %(status_code)d: %(err_text)s.")
|
||||||
|
args = {
|
||||||
|
'name': rp_name,
|
||||||
|
'status_code': resp.status_code,
|
||||||
|
'err_text': resp.text,
|
||||||
|
}
|
||||||
|
LOG.error(msg, args)
|
||||||
|
raise exceptions.ResourceProviderCreationConflict(name=rp_name)
|
||||||
|
|
||||||
msg = ("Failed to create resource provider record in placement API "
|
msg = ("Failed to create resource provider record in placement API "
|
||||||
"for resource provider %(name)s. "
|
"for resource provider %(name)s. "
|
||||||
"Got %(status_code)d: %(err_text)s.")
|
"Got %(status_code)d: %(err_text)s.")
|
||||||
|
|
Loading…
Reference in New Issue