heat/heat/tests/templates
Kent Wang 41e879ade7 Fixes JSON to YAML conversion bug
Previously running cfn-json2yaml would generate valid YAML, but the
HOT file would not work. The key mappings it generates had 64 instead
of '64'. Since 64 in YAML is a number and not a string, the template
cannot find the key '64' as it is not a string value.

Turns out this issue was caused by simply forgetting to explicitly
re-add quotation marks after converting from a python object to YAML.

In the conversion code (heat/common/template_format.py), the json
string is first converted into a python object via yaml.load. Next
the python object gets converted to yaml via yaml.dump.

For example:
u'__00015__order__32': u'F17-i386-cfntools' in the python object gets
converted to __00015__order__32: F17-i386-cfntools in yaml.

Crucially in YAML, all strings are not explicity quoted except for
strings that contain only digits. For instance, numerical strings like
'32' will automatically get quoted when using yaml.dump

Normally this would be fine, but a subtle problem arises in the
next line of code:

yml = re.sub('__\d*__order__', '', yml)

By removing all instances of the order substring in the yaml, previous
alphanumeric strings become numeric-only strings. However, since this
step comes after the call to yaml.dump, quotes are not explicity set
anymore!

so for example:
__00015__order__32: F17-i386-cfntool becomes 32: F17-i386-cfntool

Then in YAML, the key 32 is now interpreted as number 32 and not
what we wanted, which is a string '32'

So to help fix this issue, replace all numeric-only keys with quoted
keys. For example:
32: F17-i386-cfntool becomes '32': F17-i386-cfntool
This helps to fix the issue of not finding the numerical keys in
the HOT yaml file.

Change-Id: I37208679f0699d088a7ca632a409d8675cad72c4
Closes-Bug: #1286380
Closes-Bug: #1467029
Closes-Bug: #1467026
2015-06-25 07:32:34 -07:00
..
Neutron.template "version" section should be required in template 2014-01-24 09:47:55 +08:00
Neutron.yaml Rename Quantum to Neutron 2013-08-06 22:08:27 -07:00
README Clarify text in heat/tests/templates/README 2013-07-29 04:53:57 +00:00
WordPress_Single_Instance.template Fixes JSON to YAML conversion bug 2015-06-25 07:32:34 -07:00
WordPress_Single_Instance.yaml tests : convert test_template_format to test-local templates 2013-05-08 12:39:47 +01:00

README

These templates are required by test_template_format and test_provider_template
in situations where we don't want to use a minimal template snippet. Ideally we
want to test the maximum possible syntax to prove the format conversion works.

In general, tests should not depend on these templates, inline minimal
template snippets are preferred.