From 096c08cdc05f925aa995e424cd0b1ca8f5d18b77 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 25 Jul 2013 11:33:41 +0200 Subject: [PATCH] Always convert AllowedValues to a list Passing e.g. a string as the AllowedValues list can appear to work, since str.__contains__() performs a substring match. It's better to fail fast, so convert AllowedValues to a list regardless of its initial type. Change-Id: I74783e6a7c1743ead3f086116dd3850afeb7a028 --- heat/engine/parameters.py | 4 ++-- heat/engine/properties.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index e21a3690a..f71fdacfa 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -87,7 +87,7 @@ class Parameter(object): def _validate(self, value): if VALUES in self.schema: - allowed = self.schema[VALUES] + allowed = list(self.schema[VALUES]) if value not in allowed: message = '%s not in %s %s' % (value, VALUES, allowed) raise ValueError(self._error_msg(message)) @@ -253,7 +253,7 @@ class JsonParam(Parameter, collections.Mapping): raise ValueError(self._error_msg(message)) # check valid keys if VALUES in self.schema: - allowed = self.schema[VALUES] + allowed = list(self.schema[VALUES]) bad_keys = [k for k in self.parsed if k not in allowed] if bad_keys: message = ('keys %s are not in %s %s' diff --git a/heat/engine/properties.py b/heat/engine/properties.py index 810ddaaad..f1d0fb028 100644 --- a/heat/engine/properties.py +++ b/heat/engine/properties.py @@ -21,7 +21,8 @@ from heat.common import exception SCHEMA_KEYS = ( REQUIRED, IMPLEMENTED, DEFAULT, TYPE, SCHEMA, - PATTERN, MIN_VALUE, MAX_VALUE, VALUES, MIN_LENGTH, MAX_LENGTH, + PATTERN, MIN_VALUE, MAX_VALUE, VALUES, + MIN_LENGTH, MAX_LENGTH, ) = ( 'Required', 'Implemented', 'Default', 'Type', 'Schema', 'AllowedPattern', 'MinValue', 'MaxValue', 'AllowedValues', @@ -67,7 +68,7 @@ class Property(object): def _check_allowed(self, value): if VALUES in self.schema: - allowed = self.schema[VALUES] + allowed = list(self.schema[VALUES]) if value not in allowed: raise ValueError('"%s" is not an allowed value %s' % (value, str(allowed)))