diff --git a/heat/db/sqlalchemy/migrate_repo/versions/034_raw_template_files.py b/heat/db/sqlalchemy/migrate_repo/versions/034_raw_template_files.py new file mode 100644 index 0000000000..4f657540d9 --- /dev/null +++ b/heat/db/sqlalchemy/migrate_repo/versions/034_raw_template_files.py @@ -0,0 +1,33 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import sqlalchemy +from heat.db.sqlalchemy.types import Json + + +def upgrade(migrate_engine): + meta = sqlalchemy.MetaData() + meta.bind = migrate_engine + + raw_template = sqlalchemy.Table('raw_template', meta, autoload=True) + files = sqlalchemy.Column('files', Json, default='{}') + files.create(raw_template) + + +def downgrade(migrate_engine): + meta = sqlalchemy.MetaData() + meta.bind = migrate_engine + + raw_template = sqlalchemy.Table('raw_template', meta, autoload=True) + raw_template.c.files.drop() diff --git a/heat/db/sqlalchemy/models.py b/heat/db/sqlalchemy/models.py index a453b85b3e..516c420012 100644 --- a/heat/db/sqlalchemy/models.py +++ b/heat/db/sqlalchemy/models.py @@ -87,6 +87,7 @@ class RawTemplate(BASE, HeatBase): __tablename__ = 'raw_template' id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) template = sqlalchemy.Column(Json) + files = sqlalchemy.Column(Json) class Stack(BASE, HeatBase, SoftDelete): diff --git a/heat/engine/template.py b/heat/engine/template.py index b02ac60e14..53e6b87ba8 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -57,12 +57,15 @@ class Template(collections.Mapping): def load(cls, context, template_id): '''Retrieve a Template with the given ID from the database.''' t = db_api.raw_template_get(context, template_id) - return cls(t.template, template_id) + return cls(t.template, template_id=template_id, files=t.files) def store(self, context=None): '''Store the Template in the database and return its ID.''' if self.id is None: - rt = {'template': self.t} + rt = { + 'template': self.t, + 'files': self.files + } new_rt = db_api.raw_template_create(context, rt) self.id = new_rt.id return self.id diff --git a/heat/tests/db/test_migrations.py b/heat/tests/db/test_migrations.py index cd8ca637da..aeb0ad9b5d 100644 --- a/heat/tests/db/test_migrations.py +++ b/heat/tests/db/test_migrations.py @@ -172,3 +172,6 @@ class TestHeatMigrations(test_migrations.BaseMigrationTestCase, self.assertColumnExists(engine, 'stack_lock', 'engine_id') self.assertColumnExists(engine, 'stack_lock', 'created_at') self.assertColumnExists(engine, 'stack_lock', 'updated_at') + + def _check_034(self, engine, data): + self.assertColumnExists(engine, 'raw_template', 'files') diff --git a/heat/tests/test_sqlalchemy_api.py b/heat/tests/test_sqlalchemy_api.py index 2aa78132c2..80a2ed7521 100644 --- a/heat/tests/test_sqlalchemy_api.py +++ b/heat/tests/test_sqlalchemy_api.py @@ -755,6 +755,7 @@ def create_raw_template(context, **kwargs): t = template_format.parse(wp_template) template = { 'template': t, + 'files': {'foo': 'bar'} } template.update(kwargs) return db_api.raw_template_create(context, template) @@ -856,6 +857,7 @@ class DBAPIRawTemplateTest(HeatTestCase): tp = create_raw_template(self.ctx, template=t) self.assertIsNotNone(tp.id) self.assertEqual(t, tp.template) + self.assertEqual({'foo': 'bar'}, tp.files) def test_raw_template_get(self): t = template_format.parse(wp_template)