RPC API: Add a PhysicalResourceNotFound exception

Change-Id: I409f8df9e93809f7267fb09656302082e42753da
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2013-01-17 11:10:15 +01:00
parent d8be4d0c12
commit 805416ebb1
6 changed files with 35 additions and 3 deletions

View File

@ -250,6 +250,7 @@ def map_remote_error(ex):
'StackNotFound',
'ResourceNotFound',
'ResourceNotAvailable',
'PhysicalResourceNotFound',
'StackExists',
)

View File

@ -94,6 +94,7 @@ def remote_error(ex, force_exists=False):
'StackNotFound': exc.HTTPNotFound,
'ResourceNotFound': exc.HTTPNotFound,
'ResourceNotAvailable': exc.HTTPNotFound,
'PhysicalResourceNotFound': exc.HTTPNotFound,
'InvalidTenant': exc.HTTPForbidden,
'StackExists': exc.HTTPConflict,
}

View File

@ -224,3 +224,7 @@ class ResourceNotFound(OpenstackException):
class ResourceNotAvailable(OpenstackException):
message = _("The Resource (%(resource_name)s) is not available.")
class PhysicalResourceNotFound(OpenstackException):
message = _("The Resource (%(resource_id)s) could not be found.")

View File

@ -396,8 +396,8 @@ class EngineService(service.Service):
rs = db_api.resource_get_by_physical_resource_id(context,
physical_resource_id)
if not rs:
msg = "The specified PhysicalResourceId doesn't exist"
raise AttributeError(msg)
raise exception.PhysicalResourceNotFound(
resource_id=physical_resource_id)
stack = parser.Stack.load(context, stack=rs.stack)
resource = stack[rs.name]

View File

@ -1208,6 +1208,32 @@ class StackControllerTest(unittest.TestCase):
self.assertEqual(response, expected)
def test_describe_stack_resources_physical_not_found(self):
# Format a dummy request
stack_name = "wordpress"
identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
params = {'Action': 'DescribeStackResources',
'LogicalResourceId': "WikiDatabase",
'PhysicalResourceId': 'aaaaaaaa-9f88-404d-cccc-ffffffffffff'}
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': 'find_physical_resource',
'args': {'physical_resource_id':
'aaaaaaaa-9f88-404d-cccc-ffffffffffff'},
'version': self.api_version},
None).AndRaise(
rpc_common.RemoteError("PhysicalResourceNotFound"))
self.m.ReplayAll()
response = self.controller.describe_stack_resources(dummy_req)
self.assertEqual(type(response),
exception.HeatInvalidParameterValueError)
def test_describe_stack_resources_err_inval(self):
# Format a dummy request containing both StackName and
# PhysicalResourceId, which is invalid and should throw a

View File

@ -640,7 +640,7 @@ class stackServiceTest(unittest.TestCase):
self.assertEqual(resource_identity.resource_name, 'WebServer')
def test_find_physical_resource_nonexist(self):
self.assertRaises(AttributeError,
self.assertRaises(exception.PhysicalResourceNotFound,
self.man.find_physical_resource,
self.ctx, 'foo')