Use EntityNotFound instead of StackNotFound.

replace and remove StackNotFound

Change-Id: I0bf4e35e4acf8bcfdd933c7fb862c63f7550f6c2
Partial-Bug: #1515603
This commit is contained in:
ricolin 2015-11-12 21:58:16 +08:00
parent 3f6a109b0f
commit 220e44a3ac
14 changed files with 58 additions and 58 deletions

View File

@ -284,7 +284,7 @@ def map_remote_error(ex):
'AttributeError',
'ValueError',
'InvalidTenant',
'StackNotFound',
'EntityNotFound',
'ResourceActionNotSupported',
'ResourceNotFound',
'ResourceNotAvailable',

View File

@ -57,7 +57,6 @@ class FaultWrapper(wsgi.Middleware):
'ActionInProgress': webob.exc.HTTPConflict,
'ValueError': webob.exc.HTTPBadRequest,
'EntityNotFound': webob.exc.HTTPNotFound,
'StackNotFound': webob.exc.HTTPNotFound,
'NotFound': webob.exc.HTTPNotFound,
'ResourceActionNotSupported': webob.exc.HTTPBadRequest,
'ResourceNotFound': webob.exc.HTTPNotFound,

View File

@ -149,10 +149,6 @@ class InvalidTenant(HeatException):
"from Tenant %(actual)s forbidden.")
class StackNotFound(HeatException):
msg_fmt = _("The Stack (%(stack_name)s) could not be found.")
class StackExists(HeatException):
msg_fmt = _("The Stack (%(stack_name)s) already exists.")

View File

@ -439,7 +439,7 @@ class EngineService(service.Service):
stack = parser.Stack.load(cnxt, stack=s)
return dict(stack.identifier())
else:
raise exception.StackNotFound(stack_name=stack_name)
raise exception.EntityNotFound(entity='Stack', name=stack_name)
def _get_stack(self, cnxt, stack_identity, show_deleted=False):
identity = identifier.HeatIdentifier(**stack_identity)
@ -451,7 +451,8 @@ class EngineService(service.Service):
eager_load=True)
if s is None:
raise exception.StackNotFound(stack_name=identity.stack_name)
raise exception.EntityNotFound(entity='Stack',
name=identity.stack_name)
if cnxt.tenant_id not in (identity.tenant, s.stack_user_project_id):
# The DB API should not allow this, but sanity-check anyway..
@ -459,7 +460,8 @@ class EngineService(service.Service):
actual=cnxt.tenant_id)
if identity.path or s.name != identity.stack_name:
raise exception.StackNotFound(stack_name=identity.stack_name)
raise exception.EntityNotFound(entity='Stack',
name=identity.stack_name)
return s

View File

@ -488,7 +488,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -934,7 +934,7 @@ class CfnStackControllerTest(common.HeatTestCase):
rpc_client.EngineClient.call(
dummy_req.context,
('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1011,7 +1011,7 @@ class CfnStackControllerTest(common.HeatTestCase):
rpc_client.EngineClient.call(
dummy_req.context,
('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1159,7 +1159,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1267,7 +1267,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1354,7 +1354,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1469,7 +1469,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()
@ -1650,7 +1650,7 @@ class CfnStackControllerTest(common.HeatTestCase):
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
dummy_req.context, ('identify_stack', {'stack_name': stack_name})
).AndRaise(heat_exception.StackNotFound(stack_name='test'))
).AndRaise(heat_exception.EntityNotFound(entity='Stack', name='test'))
self.m.ReplayAll()

View File

@ -291,7 +291,7 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
'limit': None, 'sort_keys': None, 'marker': None,
'sort_dir': None, 'filters': None}
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -307,7 +307,7 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=stack_identity.stack_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_index_err_denied_policy(self, mock_enforce):
@ -565,7 +565,7 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
'limit': None, 'sort_keys': None, 'marker': None,
'sort_dir': None, 'filters': {'resource_name': res_name}}
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context, ('list_events', kwargs)
@ -582,7 +582,7 @@ class EventControllerTest(tools.ControllerTest, common.HeatTestCase):
event_id=event_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_show_err_denied_policy(self, mock_enforce):

View File

@ -108,7 +108,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get(stack_identity._tenant_path() + '/resources')
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -127,7 +127,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=stack_identity.stack_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_index_nested_depth(self, mock_enforce):
@ -391,7 +391,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get(res_identity._tenant_path())
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -411,7 +411,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
resource_name=res_name)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_show_with_single_attribute(self, mock_enforce):
@ -597,7 +597,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get(res_identity._tenant_path() + '/metadata')
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -617,7 +617,7 @@ class ResourceControllerTest(tools.ControllerTest, common.HeatTestCase):
resource_name=res_name)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_metadata_show_nonexist_resource(self, mock_enforce):

View File

@ -1284,7 +1284,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get('/stacks/%(stack_name)s' % {
'stack_name': stack_name})
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -1298,7 +1298,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_name=stack_name)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_lookup_err_policy(self, mock_enforce):
@ -1346,7 +1346,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get('/stacks/%(stack_name)s/resources' % {
'stack_name': stack_name})
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -1361,7 +1361,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
path='resources')
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_lookup_resource_err_denied_policy(self, mock_enforce):
@ -1454,7 +1454,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -1469,7 +1469,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=identity.stack_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_show_invalidtenant(self, mock_enforce):
@ -1546,7 +1546,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -1562,7 +1562,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=identity.stack_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_update(self, mock_enforce):
@ -1651,7 +1651,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._put('/stacks/%(stack_name)s/%(stack_id)s' % identity,
json.dumps(body))
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
rpc_client.EngineClient.call(
req.context,
@ -1675,7 +1675,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
body=body)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_update_timeout_not_int(self, mock_enforce):
@ -2054,7 +2054,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
req = self._delete('/stacks/%(stack_name)s/%(stack_id)s' % identity)
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
# Engine returns None when delete successful
rpc_client.EngineClient.call(
@ -2070,7 +2070,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=identity.stack_id)
self.assertEqual(404, resp.json['code'])
self.assertEqual('StackNotFound', resp.json['error']['type'])
self.assertEqual('EntityNotFound', resp.json['error']['type'])
self.m.VerifyAll()
def test_validate_template(self, mock_enforce):

View File

@ -83,7 +83,7 @@ class StackServiceActionsTest(common.HeatTestCase):
ex = self.assertRaises(dispatcher.ExpectedException,
self.man.stack_suspend, self.ctx,
stk.identifier())
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
def test_stack_resume_nonexist(self):
stack_name = 'service_resume_nonexist_test_stack'
@ -94,7 +94,7 @@ class StackServiceActionsTest(common.HeatTestCase):
ex = self.assertRaises(dispatcher.ExpectedException,
self.man.stack_resume, self.ctx,
stk.identifier())
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
def _mock_thread_start(self, stack_id, func, *args, **kwargs):
func(*args, **kwargs)

View File

@ -52,7 +52,7 @@ class StackDeleteTest(common.HeatTestCase):
ex = self.assertRaises(dispatcher.ExpectedException,
self.man.delete_stack,
self.ctx, stack.identifier())
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
@mock.patch.object(parser.Stack, 'load')
@mock.patch.object(stack_lock.StackLock, 'try_acquire')

View File

@ -97,12 +97,13 @@ class StackResourcesServiceTest(common.HeatTestCase):
non_exist_identifier = identifier.HeatIdentifier(
self.ctx.tenant_id, 'wibble',
'18d06e2e-44d3-4bef-9fbf-52480d604b02')
mock_get.side_effect = exception.StackNotFound(stack_name='test')
mock_get.side_effect = exception.EntityNotFound(
entity='Stack', name='test')
ex = self.assertRaises(dispatcher.ExpectedException,
self.eng.describe_stack_resource,
self.ctx, non_exist_identifier, 'WebServer')
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
mock_get.assert_called_once_with(self.ctx, non_exist_identifier)
@mock.patch.object(stack.Stack, 'load')
@ -191,7 +192,7 @@ class StackResourcesServiceTest(common.HeatTestCase):
ex = self.assertRaises(dispatcher.ExpectedException,
self.eng.describe_stack_resources,
self.ctx, non_exist_identifier, 'WebServer')
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
@tools.stack_context('find_phys_res_stack')
def test_find_physical_resource(self):
@ -273,12 +274,13 @@ class StackResourcesServiceTest(common.HeatTestCase):
non_exist_identifier = identifier.HeatIdentifier(
self.ctx.tenant_id, 'wibble',
'18d06e2e-44d3-4bef-9fbf-52480d604b02')
mock_get.side_effect = exception.StackNotFound(stack_name='test')
mock_get.side_effect = exception.EntityNotFound(entity='Stack',
name='test')
ex = self.assertRaises(dispatcher.ExpectedException,
self.eng.list_stack_resources,
self.ctx, non_exist_identifier)
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
mock_get.assert_called_once_with(self.ctx, non_exist_identifier,
show_deleted=True)

View File

@ -554,7 +554,7 @@ class ServiceStackUpdateTest(common.HeatTestCase):
self.man.update_stack,
self.ctx, stk.identifier(), template,
params, None, {})
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
def test_stack_update_no_credentials(self):
cfg.CONF.set_default('deferred_auth_method', 'password')

View File

@ -450,7 +450,7 @@ class StackServiceTest(common.HeatTestCase):
def test_stack_identify_nonexist(self):
ex = self.assertRaises(dispatcher.ExpectedException,
self.eng.identify_stack, self.ctx, 'wibble')
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
@tools.stack_context('service_create_existing_test_stack', False)
def test_stack_create_existing(self):
@ -853,7 +853,8 @@ class StackServiceTest(common.HeatTestCase):
self.ctx.tenant_id, 'wibble',
'18d06e2e-44d3-4bef-9fbf-52480d604b02')
stack_not_found_exc = exception.StackNotFound(stack_name='test')
stack_not_found_exc = exception.EntityNotFound(
entity='Stack', name='test')
self.m.StubOutWithMock(service.EngineService, '_get_stack')
service.EngineService._get_stack(
self.ctx, non_exist_identifier,
@ -863,7 +864,7 @@ class StackServiceTest(common.HeatTestCase):
ex = self.assertRaises(dispatcher.ExpectedException,
self.eng.show_stack,
self.ctx, non_exist_identifier)
self.assertEqual(exception.StackNotFound, ex.exc_info[0])
self.assertEqual(exception.EntityNotFound, ex.exc_info[0])
self.m.VerifyAll()
def test_stack_describe_bad_tenant(self):

View File

@ -26,7 +26,7 @@ from heat.common.i18n import _
from heat.tests import common
class StackNotFoundChild(heat_exc.StackNotFound):
class StackNotFoundChild(heat_exc.EntityNotFound):
pass
@ -70,11 +70,11 @@ class FaultMiddlewareTest(common.HeatTestCase):
def test_openstack_exception_with_kwargs(self):
wrapper = fault.FaultWrapper(None)
msg = wrapper._error(heat_exc.StackNotFound(stack_name='a'))
msg = wrapper._error(heat_exc.EntityNotFound(entity='Stack', name='a'))
expected = {'code': 404,
'error': {'message': 'The Stack (a) could not be found.',
'traceback': None,
'type': 'StackNotFound'},
'type': 'EntityNotFound'},
'explanation': 'The resource could not be found.',
'title': 'Not Found'}
self.assertEqual(expected, msg)
@ -116,7 +116,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
def test_remote_exception(self):
# We want tracebacks
cfg.CONF.set_override('debug', True)
error = heat_exc.StackNotFound(stack_name='a')
error = heat_exc.EntityNotFound(entity='Stack', name='a')
exc_info = (type(error), error, None)
serialized = rpc_common.serialize_remote_exception(exc_info)
remote_error = rpc_common.deserialize_remote_exception(
@ -128,7 +128,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
expected = {'code': 404,
'error': {'message': expected_message,
'traceback': expected_traceback,
'type': 'StackNotFound'},
'type': 'EntityNotFound'},
'explanation': 'The resource could not be found.',
'title': 'Not Found'}
self.assertEqual(expected, msg)
@ -194,7 +194,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
def test_should_not_ignore_parent_classes(self):
wrapper = fault.FaultWrapper(None)
msg = wrapper._error(StackNotFoundChild(stack_name='a'))
msg = wrapper._error(StackNotFoundChild(entity='Stack', name='a'))
expected = {'code': 404,
'error': {'message': 'The Stack (a) could not be found.',
'traceback': None,
@ -224,7 +224,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
# We want tracebacks
cfg.CONF.set_override('debug', True)
error = StackNotFoundChild(stack_name='a')
error = StackNotFoundChild(entity='Stack', name='a')
exc_info = (type(error), error, None)
serialized = rpc_common.serialize_remote_exception(exc_info)
remote_error = rpc_common.deserialize_remote_exception(