From 7a1a65bac2215938ed7d477985f5c59491e2f3b2 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 21 Jun 2016 09:42:40 +1200 Subject: [PATCH] Create an admin context to refresh template files Its impractical to pass in the current context to TemplateFiles._refresh, and it will soon be mandatory for all db api context arguments to be not None. This change creates a short-lived context just for the refresh. It will have the same effect as the current behaviour of creating a new session, since the a new session will be associated with the context, so there is no danger of returning stale data from the current session's identity map. This change also makes the context argument mandatory for any raw templates operations that might need one. Change-Id: I156096d736aac4999a3eebe077ed50ef7384ca02 --- heat/engine/template.py | 2 +- heat/engine/template_files.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/heat/engine/template.py b/heat/engine/template.py index 9a0821de7f..d3a8ad2e4d 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -133,7 +133,7 @@ class Template(collections.Mapping): return cls(t.template, template_id=template_id, env=env, files=t_files) - def store(self, context=None): + def store(self, context): """Store the Template in the database and return its ID.""" rt = { 'template': self.t, diff --git a/heat/engine/template_files.py b/heat/engine/template_files.py index 2d028c02f0..1d9f75fbb8 100644 --- a/heat/engine/template_files.py +++ b/heat/engine/template_files.py @@ -15,6 +15,7 @@ import collections import six import weakref +from heat.common import context from heat.common.i18n import _ from heat.db import api as db_api from heat.objects import raw_template_files @@ -89,12 +90,13 @@ class TemplateFiles(collections.Mapping): self._refresh() def _refresh(self): - rtf_obj = db_api.raw_template_files_get(None, self.files_id) + ctxt = context.get_admin_context() + rtf_obj = db_api.raw_template_files_get(ctxt, self.files_id) _files_dict = ReadOnlyDict(rtf_obj.files) self.files = _files_dict _d[self.files_id] = _files_dict - def store(self, ctxt=None): + def store(self, ctxt): if not self.files or self.files_id is not None: # Do not to persist an empty raw_template_files obj. If we # already have a not null self.files_id, the (immutable)