Make sure the resource exists before trying to update it.

Change-Id: I5d8bdc0f4ceff61cab0b909dcaaf8ab5952ba4af
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-06-05 10:57:08 +10:00
parent f0b75758f6
commit 4a19ab5903
1 changed files with 8 additions and 5 deletions

View File

@ -137,11 +137,14 @@ class Resource(object):
except Exception as ex:
logger.warn('db error %s' % str(ex))
elif new_state is not self.CREATE_IN_PROGRESS:
rs = db_api.resource_get(None, self.id)
rs.update_and_save({'state': new_state})
if rs.stack:
rs.stack.update_and_save({'updated_at': datetime.utcnow()})
elif self.id is not None:
try:
rs = db_api.resource_get(self.stack.context, self.id)
rs.update_and_save({'state': new_state})
if rs.stack:
rs.stack.update_and_save({'updated_at': datetime.utcnow()})
except Exception as ex:
logger.warn('db error %s' % str(ex))
if new_state != self.state:
ev = {}