Wires up constraints and type into returned plan parameters

Though constraints and type are both plumbed into the parsing
and storage models, for some reason these were not being captured
in the generated Plan object returned to the client. This adds
those missing attributes of Plan parameters. Also updates the
docs to reflect the "new" attrs

Change-Id: I138818daef38f084acd6e2250986351352b3835d
This commit is contained in:
marios 2015-04-08 17:13:42 +03:00
parent ee55408acb
commit b10d4a65e5
5 changed files with 49 additions and 6 deletions

View File

@ -26,11 +26,33 @@ Example of JSON Representation of Plan
"parameters":
[
{
"constraints":
[
{
"constraint_type": "range",
"definition":
{
"min": "0"
},
"description": "Can't be less than zero"
}
],
"default": "0",
"description": "The number of cinder storage nodes to deploy"
"hidden": false,
"label": "The number of cinder storage nodes to deploy",
"name": "Cinder-Storage-1::count",
"parameter_type": "number",
"value": "0"
},
{
"constraints": []
"default": "guest",
"description": "The password for RabbitMQ",
"hidden": true,
"label": null,
"name": "compute-1::RabbitPassword",
"parameter_type: "string"
"value": "secret-password"
}
],

View File

@ -69,6 +69,19 @@ class Role(Base):
return r
class ParameterConstraint(Base):
constraint_type = wtypes.text
definition = v2types.MultiType(list, dict, wtypes.text)
description = wtypes.text
@classmethod
def from_tuskar_model(cls, constraint):
return cls(**{'constraint_type': constraint.constraint_type,
'definition': constraint.definition,
'description': constraint.description})
class PlanParameter(Base):
name = wtypes.text
@ -77,6 +90,8 @@ class PlanParameter(Base):
description = wtypes.text
hidden = bool
value = v2types.MultiType(wtypes.text, six.integer_types, list, dict)
constraints = [ParameterConstraint]
parameter_type = wtypes.text
@classmethod
def from_tuskar_model(cls, param):
@ -84,6 +99,8 @@ class PlanParameter(Base):
:type param: tuskar.manager.models.PlanParameter
"""
constraints = [ParameterConstraint.from_tuskar_model(c)
for c in param.constraints]
p = cls(**{
'name': param.name,
'label': param.label,
@ -91,6 +108,8 @@ class PlanParameter(Base):
'description': param.description,
'hidden': param.hidden,
'value': param.value,
'constraints': constraints,
'parameter_type': param.param_type
})
return p

View File

@ -69,7 +69,7 @@ class DeploymentPlan(object):
class PlanParameter(object):
def __init__(self, name, value, param_type, description,
label, default, hidden):
label, default, hidden, constraints):
super(PlanParameter, self).__init__()
self.name = name
self.value = value
@ -78,6 +78,7 @@ class PlanParameter(object):
self.label = label
self.default = default
self.hidden = hidden
self.constraints = constraints
class ParameterValue(object):

View File

@ -459,9 +459,8 @@ class PlansManager(object):
env_param = environment.find_parameter_by_name(p.name)
return models.PlanParameter(
p.name, env_param.value, p.param_type,
p.description, p.label, p.default, p.hidden
p.description, p.label, p.default, p.hidden, p.constraints
)
params = [generate_param(tp) for tp in template.parameters]
return params

View File

@ -105,13 +105,15 @@ class PlansTests(base.TestCase):
p.add_parameters(
manager_models.PlanParameter(
name="Param 1", label="1", default=2, hidden=False,
description="1", value=1, param_type=int),
description="1", value=1, param_type='number', constraints=''),
manager_models.PlanParameter(
name="Param 2", label="2", default=['a', ], hidden=False,
description="2", value=['a', 'b'], param_type=list),
description="2", value=['a', 'b'],
param_type='comma_delimited_list', constraints=''),
manager_models.PlanParameter(
name="Param 3", label="3", default={'a': 2}, hidden=False,
description="3", value={'a': 1}, param_type=dict),
description="3", value={'a': 1}, param_type='json',
constraints=''),
)
mock_retrieve.return_value = p