From d32a0a517eb622344a59f3e5fd7829c36c4dcab4 Mon Sep 17 00:00:00 2001 From: Kamal Hussain Date: Thu, 11 Feb 2016 15:25:45 -0600 Subject: [PATCH] Map RequestLimitExceeded exception in heat-cfn-api The heat-cfn-api wasn't handling the RequestLimitExceeded error. Instead it returned generic "Internal Server Error". The fix is to correctly map RequestLimitedExceeded exception in heat-cfn-api. Added unit test to verify mapping of RequestLimitExceeded error. Change-Id: I6e13b2f6b1458fb7c194632db67eb2cebdb173d2 Closes-Bug: #1542559 --- heat/api/aws/exception.py | 12 ++++++++++++ heat/tests/api/aws/test_api_aws.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index cd27303d23..29b96206b5 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -273,6 +273,15 @@ class HeatActionInProgressError(HeatAPIException): "in progress") +class HeatRequestLimitExceeded(HeatAPIException): + + """Payload size of the request exceeds maximum allowed size.""" + + code = 400 + title = 'RequestLimitExceeded' + explanation = _("Payload exceeds maximum allowed size") + + def map_remote_error(ex): """Map rpc_common.RemoteError exceptions to HeatAPIException subclasses. @@ -306,6 +315,7 @@ def map_remote_error(ex): denied_errors = ('Forbidden', 'NotAuthorized') already_exists_errors = ('StackExists') invalid_action_errors = ('ActionInProgress',) + request_limit_exceeded = ('RequestLimitExceeded') ex_type = ex.__class__.__name__ @@ -320,6 +330,8 @@ def map_remote_error(ex): return AlreadyExistsError(detail=six.text_type(ex)) elif ex_type in invalid_action_errors: return HeatActionInProgressError(detail=six.text_type(ex)) + elif ex_type in request_limit_exceeded: + return HeatRequestLimitExceeded(detail=six.text_type(ex)) else: # Map everything else to internal server error for now return HeatInternalFailureError(detail=six.text_type(ex)) diff --git a/heat/tests/api/aws/test_api_aws.py b/heat/tests/api/aws/test_api_aws.py index 50f7e345be..d36b26bf43 100644 --- a/heat/tests/api/aws/test_api_aws.py +++ b/heat/tests/api/aws/test_api_aws.py @@ -218,3 +218,8 @@ class AWSCommonTest(common.HeatTestCase): action="testing") expected = aws_exception.HeatActionInProgressError self.assertIsInstance(aws_exception.map_remote_error(ex), expected) + + def test_map_remote_error_request_limit_exceeded(self): + ex = common_exception.RequestLimitExceeded(message="testing") + expected = aws_exception.HeatRequestLimitExceeded + self.assertIsInstance(aws_exception.map_remote_error(ex), expected)