Fix serialization of InvalidSchemaError
Move InvalidSchemaError to heat.common.exception and pass a keyword argument so that it can be serialized properly. Change-Id: Iada3273b2b0b129bc0125b68fecf1e0efc081611 Closes-Bug: #1336740
This commit is contained in:
parent
a199f46137
commit
4503154c12
@ -276,6 +276,7 @@ def map_remote_error(ex):
|
|||||||
'PhysicalResourceNotFound',
|
'PhysicalResourceNotFound',
|
||||||
'WatchRuleNotFound',
|
'WatchRuleNotFound',
|
||||||
'StackValidationFailed',
|
'StackValidationFailed',
|
||||||
|
'InvalidSchemaError',
|
||||||
'InvalidTemplateReference',
|
'InvalidTemplateReference',
|
||||||
'InvalidTemplateVersion',
|
'InvalidTemplateVersion',
|
||||||
'InvalidTemplateSection',
|
'InvalidTemplateSection',
|
||||||
|
@ -68,6 +68,7 @@ class FaultWrapper(wsgi.Middleware):
|
|||||||
'Forbidden': webob.exc.HTTPForbidden,
|
'Forbidden': webob.exc.HTTPForbidden,
|
||||||
'StackExists': webob.exc.HTTPConflict,
|
'StackExists': webob.exc.HTTPConflict,
|
||||||
'StackValidationFailed': webob.exc.HTTPBadRequest,
|
'StackValidationFailed': webob.exc.HTTPBadRequest,
|
||||||
|
'InvalidSchemaError': webob.exc.HTTPBadRequest,
|
||||||
'InvalidTemplateReference': webob.exc.HTTPBadRequest,
|
'InvalidTemplateReference': webob.exc.HTTPBadRequest,
|
||||||
'InvalidTemplateVersion': webob.exc.HTTPBadRequest,
|
'InvalidTemplateVersion': webob.exc.HTTPBadRequest,
|
||||||
'InvalidTemplateSection': webob.exc.HTTPBadRequest,
|
'InvalidTemplateSection': webob.exc.HTTPBadRequest,
|
||||||
|
@ -253,6 +253,10 @@ class StackValidationFailed(HeatException):
|
|||||||
msg_fmt = _("%(message)s")
|
msg_fmt = _("%(message)s")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidSchemaError(HeatException):
|
||||||
|
msg_fmt = _("%(message)s")
|
||||||
|
|
||||||
|
|
||||||
class ResourceNotFound(HeatException):
|
class ResourceNotFound(HeatException):
|
||||||
msg_fmt = _("The Resource (%(resource_name)s) could not be found "
|
msg_fmt = _("The Resource (%(resource_name)s) could not be found "
|
||||||
"in Stack %(stack_name)s.")
|
"in Stack %(stack_name)s.")
|
||||||
|
@ -23,10 +23,6 @@ from heat.engine import resources
|
|||||||
from heat.openstack.common import strutils
|
from heat.openstack.common import strutils
|
||||||
|
|
||||||
|
|
||||||
class InvalidSchemaError(exception.Error):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Schema(collections.Mapping):
|
class Schema(collections.Mapping):
|
||||||
"""
|
"""
|
||||||
Schema base class for validating properties or parameters.
|
Schema base class for validating properties or parameters.
|
||||||
@ -85,7 +81,8 @@ class Schema(collections.Mapping):
|
|||||||
self.label = label
|
self.label = label
|
||||||
self.type = data_type
|
self.type = data_type
|
||||||
if self.type not in self.TYPES:
|
if self.type not in self.TYPES:
|
||||||
raise InvalidSchemaError(_('Invalid type (%s)') % self.type)
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('Invalid type (%s)') % self.type)
|
||||||
|
|
||||||
self.description = description
|
self.description = description
|
||||||
self.required = required
|
self.required = required
|
||||||
@ -95,7 +92,7 @@ class Schema(collections.Mapping):
|
|||||||
msg = _('Single schema valid only for '
|
msg = _('Single schema valid only for '
|
||||||
'%(ltype)s, not %(utype)s') % dict(ltype=self.LIST,
|
'%(ltype)s, not %(utype)s') % dict(ltype=self.LIST,
|
||||||
utype=self.type)
|
utype=self.type)
|
||||||
raise InvalidSchemaError(msg)
|
raise exception.InvalidSchemaError(message=msg)
|
||||||
|
|
||||||
self.schema = AnyIndexDict(schema)
|
self.schema = AnyIndexDict(schema)
|
||||||
else:
|
else:
|
||||||
@ -106,7 +103,7 @@ class Schema(collections.Mapping):
|
|||||||
'%(mtype)s, not %(utype)s') % dict(ltype=self.LIST,
|
'%(mtype)s, not %(utype)s') % dict(ltype=self.LIST,
|
||||||
mtype=self.MAP,
|
mtype=self.MAP,
|
||||||
utype=self.type)
|
utype=self.type)
|
||||||
raise InvalidSchemaError(msg)
|
raise exception.InvalidSchemaError(message=msg)
|
||||||
|
|
||||||
self.constraints = constraints or []
|
self.constraints = constraints or []
|
||||||
self.default = default
|
self.default = default
|
||||||
@ -124,7 +121,7 @@ class Schema(collections.Mapping):
|
|||||||
'invalid for %(utype)s') % dict(
|
'invalid for %(utype)s') % dict(
|
||||||
name=type(c).__name__,
|
name=type(c).__name__,
|
||||||
utype=self.type)
|
utype=self.type)
|
||||||
raise InvalidSchemaError(err_msg)
|
raise exception.InvalidSchemaError(message=err_msg)
|
||||||
|
|
||||||
self._validate_default(context)
|
self._validate_default(context)
|
||||||
# validated nested schema(ta)
|
# validated nested schema(ta)
|
||||||
@ -140,9 +137,9 @@ class Schema(collections.Mapping):
|
|||||||
try:
|
try:
|
||||||
self.validate_constraints(self.default, context)
|
self.validate_constraints(self.default, context)
|
||||||
except (ValueError, TypeError) as exc:
|
except (ValueError, TypeError) as exc:
|
||||||
raise InvalidSchemaError(_('Invalid default '
|
raise exception.InvalidSchemaError(
|
||||||
'%(default)s (%(exc)s)') %
|
message=_('Invalid default %(default)s (%(exc)s)') %
|
||||||
dict(default=self.default, exc=exc))
|
dict(default=self.default, exc=exc))
|
||||||
|
|
||||||
def set_default(self, default=None):
|
def set_default(self, default=None):
|
||||||
"""Set the default value for this Schema object."""
|
"""Set the default value for this Schema object."""
|
||||||
@ -335,12 +332,13 @@ class Range(Constraint):
|
|||||||
|
|
||||||
for param in (min, max):
|
for param in (min, max):
|
||||||
if not isinstance(param, (float, int, long, type(None))):
|
if not isinstance(param, (float, int, long, type(None))):
|
||||||
raise InvalidSchemaError(_('min/max must be numeric'))
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('min/max must be numeric'))
|
||||||
|
|
||||||
if min is max is None:
|
if min is max is None:
|
||||||
raise InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_('A range constraint must have a min value and/or a max '
|
message=_('A range constraint must have a min value and/or '
|
||||||
'value specified.'))
|
'a max value specified.'))
|
||||||
|
|
||||||
def _str(self):
|
def _str(self):
|
||||||
if self.max is None:
|
if self.max is None:
|
||||||
@ -395,16 +393,16 @@ class Length(Range):
|
|||||||
|
|
||||||
def __init__(self, min=None, max=None, description=None):
|
def __init__(self, min=None, max=None, description=None):
|
||||||
if min is max is None:
|
if min is max is None:
|
||||||
raise InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_('A length constraint must have a min value and/or a max '
|
message=_('A length constraint must have a min value and/or '
|
||||||
'value specified.'))
|
'a max value specified.'))
|
||||||
|
|
||||||
super(Length, self).__init__(min, max, description)
|
super(Length, self).__init__(min, max, description)
|
||||||
|
|
||||||
for param in (min, max):
|
for param in (min, max):
|
||||||
if not isinstance(param, (int, long, type(None))):
|
if not isinstance(param, (int, long, type(None))):
|
||||||
msg = _('min/max length must be integral')
|
msg = _('min/max length must be integral')
|
||||||
raise InvalidSchemaError(msg)
|
raise exception.InvalidSchemaError(message=msg)
|
||||||
|
|
||||||
def _str(self):
|
def _str(self):
|
||||||
if self.max is None:
|
if self.max is None:
|
||||||
@ -443,7 +441,8 @@ class AllowedValues(Constraint):
|
|||||||
super(AllowedValues, self).__init__(description)
|
super(AllowedValues, self).__init__(description)
|
||||||
if (not isinstance(allowed, collections.Sequence) or
|
if (not isinstance(allowed, collections.Sequence) or
|
||||||
isinstance(allowed, basestring)):
|
isinstance(allowed, basestring)):
|
||||||
raise InvalidSchemaError(_('AllowedValues must be a list'))
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('AllowedValues must be a list'))
|
||||||
self.allowed = tuple(allowed)
|
self.allowed = tuple(allowed)
|
||||||
|
|
||||||
def _str(self):
|
def _str(self):
|
||||||
@ -487,7 +486,8 @@ class AllowedPattern(Constraint):
|
|||||||
def __init__(self, pattern, description=None):
|
def __init__(self, pattern, description=None):
|
||||||
super(AllowedPattern, self).__init__(description)
|
super(AllowedPattern, self).__init__(description)
|
||||||
if not isinstance(pattern, basestring):
|
if not isinstance(pattern, basestring):
|
||||||
raise InvalidSchemaError(_('AllowedPattern must be a string'))
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('AllowedPattern must be a string'))
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
self.match = re.compile(pattern).match
|
self.match = re.compile(pattern).match
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from heat.common import exception
|
||||||
from heat.engine import constraints as constr
|
from heat.engine import constraints as constr
|
||||||
from heat.engine import parameters
|
from heat.engine import parameters
|
||||||
|
|
||||||
@ -63,9 +64,9 @@ class HOTParamSchema(parameters.Schema):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(constraints, list):
|
if not isinstance(constraints, list):
|
||||||
raise constr.InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_("Invalid parameter constraints for parameter %s, "
|
message=_("Invalid parameter constraints for parameter "
|
||||||
"expected a list") % param_name)
|
"%s, expected a list") % param_name)
|
||||||
|
|
||||||
valid_keys = (DESCRIPTION, LENGTH, RANGE, ALLOWED_VALUES,
|
valid_keys = (DESCRIPTION, LENGTH, RANGE, ALLOWED_VALUES,
|
||||||
ALLOWED_PATTERN, CUSTOM_CONSTRAINT)
|
ALLOWED_PATTERN, CUSTOM_CONSTRAINT)
|
||||||
@ -96,8 +97,8 @@ class HOTParamSchema(parameters.Schema):
|
|||||||
cdef = constraint.get(CUSTOM_CONSTRAINT)
|
cdef = constraint.get(CUSTOM_CONSTRAINT)
|
||||||
yield constr.CustomConstraint(cdef, desc)
|
yield constr.CustomConstraint(cdef, desc)
|
||||||
else:
|
else:
|
||||||
raise constr.InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_("No constraint expressed"))
|
message=_("No constraint expressed"))
|
||||||
|
|
||||||
# make update_allowed true by default on TemplateResources
|
# make update_allowed true by default on TemplateResources
|
||||||
# as the template should deal with this.
|
# as the template should deal with this.
|
||||||
|
@ -75,17 +75,16 @@ class Schema(constr.Schema):
|
|||||||
try:
|
try:
|
||||||
default_value = self.default.split(',')
|
default_value = self.default.split(',')
|
||||||
except (KeyError, AttributeError) as err:
|
except (KeyError, AttributeError) as err:
|
||||||
raise constr.InvalidSchemaError(_('Default must be a '
|
raise exception.InvalidSchemaError(
|
||||||
'comma-delimited list '
|
message=_('Default must be a comma-delimited list '
|
||||||
'string: %s') % err)
|
'string: %s') % err)
|
||||||
try:
|
try:
|
||||||
self.validate_constraints(default_value, context)
|
self.validate_constraints(default_value, context)
|
||||||
except (ValueError, TypeError,
|
except (ValueError, TypeError,
|
||||||
exception.StackValidationFailed) as exc:
|
exception.StackValidationFailed) as exc:
|
||||||
raise constr.InvalidSchemaError(_('Invalid default '
|
raise exception.InvalidSchemaError(
|
||||||
'%(default)s (%(exc)s)') %
|
message=_('Invalid default %(default)s (%(exc)s)') %
|
||||||
dict(default=self.default,
|
dict(default=self.default, exc=exc))
|
||||||
exc=exc))
|
|
||||||
|
|
||||||
def set_default(self, default=None):
|
def set_default(self, default=None):
|
||||||
super(Schema, self).set_default(default)
|
super(Schema, self).set_default(default)
|
||||||
@ -101,12 +100,12 @@ class Schema(constr.Schema):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_dict(schema_dict, allowed_keys, entity):
|
def _check_dict(schema_dict, allowed_keys, entity):
|
||||||
if not isinstance(schema_dict, dict):
|
if not isinstance(schema_dict, dict):
|
||||||
raise constr.InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_("Invalid %s, expected a mapping") % entity)
|
message=_("Invalid %s, expected a mapping") % entity)
|
||||||
for key in schema_dict:
|
for key in schema_dict:
|
||||||
if key not in allowed_keys:
|
if key not in allowed_keys:
|
||||||
raise constr.InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_("Invalid key '%(key)s' for %(entity)s") % {
|
message=_("Invalid key '%(key)s' for %(entity)s") % {
|
||||||
"key": key, "entity": entity})
|
"key": key, "entity": entity})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -116,8 +115,9 @@ class Schema(constr.Schema):
|
|||||||
"parameter (%s)" % param_name)
|
"parameter (%s)" % param_name)
|
||||||
|
|
||||||
if cls.TYPE not in schema_dict:
|
if cls.TYPE not in schema_dict:
|
||||||
raise constr.InvalidSchemaError(
|
raise exception.InvalidSchemaError(
|
||||||
_("Missing parameter type for parameter: %s") % param_name)
|
message=_("Missing parameter type for parameter: %s") %
|
||||||
|
param_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, param_name, schema_dict):
|
def from_dict(cls, param_name, schema_dict):
|
||||||
|
@ -74,7 +74,8 @@ class Schema(constr.Schema):
|
|||||||
|
|
||||||
unknown = [k for k in schema_dict if k not in SCHEMA_KEYS]
|
unknown = [k for k in schema_dict if k not in SCHEMA_KEYS]
|
||||||
if unknown:
|
if unknown:
|
||||||
raise constr.InvalidSchemaError(_('Unknown key(s) %s') % unknown)
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('Unknown key(s) %s') % unknown)
|
||||||
|
|
||||||
def constraints():
|
def constraints():
|
||||||
def get_num(key):
|
def get_num(key):
|
||||||
@ -95,7 +96,8 @@ class Schema(constr.Schema):
|
|||||||
try:
|
try:
|
||||||
data_type = schema_dict[TYPE]
|
data_type = schema_dict[TYPE]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise constr.InvalidSchemaError(_('No %s specified') % TYPE)
|
raise exception.InvalidSchemaError(
|
||||||
|
message=_('No %s specified') % TYPE)
|
||||||
|
|
||||||
if SCHEMA in schema_dict:
|
if SCHEMA in schema_dict:
|
||||||
if data_type == Schema.LIST:
|
if data_type == Schema.LIST:
|
||||||
@ -104,11 +106,9 @@ class Schema(constr.Schema):
|
|||||||
schema_dicts = schema_dict[SCHEMA].items()
|
schema_dicts = schema_dict[SCHEMA].items()
|
||||||
ss = dict((n, cls.from_legacy(sd)) for n, sd in schema_dicts)
|
ss = dict((n, cls.from_legacy(sd)) for n, sd in schema_dicts)
|
||||||
else:
|
else:
|
||||||
raise constr.InvalidSchemaError(_('%(schema)s supplied for '
|
raise exception.InvalidSchemaError(
|
||||||
' %(type)s %(data)s') %
|
message=_('%(schema)s supplied for %(type)s %(data)s') %
|
||||||
dict(schema=SCHEMA,
|
dict(schema=SCHEMA, type=TYPE, data=data_type))
|
||||||
type=TYPE,
|
|
||||||
data=data_type))
|
|
||||||
else:
|
else:
|
||||||
ss = None
|
ss = None
|
||||||
|
|
||||||
|
@ -181,11 +181,11 @@ class SchemaTest(testtools.TestCase):
|
|||||||
self.assertEqual(d, dict(l))
|
self.assertEqual(d, dict(l))
|
||||||
|
|
||||||
def test_invalid_type(self):
|
def test_invalid_type(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError, constraints.Schema,
|
self.assertRaises(exception.InvalidSchemaError, constraints.Schema,
|
||||||
'Fish')
|
'Fish')
|
||||||
|
|
||||||
def test_schema_invalid_type(self):
|
def test_schema_invalid_type(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
constraints.Schema,
|
constraints.Schema,
|
||||||
'String',
|
'String',
|
||||||
schema=constraints.Schema('String'))
|
schema=constraints.Schema('String'))
|
||||||
@ -193,14 +193,14 @@ class SchemaTest(testtools.TestCase):
|
|||||||
def test_range_invalid_type(self):
|
def test_range_invalid_type(self):
|
||||||
schema = constraints.Schema('String',
|
schema = constraints.Schema('String',
|
||||||
constraints=[constraints.Range(1, 10)])
|
constraints=[constraints.Range(1, 10)])
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError,
|
err = self.assertRaises(exception.InvalidSchemaError,
|
||||||
schema.validate)
|
schema.validate)
|
||||||
self.assertIn('Range constraint invalid for String', str(err))
|
self.assertIn('Range constraint invalid for String', str(err))
|
||||||
|
|
||||||
def test_length_invalid_type(self):
|
def test_length_invalid_type(self):
|
||||||
schema = constraints.Schema('Integer',
|
schema = constraints.Schema('Integer',
|
||||||
constraints=[constraints.Length(1, 10)])
|
constraints=[constraints.Length(1, 10)])
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError,
|
err = self.assertRaises(exception.InvalidSchemaError,
|
||||||
schema.validate)
|
schema.validate)
|
||||||
self.assertIn('Length constraint invalid for Integer', str(err))
|
self.assertIn('Length constraint invalid for Integer', str(err))
|
||||||
|
|
||||||
@ -209,21 +209,21 @@ class SchemaTest(testtools.TestCase):
|
|||||||
'Integer',
|
'Integer',
|
||||||
constraints=[constraints.AllowedPattern('[0-9]*')]
|
constraints=[constraints.AllowedPattern('[0-9]*')]
|
||||||
)
|
)
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError,
|
err = self.assertRaises(exception.InvalidSchemaError,
|
||||||
schema.validate)
|
schema.validate)
|
||||||
self.assertIn('AllowedPattern constraint invalid for Integer',
|
self.assertIn('AllowedPattern constraint invalid for Integer',
|
||||||
str(err))
|
str(err))
|
||||||
|
|
||||||
def test_range_vals_invalid_type(self):
|
def test_range_vals_invalid_type(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
constraints.Range, '1', 10)
|
constraints.Range, '1', 10)
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
constraints.Range, 1, '10')
|
constraints.Range, 1, '10')
|
||||||
|
|
||||||
def test_length_vals_invalid_type(self):
|
def test_length_vals_invalid_type(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
constraints.Length, '1', 10)
|
constraints.Length, '1', 10)
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
constraints.Length, 1, '10')
|
constraints.Length, 1, '10')
|
||||||
|
|
||||||
def test_schema_validate_good(self):
|
def test_schema_validate_good(self):
|
||||||
@ -236,7 +236,7 @@ class SchemaTest(testtools.TestCase):
|
|||||||
s = constraints.Schema(constraints.Schema.STRING, 'A string',
|
s = constraints.Schema(constraints.Schema.STRING, 'A string',
|
||||||
default='wibble', required=True,
|
default='wibble', required=True,
|
||||||
constraints=[constraints.Range(max=4)])
|
constraints=[constraints.Range(max=4)])
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError, s.validate)
|
err = self.assertRaises(exception.InvalidSchemaError, s.validate)
|
||||||
self.assertIn('Range constraint invalid for String', str(err))
|
self.assertIn('Range constraint invalid for String', str(err))
|
||||||
|
|
||||||
def test_schema_nested_validate_good(self):
|
def test_schema_nested_validate_good(self):
|
||||||
@ -253,7 +253,7 @@ class SchemaTest(testtools.TestCase):
|
|||||||
constraints=[constraints.Range(max=4)])
|
constraints=[constraints.Range(max=4)])
|
||||||
s = constraints.Schema(constraints.Schema.MAP, 'A map',
|
s = constraints.Schema(constraints.Schema.MAP, 'A map',
|
||||||
schema={'Foo': nested})
|
schema={'Foo': nested})
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError, s.validate)
|
err = self.assertRaises(exception.InvalidSchemaError, s.validate)
|
||||||
self.assertIn('Range constraint invalid for String', str(err))
|
self.assertIn('Range constraint invalid for String', str(err))
|
||||||
|
|
||||||
def test_allowed_values_numeric_int(self):
|
def test_allowed_values_numeric_int(self):
|
||||||
|
@ -17,7 +17,6 @@ import six
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import constraints
|
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import function
|
from heat.engine import function
|
||||||
from heat.engine.hot import functions as hot_functions
|
from heat.engine.hot import functions as hot_functions
|
||||||
@ -1235,7 +1234,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
|
|
||||||
schema = hot_param.HOTParamSchema.from_dict('db_port',
|
schema = hot_param.HOTParamSchema.from_dict('db_port',
|
||||||
param['db_port'])
|
param['db_port'])
|
||||||
err = self.assertRaises(constraints.InvalidSchemaError,
|
err = self.assertRaises(exception.InvalidSchemaError,
|
||||||
schema.validate)
|
schema.validate)
|
||||||
self.assertIn(range_desc, str(err))
|
self.assertIn(range_desc, str(err))
|
||||||
|
|
||||||
@ -1247,7 +1246,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
foo: bar
|
foo: bar
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual("Invalid key 'foo' for parameter (param1)",
|
self.assertEqual("Invalid key 'foo' for parameter (param1)",
|
||||||
str(error))
|
str(error))
|
||||||
@ -1260,7 +1259,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
description: Hi!
|
description: Hi!
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual("Missing parameter type for parameter: param1",
|
self.assertEqual("Missing parameter type for parameter: param1",
|
||||||
str(error))
|
str(error))
|
||||||
@ -1273,7 +1272,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
type: Unicode
|
type: Unicode
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid type (Unicode)", str(error))
|
"Invalid type (Unicode)", str(error))
|
||||||
@ -1289,7 +1288,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid key 'allowed_valus' for parameter constraints",
|
"Invalid key 'allowed_valus' for parameter constraints",
|
||||||
@ -1305,7 +1304,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid parameter constraints for parameter param1, "
|
"Invalid parameter constraints for parameter param1, "
|
||||||
@ -1321,7 +1320,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid parameter constraints, expected a mapping", str(error))
|
"Invalid parameter constraints, expected a mapping", str(error))
|
||||||
@ -1337,7 +1336,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual("No constraint expressed", str(error))
|
self.assertEqual("No constraint expressed", str(error))
|
||||||
|
|
||||||
@ -1352,7 +1351,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid range constraint, expected a mapping", str(error))
|
"Invalid range constraint, expected a mapping", str(error))
|
||||||
@ -1368,7 +1367,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: 1
|
default: 1
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid key 'foo' for range constraint", str(error))
|
"Invalid key 'foo' for range constraint", str(error))
|
||||||
@ -1384,7 +1383,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid length constraint, expected a mapping", str(error))
|
"Invalid length constraint, expected a mapping", str(error))
|
||||||
@ -1400,7 +1399,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"Invalid key 'foo' for length constraint", str(error))
|
"Invalid key 'foo' for length constraint", str(error))
|
||||||
@ -1416,7 +1415,7 @@ class HOTParamValidatorTest(HeatTestCase):
|
|||||||
default: foo
|
default: foo
|
||||||
''')
|
''')
|
||||||
error = self.assertRaises(
|
error = self.assertRaises(
|
||||||
constraints.InvalidSchemaError, parameters.Parameters,
|
exception.InvalidSchemaError, parameters.Parameters,
|
||||||
"stack_testit", parser.Template(hot_tpl))
|
"stack_testit", parser.Template(hot_tpl))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"AllowedPattern must be a string", str(error))
|
"AllowedPattern must be a string", str(error))
|
||||||
|
@ -17,7 +17,6 @@ import testtools
|
|||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.engine import constraints as constr
|
|
||||||
from heat.engine import parameters
|
from heat.engine import parameters
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
|
|
||||||
@ -51,8 +50,8 @@ class ParameterTest(testtools.TestCase):
|
|||||||
self.assertIsInstance(p, parameters.JsonParam)
|
self.assertIsInstance(p, parameters.JsonParam)
|
||||||
|
|
||||||
def test_new_bad_type(self):
|
def test_new_bad_type(self):
|
||||||
self.assertRaises(constr.InvalidSchemaError, self.new_parameter, 'p',
|
self.assertRaises(exception.InvalidSchemaError, self.new_parameter,
|
||||||
{'Type': 'List'}, validate_value=False)
|
'p', {'Type': 'List'}, validate_value=False)
|
||||||
|
|
||||||
def test_default_no_override(self):
|
def test_default_no_override(self):
|
||||||
p = self.new_parameter('defaulted', {'Type': 'String',
|
p = self.new_parameter('defaulted', {'Type': 'String',
|
||||||
@ -75,7 +74,7 @@ class ParameterTest(testtools.TestCase):
|
|||||||
'AllowedValues': ['foo'],
|
'AllowedValues': ['foo'],
|
||||||
'ConstraintDescription': 'wibble',
|
'ConstraintDescription': 'wibble',
|
||||||
'Default': 'bar'}
|
'Default': 'bar'}
|
||||||
err = self.assertRaises(constr.InvalidSchemaError,
|
err = self.assertRaises(exception.InvalidSchemaError,
|
||||||
self.new_parameter, 'p', schema, 'foo')
|
self.new_parameter, 'p', schema, 'foo')
|
||||||
self.assertIn('wibble', str(err))
|
self.assertIn('wibble', str(err))
|
||||||
|
|
||||||
@ -470,7 +469,7 @@ class ParametersTest(testtools.TestCase):
|
|||||||
params = {'Parameters': {'Foo': {'Type': 'String'},
|
params = {'Parameters': {'Foo': {'Type': 'String'},
|
||||||
'NoAttr': 'No attribute.',
|
'NoAttr': 'No attribute.',
|
||||||
'Bar': {'Type': 'Number', 'Default': '1'}}}
|
'Bar': {'Type': 'Number', 'Default': '1'}}}
|
||||||
self.assertRaises(constr.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
self.new_parameters,
|
self.new_parameters,
|
||||||
'test',
|
'test',
|
||||||
params)
|
params)
|
||||||
@ -479,14 +478,14 @@ class ParametersTest(testtools.TestCase):
|
|||||||
class ParameterSchemaTest(testtools.TestCase):
|
class ParameterSchemaTest(testtools.TestCase):
|
||||||
|
|
||||||
def test_validate_schema_wrong_key(self):
|
def test_validate_schema_wrong_key(self):
|
||||||
error = self.assertRaises(constr.InvalidSchemaError,
|
error = self.assertRaises(exception.InvalidSchemaError,
|
||||||
parameters.Schema.from_dict, 'param_name',
|
parameters.Schema.from_dict, 'param_name',
|
||||||
{"foo": "bar"})
|
{"foo": "bar"})
|
||||||
self.assertEqual("Invalid key 'foo' for parameter (param_name)",
|
self.assertEqual("Invalid key 'foo' for parameter (param_name)",
|
||||||
str(error))
|
str(error))
|
||||||
|
|
||||||
def test_validate_schema_no_type(self):
|
def test_validate_schema_no_type(self):
|
||||||
error = self.assertRaises(constr.InvalidSchemaError,
|
error = self.assertRaises(exception.InvalidSchemaError,
|
||||||
parameters.Schema.from_dict,
|
parameters.Schema.from_dict,
|
||||||
'broken',
|
'broken',
|
||||||
{"Description": "Hi!"})
|
{"Description": "Hi!"})
|
||||||
|
@ -310,7 +310,7 @@ class PropertySchemaTest(testtools.TestCase):
|
|||||||
self.assertEqual('wibble', ss.default)
|
self.assertEqual('wibble', ss.default)
|
||||||
|
|
||||||
def test_from_legacy_invalid_key(self):
|
def test_from_legacy_invalid_key(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
properties.Schema.from_legacy,
|
properties.Schema.from_legacy,
|
||||||
{'Type': 'String', 'Foo': 'Bar'})
|
{'Type': 'String', 'Foo': 'Bar'})
|
||||||
|
|
||||||
@ -604,11 +604,11 @@ class PropertyTest(testtools.TestCase):
|
|||||||
self.assertEqual('String', p.type())
|
self.assertEqual('String', p.type())
|
||||||
|
|
||||||
def test_bad_type(self):
|
def test_bad_type(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
properties.Property, {'Type': 'Fish'})
|
properties.Property, {'Type': 'Fish'})
|
||||||
|
|
||||||
def test_bad_key(self):
|
def test_bad_key(self):
|
||||||
self.assertRaises(constraints.InvalidSchemaError,
|
self.assertRaises(exception.InvalidSchemaError,
|
||||||
properties.Property,
|
properties.Property,
|
||||||
{'Type': 'String', 'Foo': 'Bar'})
|
{'Type': 'String', 'Foo': 'Bar'})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user