diff --git a/heat/engine/api.py b/heat/engine/api.py index 7557082b13..57cf90b330 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -43,8 +43,10 @@ def extract_args(params): elif str(disable_rollback).lower() == 'false': kwargs[api.PARAM_DISABLE_ROLLBACK] = False else: - raise ValueError("Unexpected value for parameter %s : %s" % - (api.PARAM_DISABLE_ROLLBACK, disable_rollback)) + raise ValueError(_('Unexpected value for parameter' + ' %(name)s : %(value)s') % + dict(name=api.PARAM_DISABLE_ROLLBACK, + value=disable_rollback)) return kwargs diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 857c79bf3e..a46c91fcc4 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.py @@ -82,8 +82,8 @@ class Attributes(collections.Mapping): def __getitem__(self, key): if key not in self: - raise KeyError('%s: Invalid attribute %s' % - (self._resource_name, key)) + raise KeyError(_('%(resource)s: Invalid attribute %(key)s') % + dict(resource=self._resource_name, key=key)) return self._resolver(key) def __len__(self): diff --git a/heat/engine/components.py b/heat/engine/components.py index e4bf0875c6..bed2c752f6 100644 --- a/heat/engine/components.py +++ b/heat/engine/components.py @@ -86,14 +86,15 @@ class Components(dict): deps = self.depends() for dep in deps: if dep not in self.iterkeys(): - raise ValueError('component %s is not defined.' % dep) + raise ValueError(_('component %s is not defined.') % dep) comp = self[dep] if dep in comp.depends(): - raise ValueError('component %s depends on itself.' % dep) + raise ValueError(_('component %s depends on itself.') % dep) for (name, comp) in self.iteritems(): cdeps = comp.depends() for dep in cdeps: if cdeps.count(dep) > 1: - msg = 'duplicated %s in %s depends on.' % (dep, name) + msg = _('duplicated %(dep)s in' + ' %(name)s depends on.') % dict(dep=dep, name=name) raise ValueError(msg) return True diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index 6bc8a7cc92..6f54103761 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -151,7 +151,7 @@ class Parameter(object): elif param_type == JSON: ParamClass = JsonParam else: - raise ValueError('Invalid Parameter type "%s"' % param_type) + raise ValueError(_('Invalid Parameter type "%s"') % param_type) return ParamClass(name, schema, value, validate_value) @@ -180,7 +180,7 @@ class Parameter(object): if self.has_default(): return self.default() - raise KeyError('Missing parameter %s' % self.name) + raise KeyError(_('Missing parameter %s') % self.name) def no_echo(self): ''' @@ -251,7 +251,7 @@ class CommaDelimitedListParam(Parameter, collections.Sequence): if value: return value.split(',') except (KeyError, AttributeError) as err: - message = 'Value must be a comma-delimited list string: %s' + message = _('Value must be a comma-delimited list string: %s') raise ValueError(message % str(err)) return value @@ -287,7 +287,7 @@ class JsonParam(Parameter, collections.Mapping): if val: return json.loads(val) except (ValueError, TypeError) as err: - message = 'Value must be valid JSON: %s' % str(err) + message = _('Value must be valid JSON: %s') % str(err) raise ValueError(message) return value @@ -298,7 +298,7 @@ class JsonParam(Parameter, collections.Mapping): val = json.dumps(val) self.user_value = val except (ValueError, TypeError) as err: - message = 'Value must be valid JSON' + message = _('Value must be valid JSON') raise ValueError("%s: %s" % (message, str(err))) return val diff --git a/heat/engine/parser.py b/heat/engine/parser.py index 9b84959ae2..9e7f98891b 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -181,7 +181,7 @@ class Stack(collections.Mapping): stack = db_api.stack_get(context, stack_id, show_deleted=show_deleted) if stack is None: - message = 'No stack exists with id "%s"' % str(stack_id) + message = _('No stack exists with id "%s"') % str(stack_id) raise exception.NotFound(message) template = Template.load(context, stack.raw_template_id) @@ -306,7 +306,7 @@ class Stack(collections.Mapping): if dup_names: logger.debug("Duplicate names %s" % dup_names) - raise StackValidationFailed(message="Duplicate names %s" % + raise StackValidationFailed(message=_("Duplicate names %s") % dup_names) for res in self.dependencies: @@ -332,10 +332,10 @@ class Stack(collections.Mapping): def state_set(self, action, status, reason): '''Update the stack state in the database.''' if action not in self.ACTIONS: - raise ValueError("Invalid action %s" % action) + raise ValueError(_("Invalid action %s") % action) if status not in self.STATUSES: - raise ValueError("Invalid status %s" % status) + raise ValueError(_("Invalid status %s") % status) self.action = action self.status = status diff --git a/heat/engine/properties.py b/heat/engine/properties.py index ad92229fd5..038457ec8c 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -85,7 +85,8 @@ class Schema(collections.Mapping): self._len = None self.type = data_type if self.type not in SCHEMA_TYPES: - raise InvalidPropertySchemaError('Invalid type (%s)' % self.type) + raise InvalidPropertySchemaError(_('Invalid type (%s)') % + self.type) self.description = description self.required = required @@ -93,23 +94,28 @@ class Schema(collections.Mapping): if isinstance(schema, type(self)): if self.type != LIST: - msg = 'Single schema valid only for %s, not %s' % (LIST, - self.type) + msg = _('Single schema valid only for ' + '%(ltype)s, not %(utype)s') % dict(ltype=LIST, + utype=self.type) raise InvalidPropertySchemaError(msg) self.schema = AnyIndexDict(schema) else: self.schema = schema if self.schema is not None and self.type not in (LIST, MAP): - msg = 'Schema valid only for %s or %s, not %s' % (LIST, MAP, - self.type) + msg = _('Schema valid only for %(ltype)s or ' + '%(mtype)s, not %(utype)s') % dict(ltype=LIST, + mtype=MAP, + utype=self.type) raise InvalidPropertySchemaError(msg) self.constraints = constraints for c in constraints: if self.type not in c.valid_types: - err_msg = '%s constraint invalid for %s' % (type(c).__name__, - self.type) + err_msg = _('%(name)s constraint ' + 'invalid for %(utype)s') % dict( + name=type(c).__name__, + utype=self.type) raise InvalidPropertySchemaError(err_msg) self.default = default @@ -117,8 +123,10 @@ class Schema(collections.Mapping): try: self.validate_constraints(self.default) except (ValueError, TypeError) as exc: - raise InvalidPropertySchemaError('Invalid default %s (%s)' % - (self.default, exc)) + raise InvalidPropertySchemaError(_('Invalid default ' + '%(default)s (%(exc)s)') % + dict(default=self.default, + exc=exc)) @classmethod def from_legacy(cls, schema_dict): @@ -132,7 +140,7 @@ class Schema(collections.Mapping): unknown = [k for k in schema_dict if k not in SCHEMA_KEYS] if unknown: - raise InvalidPropertySchemaError('Unknown key(s) %s' % unknown) + raise InvalidPropertySchemaError(_('Unknown key(s) %s') % unknown) def constraints(): def get_num(key): @@ -155,7 +163,7 @@ class Schema(collections.Mapping): try: data_type = schema_dict[TYPE] except KeyError: - raise InvalidPropertySchemaError('No %s specified' % TYPE) + raise InvalidPropertySchemaError(_('No %s specified') % TYPE) if SCHEMA in schema_dict: if data_type == LIST: @@ -164,8 +172,11 @@ class Schema(collections.Mapping): schema_dicts = schema_dict[SCHEMA].items() ss = dict((n, cls.from_legacy(sd)) for n, sd in schema_dicts) else: - raise InvalidPropertySchemaError('%s supplied for %s %s' % - (SCHEMA, TYPE, data_type)) + raise InvalidPropertySchemaError(_('%(schema)s supplied for' + ' %(type)s %(data)s') % + dict(schema=SCHEMA, + type=TYPE, + data=data_type)) else: ss = None @@ -299,7 +310,7 @@ class AnyIndexDict(collections.Mapping): def __getitem__(self, key): if key != self.ANYTHING and not isinstance(key, (int, long)): - raise KeyError('Invalid key %s' % str(key)) + raise KeyError(_('Invalid key %s') % str(key)) return self.value @@ -388,10 +399,11 @@ class Range(Constraint): for param in (min, max): if not isinstance(param, (float, int, long, type(None))): - raise InvalidPropertySchemaError('min/max must be numeric') + raise InvalidPropertySchemaError(_('min/max must be numeric')) if min is max is None: - raise InvalidPropertySchemaError('range must have min and/or max') + raise InvalidPropertySchemaError(_('range must have ' + 'min and/or max')) def _str(self): if self.max is None: @@ -449,7 +461,7 @@ class Length(Range): for param in (min, max): if not isinstance(param, (int, long, type(None))): - msg = 'min/max length must be integral' + msg = _('min/max length must be integral') raise InvalidPropertySchemaError(msg) def _str(self): @@ -488,7 +500,7 @@ class AllowedValues(Constraint): super(AllowedValues, self).__init__(description) if (not isinstance(allowed, collections.Sequence) or isinstance(allowed, basestring)): - raise InvalidPropertySchemaError('AllowedValues must be a list') + raise InvalidPropertySchemaError(_('AllowedValues must be a list')) self.allowed = tuple(allowed) def _str(self): @@ -571,7 +583,7 @@ class Property(object): if value is None: value = self.has_default() and self.default() or 0 if not isinstance(value, (int, long)): - raise TypeError('value is not an integer') + raise TypeError(_('value is not an integer')) return self._validate_number(value) def _validate_number(self, value): @@ -586,7 +598,7 @@ class Property(object): if value is None: value = self.has_default() and self.default() or '' if not isinstance(value, basestring): - raise ValueError('Value must be a string') + raise ValueError(_('Value must be a string')) return value def _validate_children(self, child_values, keys=None): @@ -604,7 +616,7 @@ class Property(object): if value is None: value = self.has_default() and self.default() or {} if not isinstance(value, collections.Mapping): - raise TypeError('"%s" is not a map' % value) + raise TypeError(_('"%s" is not a map') % value) return dict(self._validate_children(value.iteritems())) @@ -613,7 +625,7 @@ class Property(object): value = self.has_default() and self.default() or [] if (not isinstance(value, collections.Sequence) or isinstance(value, basestring)): - raise TypeError('"%s" is not a list' % repr(value)) + raise TypeError(_('"%s" is not a list') % repr(value)) return [v for i, v in self._validate_children(enumerate(value), range(len(value)))] @@ -625,7 +637,7 @@ class Property(object): return value normalised = value.lower() if normalised not in ['true', 'false']: - raise ValueError('"%s" is not a valid boolean') + raise ValueError(_('"%s" is not a valid boolean') % normalised) return normalised == 'true' @@ -691,22 +703,22 @@ class Properties(collections.Mapping): try: self[key] except ValueError as e: - msg = "Property error : %s" % str(e) + msg = _("Property error : %s") % str(e) raise exception.StackValidationFailed(message=msg) # are there unimplemented Properties if not prop.implemented() and key in self.data: - msg = "Property %s not implemented yet" % key + msg = _("Property %s not implemented yet") % key raise exception.StackValidationFailed(message=msg) for key in self.data: if key not in self.props: - msg = "Unknown Property %s" % key + msg = _("Unknown Property %s") % key raise exception.StackValidationFailed(message=msg) def __getitem__(self, key): if key not in self: - raise KeyError(self.error_prefix + 'Invalid Property %s' % key) + raise KeyError(self.error_prefix + _('Invalid Property %s') % key) prop = self.props[key] @@ -722,7 +734,7 @@ class Properties(collections.Mapping): return prop.default() elif prop.required(): raise ValueError(self.error_prefix + - 'Property %s not assigned' % key) + _('Property %s not assigned') % key) def __len__(self): return len(self.props) diff --git a/heat/engine/template.py b/heat/engine/template.py index a8a0ba7b9b..d758cb035b 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -68,7 +68,7 @@ class Template(collections.Mapping): def __getitem__(self, section): '''Get the relevant section in the template.''' if section not in SECTIONS: - raise KeyError('"%s" is not a valid template section' % section) + raise KeyError(_('"%s" is not a valid template section') % section) if section == VERSION: return self.t[section] @@ -186,16 +186,18 @@ class Template(collections.Mapping): ''' def handle_join(args): if not isinstance(args, (list, tuple)): - raise TypeError('Arguments to "Fn::Join" must be a list') + raise TypeError(_('Arguments to "Fn::Join" must be a list')) try: delim, items = args except ValueError as ex: example = '"Fn::Join" : [ " ", [ "str1", "str2"]]' - raise ValueError('Incorrect arguments to "Fn::Join" %s: %s' % - ('should be', example)) + raise ValueError(_('Incorrect arguments to ' + '"Fn::Join" should be: %s') % + example) if not isinstance(items, (list, tuple)): - raise TypeError('Arguments to "Fn::Join" not fully resolved') + raise TypeError(_('Arguments to "Fn::Join" ' + 'not fully resolved')) reduced = [] contiguous = [] for item in items: @@ -228,14 +230,15 @@ class Template(collections.Mapping): ''' def handle_select(args): if not isinstance(args, (list, tuple)): - raise TypeError('Arguments to "Fn::Select" must be a list') + raise TypeError(_('Arguments to "Fn::Select" must be a list')) try: lookup, strings = args except ValueError as ex: example = '"Fn::Select" : [ "4", [ "str1", "str2"]]' - raise ValueError('Incorrect arguments to "Fn::Select" %s: %s' % - ('should be', example)) + raise ValueError(_('Incorrect arguments to ' + '"Fn::Select" should be: %s') % + example) try: index = int(lookup) @@ -254,7 +257,7 @@ class Template(collections.Mapping): if strings is None: return '' - raise TypeError('Arguments to "Fn::Select" not fully resolved') + raise TypeError(_('Arguments to "Fn::Select" not fully resolved')) return _resolve(lambda k, v: k == 'Fn::Select', handle_select, s) @@ -266,17 +269,19 @@ class Template(collections.Mapping): ''' def handle_join(args): if not isinstance(args, (list, tuple)): - raise TypeError('Arguments to "Fn::Join" must be a list') + raise TypeError(_('Arguments to "Fn::Join" must be a list')) try: delim, strings = args except ValueError as ex: example = '"Fn::Join" : [ " ", [ "str1", "str2"]]' - raise ValueError('Incorrect arguments to "Fn::Join" %s: %s' % - ('should be', example)) + raise ValueError(_('Incorrect arguments to ' + '"Fn::Join" should be: %s') % + example) if not isinstance(strings, (list, tuple)): - raise TypeError('Arguments to "Fn::Join" not fully resolved') + raise TypeError(_('Arguments to "Fn::Join" ' + 'not fully resolved')) def empty_for_none(v): if v is None: @@ -299,17 +304,18 @@ class Template(collections.Mapping): ''' def handle_split(args): if not isinstance(args, (list, tuple)): - raise TypeError('Arguments to "Fn::Split" must be a list') + raise TypeError(_('Arguments to "Fn::Split" must be a list')) example = '"Fn::Split" : [ ",", "str1, str2"]]' try: delim, strings = args except ValueError as ex: - raise ValueError('Incorrect arguments to "Fn::Split" %s: %s' % - ('should be', example)) + raise ValueError(_('Incorrect arguments to "Fn::Split" ' + 'should be: %s') % example) if not isinstance(strings, basestring): - raise TypeError('Incorrect arguments to "Fn::Split" %s: %s' % - ('should be', example)) + raise TypeError(_('Incorrect arguments to ' + '"Fn::Split" should be: %s') % + example) return strings.split(delim) return _resolve(lambda k, v: k == 'Fn::Split', handle_split, s) @@ -327,7 +333,7 @@ class Template(collections.Mapping): """ def handle_replace(args): if not isinstance(args, (list, tuple)): - raise TypeError('Arguments to "Fn::Replace" must be a list') + raise TypeError(_('Arguments to "Fn::Replace" must be a list')) try: mapping, string = args @@ -335,24 +341,25 @@ class Template(collections.Mapping): example = ('{"Fn::Replace": ' '[ {"$var1": "foo", "%var2%": "bar"}, ' '"$var1 is %var2%"]}') - raise ValueError( - 'Incorrect arguments to "Fn::Replace" %s: %s' % - ('should be', example)) + raise ValueError(_('Incorrect arguments to ' + '"Fn::Replace" should be: %s') % + example) if not isinstance(mapping, dict): raise TypeError( - 'Arguments to "Fn::Replace" not fully resolved') + _('Arguments to "Fn::Replace" not fully resolved')) if not isinstance(string, basestring): raise TypeError( - 'Arguments to "Fn::Replace" not fully resolved') + _('Arguments to "Fn::Replace" not fully resolved')) for k, v in mapping.items(): if v is None: v = '' if not isinstance(v, basestring): raise TypeError( - '"Fn::Replace" value(%s) for "%s" is not a string' % - (str(v), k)) + _('"Fn::Replace" value(%(value)s) for' + ' "%(key)s" is not a string') % + dict(value=str(v), key=k)) string = string.replace(k, v) return string @@ -365,7 +372,8 @@ class Template(collections.Mapping): ''' def handle_base64(string): if not isinstance(string, basestring): - raise TypeError('Arguments to "Fn::Base64" not fully resolved') + raise TypeError(_('Arguments to "Fn::Base64" ' + 'not fully resolved')) return string return _resolve(lambda k, v: k == 'Fn::Base64', handle_base64, s) @@ -388,15 +396,15 @@ class Template(collections.Mapping): '.member.0.Value=door']]} ''' if not isinstance(args, (list, tuple)): - raise TypeError('Wrong Arguments try: "%s"' % correct) + raise TypeError(_('Wrong Arguments try: "%s"') % correct) if len(args) != 3: - raise TypeError('Wrong Arguments try: "%s"' % correct) + raise TypeError(_('Wrong Arguments try: "%s"') % correct) if not isinstance(args[0], basestring): - raise TypeError('Wrong Arguments try: "%s"' % correct) + raise TypeError(_('Wrong Arguments try: "%s"') % correct) if not isinstance(args[1], basestring): - raise TypeError('Wrong Arguments try: "%s"' % correct) + raise TypeError(_('Wrong Arguments try: "%s"') % correct) if not isinstance(args[2], (list, tuple)): - raise TypeError('Wrong Arguments try: "%s"' % correct) + raise TypeError(_('Wrong Arguments try: "%s"') % correct) partial = {} for item in args[2]: @@ -420,14 +428,14 @@ class Template(collections.Mapping): def handle_resource_facade(arg): if arg not in resource_attributes: raise ValueError( - 'Incorrect arguments to "Fn::ResourceFacade" %s: %s' % - ('should be one of', str(resource_attributes))) + _('Incorrect arguments to "Fn::ResourceFacade" ' + 'should be one of: %s') % str(resource_attributes)) try: if arg == 'Metadata': return stack.parent_resource.metadata return stack.parent_resource.t[arg] except KeyError: - raise KeyError('"%s" is not specified in parent resource' % + raise KeyError(_('"%s" is not specified in parent resource') % arg) return _resolve(lambda k, v: k == 'Fn::ResourceFacade', diff --git a/heat/engine/watchrule.py b/heat/engine/watchrule.py index e1a01c53e2..d717af81aa 100644 --- a/heat/engine/watchrule.py +++ b/heat/engine/watchrule.py @@ -319,7 +319,7 @@ class WatchRule(object): Persistently store the watch state ''' if state not in self.WATCH_STATES: - raise ValueError("Invalid watch state %s" % state) + raise ValueError(_("Invalid watch state %s") % state) self.state = state self.store() @@ -331,7 +331,7 @@ class WatchRule(object): ''' if state not in self.WATCH_STATES: - raise ValueError('Unknown watch state %s' % state) + raise ValueError(_('Unknown watch state %s') % state) actions = [] if state != self.state: