From aa0c15ea2bc4222db500bbdbb9e2a4d292f95883 Mon Sep 17 00:00:00 2001 From: Tatsuro Makita Date: Fri, 15 Sep 2017 03:46:57 -0700 Subject: [PATCH] Fixed Mapping Update API returned status 409 with duplicate project * add receive Duplication exception in Mapping Update API and Threshold Update API. Change-Id: I722a81f9c090e3366cab4f07efa2fecc3c430fe1 Closes-bug: #1717487 --- cloudkitty/rating/hash/controllers/mapping.py | 2 ++ cloudkitty/rating/hash/controllers/threshold.py | 2 ++ cloudkitty/rating/hash/db/sqlalchemy/api.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/cloudkitty/rating/hash/controllers/mapping.py b/cloudkitty/rating/hash/controllers/mapping.py index b98ef5b9..c1a074d1 100644 --- a/cloudkitty/rating/hash/controllers/mapping.py +++ b/cloudkitty/rating/hash/controllers/mapping.py @@ -158,6 +158,8 @@ class HashMapMappingsController(rating.RatingRestControllerBase): group_id=mapping.group_id, tenant_id=mapping.tenant_id) pecan.response.headers['Location'] = pecan.request.path + except db_api.MappingAlreadyExists as e: + pecan.abort(409, six.text_type(e)) except db_api.NoSuchMapping as e: pecan.abort(404, six.text_type(e)) except db_api.ClientHashMapError as e: diff --git a/cloudkitty/rating/hash/controllers/threshold.py b/cloudkitty/rating/hash/controllers/threshold.py index c7369923..ce53cb23 100644 --- a/cloudkitty/rating/hash/controllers/threshold.py +++ b/cloudkitty/rating/hash/controllers/threshold.py @@ -158,6 +158,8 @@ class HashMapThresholdsController(rating.RatingRestControllerBase): group_id=threshold.group_id, tenant_id=threshold.tenant_id) pecan.response.headers['Location'] = pecan.request.path + except db_api.ThresholdAlreadyExists as e: + pecan.abort(409, six.text_type(e)) except db_api.NoSuchThreshold as e: pecan.abort(404, six.text_type(e)) except db_api.ClientHashMapError as e: diff --git a/cloudkitty/rating/hash/db/sqlalchemy/api.py b/cloudkitty/rating/hash/db/sqlalchemy/api.py index ee24ce69..a0ed0a8c 100644 --- a/cloudkitty/rating/hash/db/sqlalchemy/api.py +++ b/cloudkitty/rating/hash/db/sqlalchemy/api.py @@ -432,6 +432,14 @@ class HashMap(api.HashMap): else: raise api.ClientHashMapError('No attribute to update.') return mapping_db + except exception.DBDuplicateEntry: + puuid = uuid + ptype = 'Mapping_id' + raise api.MappingAlreadyExists( + value, + puuid, + ptype, + tenant_id=kwargs.get('tenant_id')) except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchMapping(uuid) @@ -465,6 +473,14 @@ class HashMap(api.HashMap): else: raise api.ClientHashMapError('No attribute to update.') return threshold_db + except exception.DBDuplicateEntry: + puuid = uuid + ptype = 'Threshold_id' + raise api.ThresholdAlreadyExists( + value, + puuid, + ptype, + tenant_id=kwargs.get('tenant_id')) except sqlalchemy.orm.exc.NoResultFound: raise api.NoSuchThreshold(uuid)