Ensure use of stored properties in actions

This patch gives effect to the change intended to be implemented in
6bc25ef0e0.

The Resource._do_action() method is a co-routine, but in a number of
less common resource actions, we simply return the result of calling it
rather than turning the action into a wrappertask and yielding it. This
works fine (the action returns a generator; the caller doesn't care
where it came from) and reduces the amount of wrapper frames on the
stack.

However, in most cases we want the stored properties to be used while
calling _do_action(). However, to ensure that they are actually in place
when the co-routine is running, we must yield rather than return the
generator. In the suspend, resume, snapshot, and chekc actions we were
not doing that. It is not known whether any resource types are actually
accessing properties during any of these actions.

Change-Id: I2b2a87ccf1988821a250373fea261c1850e5c51b
This commit is contained in:
Zane Bitter 2019-12-17 22:29:04 -05:00
parent 5c6038f7a2
commit 0e2174fb3e
1 changed files with 8 additions and 4 deletions

View File

@ -1731,6 +1731,7 @@ class Resource(status.ResourceStatus):
"""
pass
@scheduler.wrappertask
def check(self):
"""Checks that the physical resource is in its expected state.
@ -1752,7 +1753,7 @@ class Resource(status.ResourceStatus):
raise failure
with self.frozen_properties():
return self._do_action(action)
yield self._do_action(action)
else:
if self.state == (self.INIT, self.COMPLETE):
# No need to store status; better to leave the resource in
@ -1777,6 +1778,7 @@ class Resource(status.ResourceStatus):
if invalid_checks:
raise exception.Error('; '.join(invalid_checks))
@scheduler.wrappertask
def suspend(self):
"""Return a task to suspend the resource.
@ -1796,8 +1798,9 @@ class Resource(status.ResourceStatus):
LOG.info('suspending %s', self)
with self.frozen_properties():
return self._do_action(action)
yield self._do_action(action)
@scheduler.wrappertask
def resume(self):
"""Return a task to resume the resource.
@ -1817,13 +1820,14 @@ class Resource(status.ResourceStatus):
LOG.info('resuming %s', self)
with self.frozen_properties():
return self._do_action(action)
yield self._do_action(action)
@scheduler.wrappertask
def snapshot(self):
"""Snapshot the resource and return the created data, if any."""
LOG.info('snapshotting %s', self)
with self.frozen_properties():
return self._do_action(self.SNAPSHOT)
yield self._do_action(self.SNAPSHOT)
@scheduler.wrappertask
def delete_snapshot(self, data):