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