Ensuring environment data is passed to heat template validate

- environment data was being passed to heat API on stack create,
   but not stack validate - meaning that templates that referenced
   environment files were not validating correctly

 - heat client does not support URLs for environment files - we will
   need to do this client side before POSTing back to horizon. future
   patch

Partial-Bug: #1322258

Change-Id: I40982b777abaec743ed6cbc527008522a619e817
This commit is contained in:
Jordan OMara 2014-06-04 15:45:39 -04:00
parent c28c221f77
commit ecdc73a339
2 changed files with 11 additions and 21 deletions

View File

@ -49,12 +49,14 @@ class TemplateForm(forms.SelfHandlingForm):
help_text = _('From here you can select a template to launch '
'a stack.')
choices = [('url', _('URL')),
('file', _('File')),
# TODO(jomara) - update URL choice for template & environment files
# w/ client side download when applicable
base_choices = [('file', _('File')),
('raw', _('Direct Input'))]
url_choice = [('url', _('URL'))]
attributes = {'class': 'switchable', 'data-slug': 'templatesource'}
template_source = forms.ChoiceField(label=_('Template Source'),
choices=choices,
choices=base_choices + url_choice,
widget=forms.Select(attrs=attributes))
attributes = create_upload_form_attributes(
@ -90,7 +92,7 @@ class TemplateForm(forms.SelfHandlingForm):
attributes = {'data-slug': 'envsource', 'class': 'switchable'}
environment_source = forms.ChoiceField(
label=_('Environment Source'),
choices=choices,
choices=base_choices,
widget=forms.Select(attrs=attributes),
required=False)
@ -104,16 +106,6 @@ class TemplateForm(forms.SelfHandlingForm):
widget=forms.FileInput(attrs=attributes),
required=False)
attributes = create_upload_form_attributes(
'env',
'url',
_('Environment URL'))
environment_url = forms.URLField(
label=_('Environment URL'),
help_text=_('An external (HTTP) URL to load the environment from.'),
widget=forms.TextInput(attrs=attributes),
required=False)
attributes = create_upload_form_attributes(
'env',
'raw',
@ -145,6 +137,9 @@ class TemplateForm(forms.SelfHandlingForm):
else:
kwargs['template_url'] = cleaned['template_url']
if cleaned['environment_data']:
kwargs['environment'] = cleaned['environment_data']
try:
validated = api.heat.template_validate(self.request, **kwargs)
cleaned['template_validate'] = validated
@ -208,7 +203,6 @@ class TemplateForm(forms.SelfHandlingForm):
def create_kwargs(self, data):
kwargs = {'parameters': data['template_validate'],
'environment_data': data['environment_data'],
'environment_url': data['environment_url'],
'template_data': data['template_data'],
'template_url': data['template_url']}
if data.get('stack_id'):
@ -255,9 +249,6 @@ class CreateStackForm(forms.SelfHandlingForm):
environment_data = forms.CharField(
widget=forms.widgets.HiddenInput,
required=False)
environment_url = forms.CharField(
widget=forms.widgets.HiddenInput,
required=False)
parameters = forms.CharField(
widget=forms.widgets.HiddenInput,
required=True)
@ -353,8 +344,6 @@ class CreateStackForm(forms.SelfHandlingForm):
if data.get('environment_data'):
fields['environment'] = data.get('environment_data')
elif data.get('environment_url'):
fields['environment_url'] = data.get('environment_url')
try:
api.heat.stack_create(self.request, **fields)

View File

@ -208,7 +208,8 @@ class StackTests(test.TestCase):
stack = self.stacks.first()
api.heat.template_validate(IsA(http.HttpRequest),
template=template.data) \
template=template.data,
environment=environment.data) \
.AndReturn(json.loads(template.validate))
api.heat.stack_create(IsA(http.HttpRequest),