]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
fix an CFN API and AWS error mapping
authorLiang Chen <cbjchen@cn.ibm.com>
Wed, 12 Jun 2013 13:47:05 +0000 (21:47 +0800)
committerLiang Chen <cbjchen@cn.ibm.com>
Thu, 13 Jun 2013 03:02:59 +0000 (11:02 +0800)
StackExists should return AlreadyExists, not InvalidParameterValue

Fixes bug #1188473

Change-Id: Ia969cddc1b61caa13f4f70bcc29f3160595a779b

heat/api/aws/exception.py
heat/tests/test_api_cfn_v1.py

index 462163c5e302822563a1c4d60357315f6ba5f529..a75463e2733bb460b614c3a23e4b27f0c492b450 100644 (file)
@@ -204,6 +204,15 @@ class HeatThrottlingError(HeatAPIException):
     explanation = "Request was denied due to request throttling"
 
 
+class AlreadyExistsError(HeatAPIException):
+    '''
+    Resource with the name requested already exists
+    '''
+    code = 400
+    title = 'AlreadyExists'
+    explanation = "Resource with the name requested already exists"
+
+
 # Not documented in the AWS docs, authentication failure errors
 class HeatAccessDeniedError(HeatAPIException):
     '''
@@ -252,17 +261,19 @@ def map_remote_error(ex):
             'ResourceNotAvailable',
             'PhysicalResourceNotFound',
             'WatchRuleNotFound',
-            'StackExists',
             'StackValidationFailed',
             'InvalidTemplateReference',
             'UnknownUserParameter',
         )
         denied_errors = ('Forbidden', 'NotAuthorized')
+        already_exists_errors = ('StackExists')
 
         if ex.exc_type in inval_param_errors:
             return HeatInvalidParameterValueError(detail=ex.value)
         elif ex.exc_type in denied_errors:
             return HeatAccessDeniedError(detail=ex.value)
+        elif ex.exc_type in already_exists_errors:
+            return AlreadyExistsError(detail=ex.value)
         else:
             # Map everything else to internal server error for now
             return HeatInternalFailureError(detail=ex.value)
index 130d2682aab1b6272ea3f54c45f645548e9c7d4a..eafff5ff6589312548ce09e98a567335fc8bbab4 100644 (file)
@@ -597,7 +597,7 @@ class CfnStackControllerTest(HeatTestCase):
         result = self.controller.create(dummy_req)
 
         self.assertEqual(type(result),
-                         exception.HeatInvalidParameterValueError)
+                         exception.AlreadyExistsError)
         self.m.VerifyAll()
 
     def test_create_err_engine(self):