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
doc/source/api
tuskar
api/controllers/v2
manager
tests/api/controllers/v2

@ -26,11 +26,33 @@ Example of JSON Representation of Plan
"parameters": "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", "default": "guest",
"description": "The password for RabbitMQ", "description": "The password for RabbitMQ",
"hidden": true, "hidden": true,
"label": null, "label": null,
"name": "compute-1::RabbitPassword", "name": "compute-1::RabbitPassword",
"parameter_type: "string"
"value": "secret-password" "value": "secret-password"
} }
], ],

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

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

@ -459,9 +459,8 @@ class PlansManager(object):
env_param = environment.find_parameter_by_name(p.name) env_param = environment.find_parameter_by_name(p.name)
return models.PlanParameter( return models.PlanParameter(
p.name, env_param.value, p.param_type, 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] params = [generate_param(tp) for tp in template.parameters]
return params return params

@ -105,13 +105,15 @@ class PlansTests(base.TestCase):
p.add_parameters( p.add_parameters(
manager_models.PlanParameter( manager_models.PlanParameter(
name="Param 1", label="1", default=2, hidden=False, 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( manager_models.PlanParameter(
name="Param 2", label="2", default=['a', ], hidden=False, 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( manager_models.PlanParameter(
name="Param 3", label="3", default={'a': 2}, hidden=False, 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 mock_retrieve.return_value = p