diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 940364e8f..d34ba2b87 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -172,6 +172,7 @@ class Stack(collections.Mapping): self._dependencies = None self._access_allowed_handlers = {} self._db_resources = None + self._tags = tags self.adopt_stack_data = adopt_stack_data self.stack_user_project_id = stack_user_project_id self.created_time = created_time @@ -230,6 +231,19 @@ class Stack(collections.Mapping): else: self.outputs = {} + @property + def tags(self): + if self._tags is None: + tags = stack_tag_object.StackTagList.get( + self.context, self.id) + if tags: + self._tags = [t.tag for t in tags] + return self._tags + + @tags.setter + def tags(self, value): + self._tags = value + @property def worker_client(self): """Return a client for making engine RPC calls.""" @@ -494,9 +508,6 @@ class Stack(collections.Mapping): use_stored_context=False, cache_data=None): template = tmpl.Template.load( context, stack.raw_template_id, stack.raw_template) - tags = None - if stack.tags: - tags = [t.tag for t in stack.tags] return cls(context, stack.name, template, stack_id=stack.id, action=stack.action, status=stack.status, @@ -512,7 +523,7 @@ class Stack(collections.Mapping): user_creds_id=stack.user_creds_id, tenant_id=stack.tenant, use_stored_context=use_stored_context, username=stack.username, convergence=stack.convergence, - current_traversal=stack.current_traversal, tags=tags, + current_traversal=stack.current_traversal, prev_raw_template_id=stack.prev_raw_template_id, current_deps=stack.current_deps, cache_data=cache_data) diff --git a/heat/objects/stack.py b/heat/objects/stack.py index 108739b7a..f3120c801 100644 --- a/heat/objects/stack.py +++ b/heat/objects/stack.py @@ -60,7 +60,6 @@ class Stack( 'current_deps': heat_fields.JsonField(), 'prev_raw_template_id': fields.IntegerField(), 'prev_raw_template': fields.ObjectField('RawTemplate'), - 'tags': fields.ObjectField('StackTagList'), 'parent_resource_name': fields.StringField(nullable=True), } @@ -71,9 +70,6 @@ class Stack( stack['raw_template'] = ( raw_template.RawTemplate.get_by_id( context, db_stack['raw_template_id'])) - elif field == 'tags': - stack['tags'] = stack_tag.StackTagList.from_db_object( - context, db_stack.get(field)) else: stack[field] = db_stack.__dict__.get(field) stack._context = context @@ -215,3 +211,7 @@ class Stack( def identifier(self): """Return an identifier for this stack.""" return identifier.HeatIdentifier(self.tenant, self.name, self.id) + + @property + def tags(self): + return stack_tag.StackTagList.get(self._context, self.id) diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index 537891d10..de54dcb17 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -347,7 +347,6 @@ class StackTest(common.HeatTestCase): username=mox.IgnoreArg(), convergence=False, current_traversal=self.stack.current_traversal, - tags=mox.IgnoreArg(), prev_raw_template_id=None, current_deps=None, cache_data=None) @@ -1276,6 +1275,23 @@ class StackTest(common.HeatTestCase): ctx_expected['auth_token'] = None self.assertEqual(ctx_expected, self.stack.stored_context().to_dict()) + def test_tags_property_get_set(self): + self.stack = stack.Stack(self.ctx, 'stack_tags', self.tmpl) + self.stack.store() + stack_id = self.stack.id + test_stack = stack.Stack.load(self.ctx, stack_id=stack_id) + self.assertIsNone(test_stack.tags) + + self.stack = stack.Stack(self.ctx, 'stack_name', self.tmpl) + self.stack.tags = ['tag1', 'tag2'] + self.assertEqual(['tag1', 'tag2'], self.stack._tags) + self.stack.store() + stack_id = self.stack.id + test_stack = stack.Stack.load(self.ctx, stack_id=stack_id) + self.assertIsNone(test_stack._tags) + self.assertEqual(['tag1', 'tag2'], test_stack.tags) + self.assertEqual(['tag1', 'tag2'], test_stack._tags) + def test_load_reads_tags(self): self.stack = stack.Stack(self.ctx, 'stack_tags', self.tmpl) self.stack.store()