Merge "render stack parameters in the correct order"
This commit is contained in:
@@ -284,8 +284,16 @@ class CreateStackForm(forms.SelfHandlingForm):
|
||||
self.help_text = template_validate['Description']
|
||||
|
||||
params = template_validate.get('Parameters', {})
|
||||
|
||||
for param_key, param in params.items():
|
||||
if template_validate.get('ParameterGroups'):
|
||||
params_in_order = []
|
||||
for group in template_validate['ParameterGroups']:
|
||||
for param in group.get('parameters', []):
|
||||
if param in params:
|
||||
params_in_order.append((param, params[param]))
|
||||
else:
|
||||
# no parameter groups, so no way to determine order
|
||||
params_in_order = params.items()
|
||||
for param_key, param in params_in_order:
|
||||
field_key = self.param_prefix + param_key
|
||||
field_args = {
|
||||
'initial': param.get('Default', None),
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import exceptions
|
||||
@@ -369,6 +370,76 @@ class StackTests(test.TestCase):
|
||||
'name="__param_secret_string" '
|
||||
'type="password" />', html=True)
|
||||
|
||||
@test.create_stubs({api.heat: ('template_validate',)})
|
||||
def test_launch_stack_with_parameter_group(self):
|
||||
template = {
|
||||
'data': ('heat_template_version: 2013-05-23\n'
|
||||
'parameters:\n'
|
||||
' last_param:\n'
|
||||
' type: string\n'
|
||||
' first_param:\n'
|
||||
' type: string\n'
|
||||
' middle_param:\n'
|
||||
' type: string\n'
|
||||
'parameter_groups:\n'
|
||||
'- parameters:\n'
|
||||
' - first_param\n'
|
||||
' - middle_param\n'
|
||||
' - last_param\n'),
|
||||
'validate': {
|
||||
'Description': 'No description',
|
||||
'Parameters': {
|
||||
'last_param': {
|
||||
'Label': 'last_param',
|
||||
'Description': '',
|
||||
'Type': 'String',
|
||||
'NoEcho': 'false'
|
||||
},
|
||||
'first_param': {
|
||||
'Label': 'first_param',
|
||||
'Description': '',
|
||||
'Type': 'String',
|
||||
'NoEcho': 'false'
|
||||
},
|
||||
'middle_param': {
|
||||
'Label': 'middle_param',
|
||||
'Description': '',
|
||||
'Type': 'String',
|
||||
'NoEcho': 'true'
|
||||
}
|
||||
},
|
||||
'ParameterGroups': [
|
||||
{
|
||||
'parameters': [
|
||||
'first_param',
|
||||
'middle_param',
|
||||
'last_param'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
api.heat.template_validate(IsA(http.HttpRequest),
|
||||
template=template['data']) \
|
||||
.AndReturn(template['validate'])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:project:stacks:select_template')
|
||||
res = self.client.get(url)
|
||||
self.assertTemplateUsed(res, 'project/stacks/select_template.html')
|
||||
|
||||
form_data = {'template_source': 'raw',
|
||||
'template_data': template['data'],
|
||||
'method': forms.TemplateForm.__name__}
|
||||
res = self.client.post(url, form_data)
|
||||
self.assertTemplateUsed(res, 'project/stacks/create.html')
|
||||
|
||||
# ensure the fields were rendered in the correct order
|
||||
regex = re.compile('^.*>first_param<.*>middle_param<.*>last_param<.*$',
|
||||
flags=re.DOTALL)
|
||||
self.assertRegexpMatches(res.content.decode('utf-8'), regex)
|
||||
|
||||
@test.create_stubs({api.heat: ('stack_update', 'stack_get',
|
||||
'template_get', 'template_validate')})
|
||||
def test_edit_stack_template(self):
|
||||
|
||||
Reference in New Issue
Block a user