'PhysicalResourceNotFound',
'WatchRuleNotFound',
'StackExists',
+ 'StackValidationFailed',
)
denied_errors = ('Forbidden', 'NotAuthorized')
except rpc_common.RemoteError as ex:
return util.remote_error(ex)
- if 'Description' in result:
- raise exc.HTTPBadRequest(result['Description'])
-
raise exc.HTTPCreated(location=util.make_url(req, result))
@util.tenant_local
except rpc_common.RemoteError as ex:
return util.remote_error(ex)
- if 'Description' in res:
- raise exc.HTTPBadRequest(res['Description'])
-
raise exc.HTTPAccepted()
@util.identified_stack
'PhysicalResourceNotFound': exc.HTTPNotFound,
'InvalidTenant': exc.HTTPForbidden,
'StackExists': exc.HTTPConflict,
+ 'StackValidationFailed': exc.HTTPBadRequest,
}
Exc = error_map.get(ex.exc_type, exc.HTTPInternalServerError)
message = _("The Stack (%(stack_name)s) already exists.")
+class StackValidationFailed(OpenstackException):
+ message = _("%(message)s")
+
+
class ResourceNotFound(OpenstackException):
message = _("The Resource (%(resource_name)s) could not be found "
"in Stack %(stack_name)s.")
from heat.db import api as db_api
from heat.openstack.common import log as logging
+from heat.common.exception import StackValidationFailed
logger = logging.getLogger(__name__)
try:
result = res.validate()
except Exception as ex:
- logger.exception('validate')
- result = str(ex)
-
+ raise StackValidationFailed(message=str(ex))
if result:
- return 'Malformed Query Response %s' % result
+ raise StackValidationFailed(message=result)
def state_set(self, new_status, reason):
'''Update the stack state in the database'''
stack = parser.Stack(context, stack_name, tmpl, template_params,
**common_params)
- response = stack.validate()
- if response:
- return {'Description': response}
+ stack.validate()
stack_id = stack.store()
updated_stack = parser.Stack(context, stack_name, tmpl,
template_params, **common_params)
- response = updated_stack.validate()
- if response:
- return {'Description': response}
+ updated_stack.validate()
self._start_in_thread(db_stack.id, current_stack.update, updated_stack)
# Stub out the RPC call to the engine with a pre-canned response
self.m.StubOutWithMock(rpc, 'call')
- engine_err = {'Description': 'Something went wrong'}
rpc.call(dummy_req.context, self.topic,
{'method': 'create_stack',
'template': template,
'params': engine_parms,
'args': engine_args},
- 'version': self.api_version}, None).AndReturn(engine_err)
+ 'version': self.api_version}, None).AndRaise(
+ rpc_common.RemoteError(
+ 'StackValidationFailed',
+ 'Something went wrong'))
self.m.ReplayAll()
result = self.controller.create(dummy_req)
- expected = {'CreateStackResponse': {'CreateStackResult': engine_err}}
-
- self.assertEqual(result, expected)
+ self.assertEqual(type(result),
+ exception.HeatInvalidParameterValueError)
self.m.VerifyAll()
def test_update(self):
req = self._post('/stacks', json.dumps(body))
self.m.StubOutWithMock(rpc, 'call')
- engine_err = {'Description': 'Something went wrong'}
rpc.call(req.context, self.topic,
{'method': 'create_stack',
'args': {'stack_name': stack_name,
'params': parameters,
'args': {'timeout_mins': 30}},
'version': self.api_version},
- None).AndReturn(engine_err)
+ None).AndRaise(rpc_common.RemoteError(
+ 'StackValidationFailed',
+ 'Something went wrong'))
self.m.ReplayAll()
self.assertRaises(webob.exc.HTTPBadRequest,
from heat.common import template_format
from heat.engine import parser
from heat.engine import service
+from heat.engine.properties import Properties
from heat.engine.resources import instance as instances
from heat.engine import watchrule
from heat.openstack.common import threadgroup
stack.t, stack.parameters).AndReturn(stack)
self.m.StubOutWithMock(stack, 'validate')
- error = 'fubar'
- stack.validate().AndReturn(error)
+ stack.validate().AndRaise(exception.StackValidationFailed(
+ message='fubar'))
self.m.ReplayAll()
- result = self.man.create_stack(self.ctx, stack_name,
- template, params, {})
- self.assertEqual(result, {'Description': error})
+ self.assertRaises(
+ exception.StackValidationFailed,
+ self.man.create_stack,
+ self.ctx, stack_name,
+ template, params, {})
self.m.VerifyAll()
def test_stack_create_invalid_stack_name(self):
self.ctx, stack_name,
stack.t, {}, {})
+ def test_stack_validate(self):
+ stack_name = 'service_create_test_validate'
+ stack = get_wordpress_stack(stack_name, self.ctx)
+ setup_mocks(self.m, stack)
+
+ template = dict(stack.t)
+ template['Parameters']['KeyName']['Default'] = 'test'
+ resource = stack['WebServer']
+
+ self.m.ReplayAll()
+
+ resource.properties = Properties(
+ resource.properties_schema,
+ {
+ 'ImageId': 'foo',
+ 'KeyName': 'test',
+ 'InstanceType': 'm1.large'
+ })
+ stack.validate()
+
+ resource.properties = Properties(
+ resource.properties_schema,
+ {
+ 'KeyName': 'test',
+ 'InstanceType': 'm1.large'
+ })
+ self.assertRaises(exception.StackValidationFailed, stack.validate)
+
def test_stack_delete(self):
stack_name = 'service_delete_test_stack'
stack = get_wordpress_stack(stack_name, self.ctx)
stack.t, stack.parameters).AndReturn(stack)
self.m.StubOutWithMock(stack, 'validate')
- error = 'fubar'
- stack.validate().AndReturn(error)
+ stack.validate().AndRaise(exception.StackValidationFailed(
+ message='fubar'))
self.m.ReplayAll()
- result = self.man.update_stack(self.ctx, old_stack.identifier(),
- template, params, {})
- self.assertEqual(result, {'Description': error})
+ self.assertRaises(
+ exception.StackValidationFailed,
+ self.man.update_stack,
+ self.ctx, old_stack.identifier(),
+ template, params, {})
self.m.VerifyAll()
def test_stack_update_nonexist(self):
def test_missing_required(self):
schema = {'foo': {'Type': 'String', 'Required': True}}
props = properties.Properties(schema, {})
- self.assertNotEqual(props.validate(), None)
+ self.assertEqual(props.validate(), 'Property foo not assigned')
def test_missing_unimplemented(self):
schema = {'foo': {'Type': 'String', 'Implemented': False}}
def test_present_unimplemented(self):
schema = {'foo': {'Type': 'String', 'Implemented': False}}
props = properties.Properties(schema, {'foo': 'bar'})
- self.assertNotEqual(props.validate(), None)
+ self.assertEqual(props.validate(), 'foo Property not implemented yet')
def test_missing(self):
schema = {'foo': {'Type': 'String'}}
def test_bad_data(self):
schema = {'foo': {'Type': 'String'}}
props = properties.Properties(schema, {'foo': 42})
- self.assertNotEqual(props.validate(), None)
+ self.assertEqual(props.validate(), 'foo Value must be a string')