Adds Parameter Label to template validate call

This change will add the ability to return the parameter label
with the parameter in the template validate call.

Change-Id: If48db3bf7f25396485f5bc8bb1cc8aeed4f8e7b0
Implements: blueprint add-parameter-label-to-template
This commit is contained in:
Tim Schnell 2014-01-07 16:50:58 +00:00
parent 54117fe58a
commit 03a8f0e313
7 changed files with 204 additions and 35 deletions

View File

@ -271,7 +271,8 @@ def format_validate_parameter(param):
api.PARAM_TYPE: schema_to_api_types.get(param.schema.type,
param.schema.type),
api.PARAM_DESCRIPTION: param.description(),
api.PARAM_NO_ECHO: 'true' if param.hidden() else 'false'
api.PARAM_NO_ECHO: 'true' if param.hidden() else 'false',
api.PARAM_LABEL: param.label()
}
if param.has_default():

View File

@ -77,8 +77,9 @@ class Schema(collections.Mapping):
def __init__(self, data_type, description=None,
default=None, schema=None,
required=False, constraints=[]):
required=False, constraints=[], label=None):
self._len = None
self.label = label
self.type = data_type
if self.type not in self.TYPES:
raise InvalidSchemaError(_('Invalid type (%s)') % self.type)

View File

@ -215,7 +215,8 @@ class HOTParamSchema(parameters.Schema):
description=schema_dict.get(HOTParamSchema.DESCRIPTION),
default=schema_dict.get(HOTParamSchema.DEFAULT),
constraints=list(constraints()),
hidden=schema_dict.get(HOTParamSchema.HIDDEN, False))
hidden=schema_dict.get(HOTParamSchema.HIDDEN, False),
label=schema_dict.get(HOTParamSchema.LABEL))
class HOTParameters(parameters.Parameters):

View File

@ -51,13 +51,14 @@ class Schema(constr.Schema):
)
def __init__(self, data_type, description=None, default=None, schema=None,
constraints=[], hidden=False, context=None):
constraints=[], hidden=False, context=None, label=None):
super(Schema, self).__init__(data_type=data_type,
description=description,
default=default,
schema=schema,
required=default is None,
constraints=constraints)
constraints=constraints,
label=label)
self.hidden = hidden
self.context = context
@ -123,7 +124,8 @@ class Schema(constr.Schema):
default=schema_dict.get(DEFAULT),
constraints=list(constraints()),
hidden=str(schema_dict.get(NO_ECHO,
'false')).lower() == 'true')
'false')).lower() == 'true',
label=schema_dict.get(LABEL))
def validate(self, name, value):
super(Schema, self).validate_constraints(value, self.context)
@ -202,6 +204,10 @@ class Parameter(object):
'''Return the description of the parameter.'''
return self.schema.description or ''
def label(self):
'''Return the label or param name.'''
return self.schema.label or self.name
def has_default(self):
'''Return whether the parameter has a default value.'''
return self.schema.default is not None

View File

@ -164,12 +164,12 @@ VALIDATE_PARAM_KEYS = (
PARAM_TYPE, PARAM_DEFAULT, PARAM_NO_ECHO,
PARAM_ALLOWED_VALUES, PARAM_ALLOWED_PATTERN, PARAM_MAX_LENGTH,
PARAM_MIN_LENGTH, PARAM_MAX_VALUE, PARAM_MIN_VALUE,
PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION
PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION, PARAM_LABEL
) = (
'Type', 'Default', 'NoEcho',
'AllowedValues', 'AllowedPattern', 'MaxLength',
'MinLength', 'MaxValue', 'MinValue',
'Description', 'ConstraintDescription'
'Description', 'ConstraintDescription', 'Label'
)
VALIDATE_PARAM_TYPES = (

View File

@ -293,7 +293,8 @@ class FormatValidateParameterTest(HeatTestCase):
expected={
'Type': 'String',
'Description': 'Name of SSH key pair',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('default',
@ -310,7 +311,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'Default': 'dummy',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_length_constraint',
@ -327,7 +329,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'MinLength': 4,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('max_length_constraint',
@ -344,7 +347,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'MaxLength': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_max_length_constraint',
@ -363,7 +367,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Description': 'Name of SSH key pair',
'MinLength': 4,
'MaxLength': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_value_constraint',
@ -380,7 +385,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'Number',
'Description': 'A number',
'MinValue': 4,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('max_value_constraint',
@ -397,7 +403,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'Number',
'Description': 'A number',
'MaxValue': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('min_max_value_constraint',
@ -416,7 +423,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Description': 'A number',
'MinValue': 4,
'MaxValue': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('allowed_values_constraint',
@ -433,7 +441,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'AllowedValues': ['foo', 'bar', 'blub'],
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('allowed_pattern_constraint',
@ -450,7 +459,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'AllowedPattern': "[a-zA-Z0-9]+",
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('multiple_constraints',
@ -475,7 +485,8 @@ class FormatValidateParameterTest(HeatTestCase):
'MaxLength': 10,
'AllowedValues': ['foo', 'bar', 'blub'],
'AllowedPattern': "[a-zA-Z0-9]+",
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('simple_hot',
@ -490,7 +501,8 @@ class FormatValidateParameterTest(HeatTestCase):
expected={
'Type': 'String',
'Description': 'Name of SSH key pair',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('default_hot',
@ -507,7 +519,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'Default': 'dummy',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_length_constraint_hot',
@ -526,7 +539,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'MinLength': 4,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('max_length_constraint_hot',
@ -545,7 +559,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'MaxLength': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_max_length_constraint_hot',
@ -565,7 +580,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Description': 'Name of SSH key pair',
'MinLength': 4,
'MaxLength': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('min_value_constraint_hot',
@ -584,7 +600,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'Number',
'Description': 'A number',
'MinValue': 4,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('max_value_constraint_hot',
@ -603,7 +620,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'Number',
'Description': 'A number',
'MaxValue': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('min_max_value_constraint_hot',
@ -623,7 +641,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Description': 'A number',
'MinValue': 4,
'MaxValue': 10,
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'MyNumber'
})
),
('allowed_values_constraint_hot',
@ -645,7 +664,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'AllowedValues': ['foo', 'bar', 'blub'],
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('allowed_pattern_constraint_hot',
@ -664,7 +684,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of SSH key pair',
'AllowedPattern': "[a-zA-Z0-9]+",
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('multiple_constraints_hot',
@ -691,7 +712,8 @@ class FormatValidateParameterTest(HeatTestCase):
'MaxLength': 10,
'AllowedValues': ['foo', 'bar', 'blub'],
'AllowedPattern': "[a-zA-Z0-9]+",
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('constraint_description_hot',
@ -712,7 +734,8 @@ class FormatValidateParameterTest(HeatTestCase):
'Description': 'Name of SSH key pair',
'MinLength': 4,
'ConstraintDescription': 'Big enough',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
('constraint_multiple_descriptions_hot',
@ -736,7 +759,8 @@ class FormatValidateParameterTest(HeatTestCase):
'MinLength': 4,
'AllowedPattern': "[a-zA-Z0-9]+",
'ConstraintDescription': 'Big enough. Only letters.',
'NoEcho': 'false'
'NoEcho': 'false',
'Label': 'KeyName'
})
),
]

View File

@ -539,14 +539,67 @@ test_template_unique_logical_name = '''
}
'''
test_template_duplicate_parameters = '''
# This is a hello world HOT template just defining a single compute instance
test_template_cfn_parameter_label = '''
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "test.",
"Parameters" : {
"KeyName" : {
''' + \
'"Description" : "Name of an existing EC2' + \
'KeyPair to enable SSH access to the instances",' + \
'''
"Type" : "String",
"Label" : "Nova KeyPair Name"
},
},
"Resources" : {
"AName": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "image_name",
"InstanceType": "m1.large",
"KeyName": { "Ref" : "KeyName" },
"NetworkInterfaces": [ "mgmt", "data" ]
}
}
}
}
'''
test_template_hot_parameter_label = '''
heat_template_version: 2013-05-23
description: >
Hello world HOT template that just defines a single compute instance.
Contains just base features to verify base HOT support.
parameters:
KeyName:
type: string
description: Name of an existing key pair to use for the instance
label: Nova KeyPair Name
resources:
my_instance:
type: AWS::EC2::Instance
properties:
KeyName: { get_param: KeyName }
ImageId: { get_param: ImageId }
InstanceType: { get_param: InstanceType }
outputs:
instance_ip:
description: The IP address of the deployed instance
value: { get_attr: [my_instance, PublicIp] }
'''
test_template_duplicate_parameters = '''
# This is a hello world HOT template just defining a single compute instance
heat_template_version: 2013-05-23
parameter_groups:
- label: Server Group
description: A group of parameters for the server
@ -682,6 +735,28 @@ outputs:
description: The IP address of the deployed instance
value: { get_attr: [my_instance, PublicIp] }
'''
test_template_hot_no_parameter_label = '''
heat_template_version: 2013-05-23
description: >
Hello world HOT template that just defines a single compute instance.
Contains just base features to verify base HOT support.
parameters:
KeyName:
type: string
description: Name of an existing key pair to use for the instance
resources:
my_instance:
type: AWS::EC2::Instance
properties:
KeyName: { get_param: KeyName }
ImageId: { get_param: ImageId }
InstanceType: { get_param: InstanceType }
'''
test_template_no_parameters = '''
heat_template_version: 2013-05-23
@ -811,9 +886,70 @@ class validateTest(HeatTestCase):
'Type': 'String',
'Description': 'Name of an existing EC2KeyPair to enable SSH '
'access to the instances',
'NoEcho': 'false'}}
'NoEcho': 'false',
'Label': 'KeyName'}}
self.assertEqual(expected, res['Parameters'])
def test_validate_hot_parameter_label(self):
t = template_format.parse(test_template_hot_parameter_label)
self.m.StubOutWithMock(instances.Instance, 'nova')
instances.Instance.nova().AndReturn(self.fc)
self.m.StubOutWithMock(service.EngineListener, 'start')
service.EngineListener.start().AndReturn(None)
self.m.ReplayAll()
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t))
parameters = res['Parameters']
expected = {'KeyName': {
'Type': 'String',
'Description': 'Name of an existing key pair to use for the '
'instance',
'NoEcho': 'false',
'Label': 'Nova KeyPair Name'}}
self.assertEqual(expected, parameters)
def test_validate_hot_no_parameter_label(self):
t = template_format.parse(test_template_hot_no_parameter_label)
self.m.StubOutWithMock(instances.Instance, 'nova')
instances.Instance.nova().AndReturn(self.fc)
self.m.StubOutWithMock(service.EngineListener, 'start')
service.EngineListener.start().AndReturn(None)
self.m.ReplayAll()
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t))
parameters = res['Parameters']
expected = {'KeyName': {
'Type': 'String',
'Description': 'Name of an existing key pair to use for the '
'instance',
'NoEcho': 'false',
'Label': 'KeyName'}}
self.assertEqual(expected, parameters)
def test_validate_cfn_parameter_label(self):
t = template_format.parse(test_template_cfn_parameter_label)
self.m.StubOutWithMock(instances.Instance, 'nova')
instances.Instance.nova().AndReturn(self.fc)
self.m.StubOutWithMock(service.EngineListener, 'start')
service.EngineListener.start().AndReturn(None)
self.m.ReplayAll()
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t))
parameters = res['Parameters']
expected = {'KeyName': {
'Type': 'String',
'Description': 'Name of an existing EC2KeyPair to enable SSH '
'access to the instances',
'NoEcho': 'false',
'Label': 'Nova KeyPair Name'}}
self.assertEqual(expected, parameters)
def test_validate_properties(self):
t = template_format.parse(test_template_invalid_property)
self.m.StubOutWithMock(instances.Instance, 'nova')