From: Zane Bitter Date: Fri, 23 Aug 2013 23:05:47 +0000 (+0200) Subject: Add a method of creating a backup stack in the DB X-Git-Tag: 2014.1~145^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d63545118e8a250dd5f24900374d9ac0d593e0ba;p=openstack-build%2Fheat-build.git Add a method of creating a backup stack in the DB This is a temporary storage place for resources that are going to be deleted once their replacements are created. They must be moved out of the stack in order to avoid conflicting with the replacement resource. Change-Id: I081498f4c8732f893dc0d0677cf2b3f40f56d808 --- diff --git a/heat/engine/parser.py b/heat/engine/parser.py index eb796ad0..f0c57134 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -70,11 +70,12 @@ class Stack(object): stack is already in the database. ''' - if re.match("[a-zA-Z][a-zA-Z0-9_.-]*$", stack_name) is None: - raise ValueError(_('Invalid stack name %s' - ' must contain only alphanumeric or ' - '\"_-.\" characters, must start with alpha' - ) % stack_name) + if owner_id is None: + if re.match("[a-zA-Z][a-zA-Z0-9_.-]*$", stack_name) is None: + raise ValueError(_('Invalid stack name %s' + ' must contain only alphanumeric or ' + '\"_-.\" characters, must start with alpha' + ) % stack_name) self.id = stack_id self.owner_id = owner_id @@ -152,7 +153,7 @@ class Stack(object): return stack - def store(self): + def store(self, backup=False): ''' Store the stack in the database and return its ID If self.id is set, we update the existing stack @@ -160,7 +161,7 @@ class Stack(object): new_creds = db_api.user_creds_create(self.context) s = { - 'name': self.name, + 'name': self._backup_name() if backup else self.name, 'raw_template_id': self.t.store(self.context), 'parameters': self.env.user_env_as_dict(), 'owner_id': self.owner_id, @@ -183,6 +184,9 @@ class Stack(object): return self.id + def _backup_name(self): + return '%s*' % self.name + def identifier(self): ''' Return an identifier for this stack. @@ -356,6 +360,23 @@ class Stack(object): if callable(post_func): post_func() + def _backup_stack(self): + ''' + Get a Stack containing any in-progress resources from the previous + stack state prior to an update. + ''' + s = db_api.stack_get_by_name(self.context, self._backup_name(), + owner_id=self.id) + if s is not None: + logger.debug('Loaded existing backup stack') + return self.load(self.context, stack=s) + else: + prev = type(self)(self.context, self.name, self.t, self.env, + owner_id=self.id) + prev.store(backup=True) + logger.debug('Created new backup stack') + return prev + def update(self, newstack, action=UPDATE): ''' Compare the current stack with newstack,