From 37ebc4f02d31257e5f53b698529c84798917eba9 Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Tue, 24 Jan 2017 15:12:51 +0800 Subject: [PATCH] Raise correct error instead of class exist in Placement API When create resource class using placement API, and at the DB layer, we have a retry logic for 100 loop, and error will raise when the retry limit exceed, currently a log about limit exceed is generated but a ResourceClassExists Error is raised, which is a little bit weird and might confuse the users. We'd better add a particular Exception for this kind of scenario and it could be used in other places also. Co-Authored-By: huangtianhua@huawei.com Closes-Bug: #1658868 Change-Id: I89156be82ad520bdeacb12b31b44e7170b77ce3f --- nova/api/openstack/placement/handlers/resource_class.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nova/api/openstack/placement/handlers/resource_class.py b/nova/api/openstack/placement/handlers/resource_class.py index affdd0f31..7b637964c 100644 --- a/nova/api/openstack/placement/handlers/resource_class.py +++ b/nova/api/openstack/placement/handlers/resource_class.py @@ -83,6 +83,13 @@ def create_resource_class(req): _('Conflicting resource class already exists: %(name)s') % {'name': data['name']}, json_formatter=util.json_error_formatter) + except exception.MaxDBRetriesExceeded: + raise webob.exc.HTTPConflict( + _('Max retries of DB transaction exceeded attempting ' + 'to create resource class: %(name)s, please' + 'try again.') % + {'name': data['name']}, + json_formatter=util.json_error_formatter) req.response.location = util.resource_class_url(req.environ, rc) req.response.status = 201