Currently translation mechanism has several mistakes, depended on modifying data before it’s using - so functions cannot be correctly translated; heavy dependence on HOT and Cfn functions; muddy code full of tricks. This spec is designed to discuss with community better way to re-implement translation mechanism.
Translation mechanism (TM) has been implemented in Kilo, refactored in Newton and still works incorrectly. There are several cases, which should be mandatory fixed:
TM incorrectly handles functions - if TM found function in the middle of translation path, it doesn’t resolve it and raises error, because cannot get next item in translation path. For example, if property networks equals function, and translation path equals to [networks, network], then network won’t get in case of function has no get method.
Current workaround suggests just to skip such translation rules, where there is such situation.
TM modifies properties data before it’s using, which is useless. At first, modifying data is unsafe. At second, if first step will be fixed, functions resolved and return resolved data every time they called, so translations cannot work with them.
TM depends on HOT and Cfn template formats - this makes it impossible for third-party template format plugins to be first-class citizens in Heat, as they are liable to break whenever someone adds a translation rule.
TM code has many muddy and tricky places, which should be facilitated and made clearer.
Before suggesting solution need to note, that changes concerned translation mechanism, but don’t translation rules and how they specified in resource plugins for support third-party resources.
Next changes should fix TM and improve it:
Make translation phase during getting properties. It assume that functions will be resolved before translation, properties will always return translated value.
- improve currently useless name variable in Property class, which will store full name of property, for example networks.network;
- operate with translation rules inside of properties - store TM object and pass it to properties sub-schemas;
- call translation before cast to defined property type - if there’s any translation.
Store translated result for already called properties - it helps doesn’t translate property every time it’s called. Translated values will be stored by full name as networks.network.
Result should not stored during validation phase.
Also, instead of storing translated result in explicitly in some dict, we can use cache instead, but there could be issues, like in LP#1609787 bug.
Refactor and facilitate huge code of TM due to previous steps try to do code more clear to understand.
Add functional tests to cover different risky cases.
Change current version TM, adding fixes for mentioned problems.