'ValueError',
'InvalidTenant',
'StackNotFound',
+ 'ResourceNotFound',
'StackExists',
)
'AttributeError': client_error,
'ValueError': client_error,
'StackNotFound': exc.HTTPNotFound,
+ 'ResourceNotFound': exc.HTTPNotFound,
'InvalidTenant': exc.HTTPForbidden,
'StackExists': exc.HTTPConflict,
}
class StackExists(OpenstackException):
message = _("The Stack (%(stack_name)s) already exists.")
+
+
+class ResourceNotFound(OpenstackException):
+ message = _("The Resource (%(resource_name)s) could not be found "
+ "in Stack %(stack_name)s.")
stack = parser.Stack.load(context, stack=s)
if resource_name not in stack:
- raise AttributeError('Unknown resource name')
+ raise exception.ResourceNotFound(resource_name=resource_name,
+ stack_name=stack.name)
resource = stack[resource_name]
if resource.id is None:
stack = parser.Stack.load(context, stack=s)
if resource_name not in stack:
- raise AttributeError("Resource not found %s" % resource_name)
+ raise exception.ResourceNotFound(resource_name=resource_name,
+ stack_name=stack.name)
resource = stack[resource_name]
resource.metadata_update(metadata)
self.assertEqual(type(result),
exception.HeatInvalidParameterValueError)
+ def test_describe_stack_resource_nonexistent(self):
+ # Format a dummy request
+ stack_name = "wordpress"
+ identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
+ params = {'Action': 'DescribeStackResource',
+ 'StackName': stack_name,
+ 'LogicalResourceId': "wibble"}
+ 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).AndReturn(identity)
+ args = {
+ 'stack_identity': identity,
+ 'resource_name': dummy_req.params.get('LogicalResourceId'),
+ }
+ rpc.call(dummy_req.context, self.topic,
+ {'method': 'describe_stack_resource',
+ 'args': args,
+ 'version': self.api_version},
+ None).AndRaise(rpc_common.RemoteError("ResourceNotFound"))
+
+ 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"
resource_name=res_name)
self.m.VerifyAll()
+ def test_show_nonexist_resource(self):
+ res_name = 'Wibble'
+ stack_identity = identifier.HeatIdentifier(self.tenant,
+ 'wordpress', '1')
+ res_identity = identifier.ResourceIdentifier(resource_name=res_name,
+ **stack_identity)
+
+ req = self._get(res_identity._tenant_path())
+
+ self.m.StubOutWithMock(rpc, 'call')
+ rpc.call(req.context, self.topic,
+ {'method': 'describe_stack_resource',
+ 'args': {'stack_identity': stack_identity,
+ 'resource_name': res_name},
+ 'version': self.api_version},
+ None).AndRaise(rpc_common.RemoteError("ResourceNotFound"))
+ self.m.ReplayAll()
+
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.controller.show,
+ req, tenant_id=self.tenant,
+ stack_name=stack_identity.stack_name,
+ stack_id=stack_identity.stack_id,
+ resource_name=res_name)
+ self.m.VerifyAll()
+
def test_metadata_show(self):
res_name = 'WikiDatabase'
stack_identity = identifier.HeatIdentifier(self.tenant,
resource_name=res_name)
self.m.VerifyAll()
+ def test_metadata_show_nonexist_resource(self):
+ res_name = 'wibble'
+ stack_identity = identifier.HeatIdentifier(self.tenant,
+ 'wordpress', '1')
+ res_identity = identifier.ResourceIdentifier(resource_name=res_name,
+ **stack_identity)
+
+ req = self._get(res_identity._tenant_path() + '/metadata')
+
+ self.m.StubOutWithMock(rpc, 'call')
+ rpc.call(req.context, self.topic,
+ {'method': 'describe_stack_resource',
+ 'args': {'stack_identity': stack_identity,
+ 'resource_name': res_name},
+ 'version': self.api_version},
+ None).AndRaise(rpc_common.RemoteError("ResourceNotFound"))
+ self.m.ReplayAll()
+
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.controller.metadata,
+ req, tenant_id=self.tenant,
+ stack_name=stack_identity.stack_name,
+ stack_id=stack_identity.stack_id,
+ resource_name=res_name)
+ self.m.VerifyAll()
+
@attr(tag=['unit', 'api-openstack-v1', 'EventController'])
@attr(speed='fast')
self.ctx, nonexist, 'WebServer')
def test_stack_resource_describe_nonexist_resource(self):
- self.assertRaises(AttributeError,
+ self.assertRaises(exception.ResourceNotFound,
self.man.describe_stack_resource,
self.ctx, self.stack_identity, 'foo')
def test_metadata_err_resource(self):
test_metadata = {'foo': 'bar', 'baz': 'quux', 'blarg': 'wibble'}
- self.assertRaises(AttributeError,
+ self.assertRaises(exception.ResourceNotFound,
self.man.metadata_update,
self.ctx, dict(self.stack_identity),
'NooServer', test_metadata)