Update: Keep a copy of the old template for rollback

To implement the blueprint update-failure-recovery we will need to modify
the current template as we change the stack. We'll need an unmodified copy
to roll back to in the event of failure, so base the previous stack on a
copy.

Change-Id: Ic06acd3c9a89312d1ad8922e26ab02bee4bafeb0
Allow raw templates to be updated in the DB

Note that although this raw_template_update_template() will get called at
least every time the stack changes state (so twice for each operation), the
performance cost is negligible: we use the context's session, so the get()
will just retrieve the session's cached object, and we don't issue the
write unless the template has actually changed.

Change-Id: I3f231b88d08ab31c275cb9fecbf2600456c793c3
Update template incrementally as resources change

As a stack update progresses, maintain the contents of the template so that
they represent the current running state of the stack, instead of only
switching over wholesale at the end, so that if a failure occurs our state
and the template stored will be consistent.

Change-Id: If79e8b1dc212c548cad92fdbc340d61f5650f9d4
Implements: partial-blueprint update-failure-recovery
Closes-Bug: #1330016
Update: persist current template on change

After each resource is updated, persist the modified template to the
database so that any new resources will be accessible to API calls -
including signals to new WaitConditionHandles. This also ensures that if
the Heat engine dies completely during an update, the template in the
database will still be in a consistent state.

Change-Id: Ie6f234302cf72213d4b0e1f5b963cd8def422498
Closes-Bug: #1291905
Closes-Bug: #1206702
Closes-Bug: #1328342
Implements: partial-blueprint update-failure-recovery
Merge "Update: Keep a copy of the old template for rollback"
Merge "Allow raw templates to be updated in the DB"
Merge "Update template incrementally as resources change"
Merge "Update: persist current template on change"