Delete db resources not in template

When migrating stacks to convergence, if there are resources in
the database that are not in the current_template_id of the stack,
they are possibly of no isue, so it would better to delete those
resources from db to avoid any future update issues.

Change-Id: Ica99cec6765d22d7ee2262e2d402b2e98cb5bd5e
Story: #2004071
Task: 27092
This commit is contained in:
rabi 2018-10-12 13:35:47 +05:30
parent f12fb69cb2
commit 43583b4a32
1 changed files with 10 additions and 1 deletions

View File

@ -2242,7 +2242,16 @@ class Stack(collections.Mapping):
db_rsrcs = self.db_active_resources_get()
if db_rsrcs is not None:
for res in db_rsrcs.values():
res.update_and_save(values=values)
# delete db resources not in current_template_id
try:
self.defn.resource_definition(res.name)
except KeyError:
LOG.warning("Resource %(res)s not found in template "
"for stack %(st)s, deleting from db.",
{'res': res.name, 'st': self.id})
resource_objects.Resource.delete(self.context, res.id)
else:
res.update_and_save(values=values)
self.set_resource_deps()
self.current_traversal = uuidutils.generate_uuid()
self.convergence = True