Return HTTPBadRequest from circular dependency

We don't map the CircularDependencyException to
a 400 Bad Request in the fault middleware so users
can never get an understand of what is wrong in
their template. They are today instead present
with a 500 internal server error without details
which doesn't help them.

Change-Id: Idc8713b4c29e2534dd7059e4566ac3b777f418e5
This commit is contained in:
Tobias Urdin 2022-11-28 15:12:13 +00:00 committed by Tobias Urdin
parent c253b38e21
commit c13f911ba6
2 changed files with 49 additions and 1 deletions

View File

@ -93,7 +93,8 @@ class FaultWrapper(wsgi.Middleware):
'UnsupportedObjectError': webob.exc.HTTPBadRequest, 'UnsupportedObjectError': webob.exc.HTTPBadRequest,
'ResourceTypeUnavailable': webob.exc.HTTPBadRequest, 'ResourceTypeUnavailable': webob.exc.HTTPBadRequest,
'InvalidBreakPointHook': webob.exc.HTTPBadRequest, 'InvalidBreakPointHook': webob.exc.HTTPBadRequest,
'ImmutableParameterModified': webob.exc.HTTPBadRequest 'ImmutableParameterModified': webob.exc.HTTPBadRequest,
'CircularDependencyException': webob.exc.HTTPBadRequest
} }
def _map_exception_to_error(self, class_exception): def _map_exception_to_error(self, class_exception):

View File

@ -1212,6 +1212,53 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
self.assertEqual('HTTPBadRequest', resp.json['error']['type']) self.assertEqual('HTTPBadRequest', resp.json['error']['type'])
self.assertIsNotNone(resp.json['error']['traceback']) self.assertIsNotNone(resp.json['error']['traceback'])
def test_create_err_circulardep(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
stack_name = "foobar"
template = {u'Foo': u'bar'}
body = {'template': template,
'stack_name': stack_name,
'parameters': {},
'timeout_mins': 30}
req = self._post('/stacks', json.dumps(body))
error = heat_exc.CircularDependencyException(cycle='some data')
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=tools.to_remote_error(error))
resp = tools.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, tenant_id=self.tenant,
body=body)
self.assertEqual(400, resp.json['code'])
self.assertEqual('CircularDependencyException',
resp.json['error']['type'])
mock_call.assert_called_once_with(
req.context,
('create_stack',
{'stack_name': stack_name,
'template': template,
'params': {'parameters': {},
'encrypted_param_names': [],
'parameter_defaults': {},
'event_sinks': [],
'resource_registry': {}},
'files': {},
'environment_files': None,
'files_container': None,
'args': {'timeout_mins': 30},
'owner_id': None,
'nested_depth': 0,
'user_creds_id': None,
'parent_resource_name': None,
'stack_user_project_id': None,
'template_id': None}),
version='1.36'
)
@mock.patch.object(rpc_client.EngineClient, 'call') @mock.patch.object(rpc_client.EngineClient, 'call')
@mock.patch.object(stacks.stacks_view, 'format_stack') @mock.patch.object(stacks.stacks_view, 'format_stack')
def test_preview_stack(self, mock_format, mock_call, mock_enforce): def test_preview_stack(self, mock_format, mock_call, mock_enforce):