Merge "Resource_provider API handler does not return specific error codes"
This commit is contained in:
commit
6ca30fd832
|
@ -41,3 +41,7 @@ URI.
|
|||
DEFAULT = 'placement.undefined_code'
|
||||
INVENTORY_INUSE = 'placement.inventory.inuse'
|
||||
CONCURRENT_UPDATE = 'placement.concurrent_update'
|
||||
DUPLICATE_NAME = 'placement.duplicate_name'
|
||||
PROVIDER_IN_USE = 'placement.resource_provider.inuse'
|
||||
PROVIDER_CANNOT_DELETE_PARENT = (
|
||||
'placement.resource_provider.cannot_delete_parent')
|
||||
|
|
|
@ -18,6 +18,7 @@ from oslo_utils import timeutils
|
|||
from oslo_utils import uuidutils
|
||||
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
|
||||
|
@ -98,7 +99,8 @@ def create_resource_provider(req):
|
|||
for column in exc.columns])
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Conflicting resource provider %(duplicate)s already exists.') %
|
||||
{'duplicate': duplicate})
|
||||
{'duplicate': duplicate},
|
||||
comment=errors.DUPLICATE_NAME)
|
||||
except exception.ObjectActionError as exc:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
_('Unable to create resource provider "%(name)s", %(rp_uuid)s: '
|
||||
|
@ -137,14 +139,16 @@ def delete_resource_provider(req):
|
|||
except exception.ResourceProviderInUse as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Unable to delete resource provider %(rp_uuid)s: %(error)s') %
|
||||
{'rp_uuid': uuid, 'error': exc})
|
||||
{'rp_uuid': uuid, 'error': exc},
|
||||
comment=errors.PROVIDER_IN_USE)
|
||||
except exception.NotFound as exc:
|
||||
raise webob.exc.HTTPNotFound(
|
||||
_("No resource provider with uuid %s found for delete") % uuid)
|
||||
except exception.CannotDeleteParentResourceProvider as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_("Unable to delete parent resource provider %(rp_uuid)s: "
|
||||
"It has child resource providers.") % {'rp_uuid': uuid})
|
||||
"It has child resource providers.") % {'rp_uuid': uuid},
|
||||
comment=errors.PROVIDER_CANNOT_DELETE_PARENT)
|
||||
req.response.status = 204
|
||||
req.response.content_type = None
|
||||
return req.response
|
||||
|
@ -275,7 +279,8 @@ def update_resource_provider(req):
|
|||
except db_exc.DBDuplicateEntry as exc:
|
||||
raise webob.exc.HTTPConflict(
|
||||
_('Conflicting resource provider %(name)s already exists.') %
|
||||
{'name': data['name']})
|
||||
{'name': data['name']},
|
||||
comment=errors.DUPLICATE_NAME)
|
||||
except exception.ObjectActionError as exc:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
_('Unable to save resource provider %(rp_uuid)s: %(error)s') %
|
||||
|
|
|
@ -144,6 +144,19 @@ tests:
|
|||
DISK_GB: 10
|
||||
status: 204
|
||||
|
||||
- name: fail to delete that provider
|
||||
DELETE: /resource_providers/$ENVIRON['RP_UUID']
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
# we need this microversion to get error codes in the response
|
||||
openstack-api-version: placement 1.23
|
||||
status: 409
|
||||
response_strings:
|
||||
- "Unable to delete resource provider $ENVIRON['RP_UUID']"
|
||||
response_json_paths:
|
||||
errors[0].code: placement.resource_provider.inuse
|
||||
|
||||
|
||||
- name: put an allocation different consumer
|
||||
PUT: /allocations/39715579-2167-4c63-8247-301311cc6703
|
||||
request_headers:
|
||||
|
|
|
@ -103,6 +103,7 @@ tests:
|
|||
- "Conflicting resource provider name: $ENVIRON['RP_NAME'] already exists"
|
||||
response_json_paths:
|
||||
$.errors[0].title: Conflict
|
||||
$.errors[0].code: placement.duplicate_name
|
||||
|
||||
- name: confirm the correct post
|
||||
GET: /resource_providers/$ENVIRON['RP_UUID']
|
||||
|
@ -394,6 +395,8 @@ tests:
|
|||
response_strings:
|
||||
- "Unable to delete parent resource provider
|
||||
$ENVIRON['PARENT_PROVIDER_UUID']: It has child resource providers."
|
||||
response_json_paths:
|
||||
$.errors[0].code: placement.resource_provider.cannot_delete_parent
|
||||
|
||||
- name: list all resource providers in a tree that does not exist
|
||||
GET: /resource_providers?in_tree=$ENVIRON['ALT_PARENT_PROVIDER_UUID']
|
||||
|
@ -620,6 +623,7 @@ tests:
|
|||
status: 409
|
||||
response_json_paths:
|
||||
$.errors[0].title: Conflict
|
||||
$.errors[0].code: placement.duplicate_name
|
||||
|
||||
- name: fail to put that provider with uuid
|
||||
PUT: $LAST_URL
|
||||
|
|
Loading…
Reference in New Issue