]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Set the stack updated time through the Timestamp
authorZane Bitter <zbitter@redhat.com>
Fri, 13 Jul 2012 20:46:20 +0000 (16:46 -0400)
committerZane Bitter <zbitter@redhat.com>
Fri, 13 Jul 2012 20:46:20 +0000 (16:46 -0400)
Don't allow the resource class to modify the parent stack's database
representation directly.

Change-Id: Iff93d1430f4cb0695e729d0cf8f784ccb2ed7598
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resources.py

index 2d246939145c01eddb20227c1eba35063238b986..a7a70d8529708fb5d7e8795c189a385592137762 100644 (file)
@@ -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))