Fix no-change updates of failed resources with restricted actions

If a resource is in a FAILED state, but the plugin overrides
_needs_update() to not raise UpdateReplace, and also no actual update is
required, we simply change the resource's state to UPDATE_COMPLETE.
However, if there were restricted actions set in the environment, this code
path was not executed. The behaviour should be the same regardless of
whether there are restrictions that have been checked.

Change-Id: Ib3ed081f9f26f4f9172c681bf9ebccb7cdc3ca9c
Related-Bug: #1663522
This commit is contained in:
Zane Bitter 2017-07-21 21:32:45 -04:00
parent 1da0790e0d
commit 0e1b4908e5
1 changed files with 24 additions and 22 deletions

View File

@ -1360,6 +1360,8 @@ class Resource(status.ResourceStatus):
self.update_template_diff_properties(after_props, before_props)
return True
else:
return False
def _check_restricted_actions(self, actions, after, before,
after_props, before_props,
@ -1383,6 +1385,8 @@ class Resource(status.ResourceStatus):
raise exception.ResourceActionRestricted(action='replace')
raise
return False
def _prepare_update_props(self, after, before):
before_props = before.properties(self.properties_schema,
@ -1472,29 +1476,27 @@ class Resource(status.ResourceStatus):
registry = self.stack.env.registry
restr_actions = registry.get_rsrc_restricted_actions(self.name)
if restr_actions:
if not self._check_restricted_actions(restr_actions,
after, before,
after_props,
before_props,
prev_resource):
if update_templ_func is not None:
update_templ_func(persist=True)
return
needs_update = self._check_restricted_actions(restr_actions,
after, before,
after_props,
before_props,
prev_resource)
else:
if not self._needs_update(after, before,
after_props, before_props,
prev_resource):
if update_templ_func is not None:
update_templ_func(persist=True)
if self.status == self.FAILED:
status_reason = _('Update status to COMPLETE for '
'FAILED resource neither update '
'nor replace.')
lock = (self.LOCK_RESPECT if self.stack.convergence
else self.LOCK_NONE)
self.state_set(self.action, self.COMPLETE,
status_reason, lock=lock)
return
needs_update = self._needs_update(after, before,
after_props, before_props,
prev_resource)
if not needs_update:
if update_templ_func is not None:
update_templ_func(persist=True)
if self.status == self.FAILED:
status_reason = _('Update status to COMPLETE for '
'FAILED resource neither update '
'nor replace.')
lock = (self.LOCK_RESPECT if self.stack.convergence
else self.LOCK_NONE)
self.state_set(self.action, self.COMPLETE,
status_reason, lock=lock)
return
if not self.stack.convergence:
if (self.action, self.status) in (