RPC API: Add a StackNotFound exception
Change-Id: Ic109e9f6f5cca3af531ffcd2c9149742442e66d4 Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
parent
c41ff7e141
commit
764f6ace97
|
@ -247,6 +247,7 @@ def map_remote_error(ex):
|
|||
'AttributeError',
|
||||
'ValueError',
|
||||
'InvalidTenant',
|
||||
'StackNotFound',
|
||||
)
|
||||
|
||||
if ex.exc_type in inval_param_errors:
|
||||
|
|
|
@ -91,6 +91,7 @@ def remote_error(ex, force_exists=False):
|
|||
error_map = {
|
||||
'AttributeError': client_error,
|
||||
'ValueError': client_error,
|
||||
'StackNotFound': exc.HTTPNotFound,
|
||||
'InvalidTenant': exc.HTTPForbidden,
|
||||
}
|
||||
|
||||
|
|
|
@ -207,3 +207,7 @@ class ImageNotFound(OpenstackException):
|
|||
class InvalidTenant(OpenstackException):
|
||||
message = _("Searching Tenant %(target)s "
|
||||
"from Tenant %(actual)s forbidden.")
|
||||
|
||||
|
||||
class StackNotFound(OpenstackException):
|
||||
message = _("The Stack (%(stack_name)s) could not be found.")
|
||||
|
|
|
@ -122,7 +122,7 @@ class EngineService(service.Service):
|
|||
stack = parser.Stack.load(context, stack=s)
|
||||
return dict(stack.identifier())
|
||||
else:
|
||||
raise AttributeError('Unknown stack name')
|
||||
raise exception.StackNotFound(stack_name=stack_name)
|
||||
|
||||
def _get_stack(self, context, stack_identity):
|
||||
identity = identifier.HeatIdentifier(**stack_identity)
|
||||
|
@ -134,10 +134,10 @@ class EngineService(service.Service):
|
|||
s = db_api.stack_get(context, identity.stack_id)
|
||||
|
||||
if s is None:
|
||||
raise AttributeError('Stack not found')
|
||||
raise exception.StackNotFound(stack_name=identity.stack_name)
|
||||
|
||||
if identity.path or s.name != identity.stack_name:
|
||||
raise AttributeError('Invalid stack ID')
|
||||
raise exception.StackNotFound(stack_name=identity.stack_name)
|
||||
|
||||
return s
|
||||
|
||||
|
|
|
@ -374,7 +374,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -586,7 +586,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -668,7 +668,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -791,7 +791,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -893,7 +893,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -967,6 +967,29 @@ class StackControllerTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(response, expected)
|
||||
|
||||
def test_describe_stack_resource_nonexistent_stack(self):
|
||||
# Format a dummy request
|
||||
stack_name = "wibble"
|
||||
identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
|
||||
params = {'Action': 'DescribeStackResource',
|
||||
'StackName': stack_name,
|
||||
'LogicalResourceId': "WikiDatabase"}
|
||||
dummy_req = self._dummy_GET_request(params)
|
||||
|
||||
# Stub out the RPC call to the engine with a pre-canned response
|
||||
self.m.StubOutWithMock(rpc, 'call')
|
||||
rpc.call(dummy_req.context, self.topic,
|
||||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
result = self.controller.describe_stack_resource(dummy_req)
|
||||
self.assertEqual(type(result),
|
||||
exception.HeatInvalidParameterValueError)
|
||||
|
||||
def test_describe_stack_resources(self):
|
||||
# Format a dummy request
|
||||
stack_name = "wordpress"
|
||||
|
@ -1046,7 +1069,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -1199,7 +1222,7 @@ class StackControllerTest(unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version}, None
|
||||
).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup,
|
||||
|
@ -483,7 +483,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'identify_stack',
|
||||
'args': {'stack_name': stack_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup,
|
||||
|
@ -558,8 +558,8 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
self.assertEqual(response, expected)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_show_aterr(self):
|
||||
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
|
||||
def test_show_notfound(self):
|
||||
identity = identifier.HeatIdentifier(self.tenant, 'wibble', '6')
|
||||
|
||||
req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)
|
||||
|
||||
|
@ -568,7 +568,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'show_stack',
|
||||
'args': {'stack_identity': dict(identity)},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -618,7 +618,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
self.assertEqual(response, template)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_get_template_err_rpcerr(self):
|
||||
def test_get_template_err_notfound(self):
|
||||
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
|
||||
req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)
|
||||
template = {u'Foo': u'bar'}
|
||||
|
@ -628,7 +628,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'get_template',
|
||||
'args': {'stack_identity': dict(identity)},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
|
@ -692,7 +692,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
'params': parameters,
|
||||
'args': {'timeout_mins': 30}},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -747,7 +747,7 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'delete_stack',
|
||||
'args': {'stack_identity': dict(identity)},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -926,7 +926,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'list_stack_resources',
|
||||
'args': {'stack_identity': stack_identity},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -1008,7 +1008,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase):
|
|||
'args': {'stack_identity': stack_identity,
|
||||
'resource_name': res_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -1076,7 +1076,7 @@ class ResourceControllerTest(ControllerTest, unittest.TestCase):
|
|||
'args': {'stack_identity': stack_identity,
|
||||
'resource_name': res_name},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -1246,7 +1246,7 @@ class EventControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'list_events',
|
||||
'args': {'stack_identity': stack_identity},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
@ -1477,7 +1477,7 @@ class EventControllerTest(ControllerTest, unittest.TestCase):
|
|||
{'method': 'list_events',
|
||||
'args': {'stack_identity': stack_identity},
|
||||
'version': self.api_version},
|
||||
None).AndRaise(rpc_common.RemoteError("AttributeError"))
|
||||
None).AndRaise(rpc_common.RemoteError("StackNotFound"))
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
|
|
|
@ -260,7 +260,7 @@ class stackServiceCreateUpdateDeleteTest(unittest.TestCase):
|
|||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.delete_stack,
|
||||
self.ctx, stack.identifier())
|
||||
self.m.VerifyAll()
|
||||
|
@ -347,7 +347,7 @@ class stackServiceCreateUpdateDeleteTest(unittest.TestCase):
|
|||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.update_stack,
|
||||
self.ctx, stack.identifier(), template, params, {})
|
||||
self.m.VerifyAll()
|
||||
|
@ -408,7 +408,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
self.assertEqual(identity, self.stack_identity)
|
||||
|
||||
def test_stack_identify_nonexist(self):
|
||||
self.assertRaises(AttributeError, self.man.identify_stack,
|
||||
self.assertRaises(exception.StackNotFound, self.man.identify_stack,
|
||||
self.ctx, 'wibble')
|
||||
|
||||
def test_stack_create_existing(self):
|
||||
|
@ -492,7 +492,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
def test_stack_describe_nonexistent(self):
|
||||
nonexist = dict(self.stack_identity)
|
||||
nonexist['stack_name'] = 'wibble'
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.show_stack,
|
||||
self.ctx, nonexist)
|
||||
|
||||
|
@ -575,7 +575,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
def test_stack_resource_describe_nonexist_stack(self):
|
||||
nonexist = dict(self.stack_identity)
|
||||
nonexist['stack_name'] = 'foo'
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.describe_stack_resource,
|
||||
self.ctx, nonexist, 'WebServer')
|
||||
|
||||
|
@ -623,7 +623,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
def test_stack_resources_describe_nonexist_stack(self):
|
||||
nonexist = dict(self.stack_identity)
|
||||
nonexist['stack_name'] = 'foo'
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.describe_stack_resources,
|
||||
self.ctx, nonexist, 'WebServer')
|
||||
|
||||
|
@ -662,7 +662,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
def test_stack_resources_list_nonexist_stack(self):
|
||||
nonexist = dict(self.stack_identity)
|
||||
nonexist['stack_name'] = 'foo'
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.list_stack_resources,
|
||||
self.ctx, nonexist)
|
||||
|
||||
|
@ -680,7 +680,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
test_metadata = {'foo': 'bar', 'baz': 'quux', 'blarg': 'wibble'}
|
||||
nonexist = dict(self.stack_identity)
|
||||
nonexist['stack_name'] = 'foo'
|
||||
self.assertRaises(AttributeError,
|
||||
self.assertRaises(exception.StackNotFound,
|
||||
self.man.metadata_update,
|
||||
self.ctx, nonexist,
|
||||
'WebServer', test_metadata)
|
||||
|
|
Loading…
Reference in New Issue