]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
resource state_set, abstract update/store logic
authorSteven Hardy <shardy@redhat.com>
Wed, 12 Dec 2012 14:57:11 +0000 (14:57 +0000)
committerSteven Hardy <shardy@redhat.com>
Wed, 12 Dec 2012 17:15:03 +0000 (17:15 +0000)
Abstract the DB update/store logic so the state_set function
can be more cleanly overridden for AutoScalingGroupInstance

ref bug 1089338

Change-Id: I02dc52068feaeed8ec8210269d9abb7b124f0a19
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/engine/resource.py

index cc16e41b637c7884c92165120e12ef4ccdc079bf..bfca7a53e000ed4ae646e7adb8c9e9492ee88f95 100644 (file)
@@ -360,8 +360,8 @@ class Resource(object):
         except Exception as ex:
             logger.error('DB error %s' % str(ex))
 
-    def state_set(self, new_state, reason="state changed"):
-        self.state, old_state = new_state, self.state
+    def _store_or_update(self, new_state, reason):
+        self.state = new_state
         self.state_description = reason
 
         if self.id is not None:
@@ -381,6 +381,10 @@ class Resource(object):
         elif new_state == self.CREATE_IN_PROGRESS:
             self._store()
 
+    def state_set(self, new_state, reason="state changed"):
+        old_state = self.state
+        self._store_or_update(new_state, reason)
+
         if new_state != old_state:
             self._add_event(new_state, reason)