[PATCH 5/5] Move changes from action ctors into apply methods.
Vratislav Podzimek
vpodzime at redhat.com
Tue Apr 22 16:08:41 UTC 2014
On Tue, 2014-04-22 at 10:26 -0500, David Lehman wrote:
> The apply method is called from DeviceTree.registerAction, so there is no
> need to change any code that creates actions.
> ---
> blivet/deviceaction.py | 106 +++++++++++++++++++++++++++++++++++++++++++++----
> blivet/devicetree.py | 2 +
> tests/action_test.py | 55 +++++++++++++++++++++----
> 3 files changed, 148 insertions(+), 15 deletions(-)
>
> diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
> index 4a50a1a..d1edec7 100644
> --- a/blivet/deviceaction.py
> +++ b/blivet/deviceaction.py
> @@ -153,14 +153,20 @@ class DeviceAction(util.ObjectID):
> raise ValueError("arg 1 must be a StorageDevice instance")
> self.device = device
> self.container = getattr(self.device, "container", None)
> + self.applied = False
I'd like to this to be self._applied. Or should it be used from the
outside somewhere?
> +
> + def apply(self):
> + """ apply changes related to the action to the device(s) """
> + self.applied = True
>
> def execute(self):
> """ perform the action """
> - pass
> + if not self.applied:
> + raise RuntimeError("cannot execute unapplied action")
>
> def cancel(self):
> """ cancel the action """
> - pass
> + self.applied = False
>
> @property
> def isDestroy(self):
> @@ -280,6 +286,7 @@ class ActionCreateDevice(DeviceAction):
> DeviceAction.__init__(self, device)
>
> def execute(self):
> + super(ActionCreateDevice, self).execute()
> self.device.create()
>
> def requires(self, action):
> @@ -328,6 +335,7 @@ class ActionDestroyDevice(DeviceAction):
> DeviceAction.__init__(self, device)
>
> def execute(self):
> + super(ActionDestroyDevice, self).execute()
> self.device.destroy()
>
> # Make sure libparted does not keep cached info for this device
> @@ -427,13 +435,26 @@ class ActionResizeDevice(DeviceAction):
> else:
> self.origsize = device.size
>
> - self.device.targetSize = newsize
> + self.targetSize = newsize
And this should be self._targetSize.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list