[placement] add error.code on a ConcurrentUpdateDetected
A pending api-sig guideline I473918ce9c6b49c0b904e93b7140421525f4e7c0 reflects discussion amongst various parties that adding error codes to structured error responses should not be considered a breaking API change. Given that, it is simply "okay" to add them. This change adds errors.CONCURRENT_UPDATE wherever the ConcurrentUpdateDetected results in an HTTPConflict (409) response. In practice this means that if microversion 1.23 or beyond is being used, there will be a code in any error response, and for some 409 responses that code will be `placement.concurrent_update`. Note that because we haven't instrumented a way to cause a truly concurrent update, we've never had real tests for this kind of thing. Change-Id: I5a164a0ee298846231113ad7b62b82a3e8f1f409
This commit is contained in:
parent
d3fa585f5e
commit
c5cdef24ed
|
@ -17,6 +17,7 @@ from oslo_utils import encodeutils
|
|||
from oslo_utils import timeutils
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.placement import errors
|
||||
from nova.api.openstack.placement import exception
|
||||
from nova.api.openstack.placement import microversion
|
||||
from nova.api.openstack.placement.objects import resource_provider as rp_obj
|
||||
|
@ -69,8 +70,11 @@ def _set_aggregates(resource_provider, aggregate_uuids,
|
|||
try:
|
||||
resource_provider.set_aggregates(
|
||||
aggregate_uuids, increment_generation=increment_generation)
|
||||
except (exception.ConcurrentUpdateDetected,
|
||||
db_exc.DBDuplicateEntry) as exc:
|
||||
except exception.ConcurrentUpdateDetected as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Update conflict: %(error)s') % {'error': exc},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Update conflict: %(error)s') % {'error': exc})
|
||||
|
||||
|
|
|
@ -202,7 +202,8 @@ def create_inventory(req):
|
|||
except (exception.ConcurrentUpdateDetected,
|
||||
db_exc.DBDuplicateEntry) as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Update conflict: %(error)s') % {'error': exc})
|
||||
_('Update conflict: %(error)s') % {'error': exc},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except (exception.InvalidInventoryCapacity,
|
||||
exception.NotFound) as exc:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
|
@ -239,7 +240,8 @@ def delete_inventory(req):
|
|||
exception.InventoryInUse) as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Unable to delete inventory of class %(class)s: %(error)s') %
|
||||
{'class': resource_class, 'error': exc})
|
||||
{'class': resource_class, 'error': exc},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except exception.NotFound as exc:
|
||||
raise webob.exc.HTTPNotFound(
|
||||
_('No inventory of class %(class)s found for delete: %(error)s') %
|
||||
|
@ -356,7 +358,8 @@ def set_inventories(req):
|
|||
except (exception.ConcurrentUpdateDetected,
|
||||
db_exc.DBDuplicateEntry) as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('update conflict: %(error)s') % {'error': exc})
|
||||
_('update conflict: %(error)s') % {'error': exc},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except exception.InventoryInUse as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('update conflict: %(error)s') % {'error': exc},
|
||||
|
@ -395,7 +398,8 @@ def delete_inventories(req):
|
|||
_('Unable to delete inventory for resource provider '
|
||||
'%(rp_uuid)s because the inventory was updated by '
|
||||
'another process. Please retry your request.')
|
||||
% {'rp_uuid': resource_provider.uuid})
|
||||
% {'rp_uuid': resource_provider.uuid},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except exception.InventoryInUse as ex:
|
||||
# NOTE(mriedem): This message cannot change without impacting the
|
||||
# nova.scheduler.client.report._RE_INV_IN_USE regex.
|
||||
|
@ -445,7 +449,8 @@ def update_inventory(req):
|
|||
except (exception.ConcurrentUpdateDetected,
|
||||
db_exc.DBDuplicateEntry) as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('update conflict: %(error)s') % {'error': exc})
|
||||
_('update conflict: %(error)s') % {'error': exc},
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
except exception.InventoryWithResourceClassNotFound as exc:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
_('No inventory record with resource class for resource provider '
|
||||
|
|
|
@ -17,6 +17,7 @@ from oslo_utils import encodeutils
|
|||
from oslo_utils import timeutils
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.placement import errors
|
||||
from nova.api.openstack.placement import exception
|
||||
from nova.api.openstack.placement import microversion
|
||||
from nova.api.openstack.placement.objects import resource_provider as rp_obj
|
||||
|
@ -260,7 +261,8 @@ def delete_traits_for_resource_provider(req):
|
|||
try:
|
||||
resource_provider.set_traits(rp_obj.TraitList(objects=[]))
|
||||
except exception.ConcurrentUpdateDetected as e:
|
||||
raise webob.exc.HTTPConflict(e.format_message())
|
||||
raise webob.exc.HTTPConflict(e.format_message(),
|
||||
comment=errors.CONCURRENT_UPDATE)
|
||||
|
||||
req.response.status = 204
|
||||
req.response.content_type = None
|
||||
|
|
Loading…
Reference in New Issue