From fba2ed3921b132621a42c95eb2230829273f431e Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 13 Jul 2012 16:46:20 -0400 Subject: [PATCH] Set the stack updated time through the Timestamp Don't allow the resource class to modify the parent stack's database representation directly. Change-Id: Iff93d1430f4cb0695e729d0cf8f784ccb2ed7598 Signed-off-by: Zane Bitter --- heat/engine/resources.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/heat/engine/resources.py b/heat/engine/resources.py index 2d246939..a7a70d85 100644 --- a/heat/engine/resources.py +++ b/heat/engine/resources.py @@ -89,6 +89,13 @@ class Timestamp(object): o.refresh(attrs=[self.attribute]) return getattr(o, self.attribute) + def __set__(self, obj, timestamp): + '''Update the timestamp for the given object.''' + if obj.id is None: + raise AttributeError("%s has not yet been created" % str(obj)) + o = self.db_fetch(obj.context, obj.id) + o.update_and_save({self.attribute: timestamp}) + class Resource(object): CREATE_IN_PROGRESS = 'IN_PROGRESS' @@ -296,8 +303,7 @@ class Resource(object): new_rs = db_api.resource_create(self.context, rs) self.id = new_rs.id - if new_rs.stack: - new_rs.stack.update_and_save({'updated_at': datetime.utcnow()}) + self.stack.updated_time = datetime.utcnow() except Exception as ex: logger.error('DB error %s' % str(ex)) @@ -330,8 +336,7 @@ class Resource(object): 'state_description': reason, 'nova_instance': self.instance_id}) - if rs.stack: - rs.stack.update_and_save({'updated_at': datetime.utcnow()}) + self.stack.updated_time = datetime.utcnow() except Exception as ex: logger.error('DB error %s' % str(ex)) -- 2.45.2