Merge "Add Boolean type to attributes schema"

This commit is contained in:
Jenkins 2015-07-07 22:21:56 +00:00 committed by Gerrit Code Review
commit b68937a446
2 changed files with 22 additions and 2 deletions

View File

@ -13,6 +13,7 @@
import collections
from oslo_utils import strutils
import six
from heat.common.i18n import _
@ -48,9 +49,9 @@ class Schema(constr.Schema):
)
TYPES = (
STRING, MAP, LIST, INTEGER
STRING, MAP, LIST, INTEGER, BOOLEAN
) = (
'String', 'Map', 'List', 'Integer'
'String', 'Map', 'List', 'Integer', 'Boolean'
)
def __init__(self, description=None,
@ -191,6 +192,13 @@ class Attributes(collections.Mapping):
LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name,
'att_type': attrib.schema.INTEGER})
elif attrib.schema.type == attrib.schema.BOOLEAN:
try:
strutils.bool_from_string(value, strict=True)
except ValueError:
LOG.warn(_LW("Attribute %(name)s is not of type %(att_type)s"),
{'name': attrib.name,
'att_type': attrib.schema.BOOLEAN})
def __getitem__(self, key):
if key not in self:

View File

@ -199,6 +199,18 @@ class AttributesTypeTest(common.HeatTestCase):
('integer_type',
dict(a_type=attributes.Schema.INTEGER,
value=1,
invalid_value='invalid_value')),
('boolean_type',
dict(a_type=attributes.Schema.BOOLEAN,
value=True,
invalid_value='invalid_value')),
('boolean_type_string_true',
dict(a_type=attributes.Schema.BOOLEAN,
value="True",
invalid_value='invalid_value')),
('boolean_type_string_false',
dict(a_type=attributes.Schema.BOOLEAN,
value="false",
invalid_value='invalid_value'))
]