Re: [PATCH] Implement the format disk question as a callback.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pls ignore this one.   The difference between the two is that in one we
ignore the creation of the device.format for the raid memebers and in
this one we don't.
On Fri, Mar 06, 2009 at 04:53:37PM +0100, Joel Granados Moreno wrote:
> ---
>  storage/devices.py    |   27 +++++++------
>  storage/devicetree.py |  101 +++++++++++++++++++++++++++----------------------
>  storage/errors.py     |    3 +
>  3 files changed, 74 insertions(+), 57 deletions(-)
> 
> diff --git a/storage/devices.py b/storage/devices.py
> index dd5a4f1..24153fc 100644
> --- a/storage/devices.py
> +++ b/storage/devices.py
> @@ -101,6 +101,7 @@ from devicelibs import lvm
>  #import block
>  from devicelibs import dm
>  import parted
> +import platform
>  
>  from errors import *
>  from iutil import log_method_call, notify_kernel, numeric_type
> @@ -636,8 +637,8 @@ class DiskDevice(StorageDevice):
>      _type = "disk"
>  
>      def __init__(self, device, format=None,
> -                 size=None, major=None, minor=None,
> -                 sysfsPath='', parents=None, init = False, labeltype = None):
> +                 size=None, major=None, minor=None, sysfsPath='', \
> +                 parents=None, initcb=None):
>          """ Create a DiskDevice instance.
>  
>              Arguments:
> @@ -654,8 +655,7 @@ class DiskDevice(StorageDevice):
>                  parents -- a list of required Device instances
>                  removable -- whether or not this is a removable device
>  
> -                init -- initialize label on this drive
> -                labeltype -- type of the label to use during initialization
> +                initcb -- the call back to be used when initiating disk.
>  
>  
>              DiskDevices always exist.
> @@ -671,12 +671,15 @@ class DiskDevice(StorageDevice):
>          if not self.partedDevice:
>              raise DeviceError("cannot find parted device instance")
>          log.debug("creating parted Disk: %s" % self.path)
> -        if init:
> -            self.partedDisk = parted.freshDisk(device=self.partedDevice, ty = labeltype)
> -        else:
> +        try:
>              self.partedDisk = parted.Disk(device=self.partedDevice)
> -        if not self.partedDisk:
> -            raise DeviceError("failed to create parted Disk")
> +        except parted.IOException:
> +            # if we have a cb function use it. else an error.
> +            if initcb is not None and initcb():
> +                self.partedDisk = parted.freshDisk(device=self.partedDevice, \
> +                        ty = platform.getPlatform(None).diskType)
> +            else:
> +                raise DeviceUserDeniedFormatError("User prefered to not format.")
>  
>          self.probe()
>  
> @@ -2159,7 +2162,7 @@ class DMRaidArrayDevice(DiskDevice):
>      devDir = "/dev/mapper"
>  
>      def __init__(self, name, raidSet=None, level=None, format=None, size=None,
> -                 major=None, minor=None, parents=None, sysfsPath=''):
> +                 major=None, minor=None, parents=None, sysfsPath='', initcb=None):
>          """ Create a DMRaidArrayDevice instance.
>  
>              Arguments:
> @@ -2180,8 +2183,8 @@ class DMRaidArrayDevice(DiskDevice):
>                  if not parent.format or parent.format.type != "dmraidmember":
>                      raise ValueError("parent devices must contain dmraidmember format")
>          DiskDevice.__init__(self, name, format=format, size=size,
> -                            major=major, minor=minor,
> -                            parents=parents, sysfsPath=sysfsPath)
> +                            major=major, minor=minor, parents=parents,
> +                            sysfsPath=sysfsPath, initcb=initcb)
>  
>          self.formatClass = get_device_format_class("dmraidmember")
>          if not self.formatClass:
> diff --git a/storage/devicetree.py b/storage/devicetree.py
> index 41e43f9..af265a7 100644
> --- a/storage/devicetree.py
> +++ b/storage/devicetree.py
> @@ -28,8 +28,6 @@ from devices import *
>  from deviceaction import *
>  import formats
>  from udev import *
> -import parted
> -import platform
>  
>  import gettext
>  _ = lambda x: gettext.ldgettext("anaconda", x)
> @@ -117,7 +115,26 @@ def getLUKSPassphrase(intf, device, globalPassphrase):
>  
>      return (passphrase, isglobal)
>  
> - 
> +# Don't really know where to put this.
> +def questionInitializeDisk(intf=None, name=None):
> +    retVal = False # The less destructive default
> +    if not intf or not name:
> +        pass
> +    else:
> +        rc = intf.messageWindow(_("Warning"),
> +                _("Error processing drive %s.\n"
> +                  "Maybe it needs to be reinitialized."
> +                  "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,),
> +                type="custom",
> +                custom_buttons = [ _("_Ignore drive"),
> +                                   _("_Re-initialize drive") ],
> +                custom_icon="question")
> +        if rc == 0:
> +            pass
> +        else:
> +            retVal = True
> +    return retVal
> +
>  class DeviceTree(object):
>      """ A quasi-tree that represents the devices in the system.
>  
> @@ -778,32 +795,15 @@ class DeviceTree(object):
>              device = self.getDeviceByName(name)
>              if device is None:
>                  try:
> +                    cb=lambda:questionInitializeDisk(self.intf, name)
>                      device = DiskDevice(name,
>                                      major=udev_device_get_major(info),
>                                      minor=udev_device_get_minor(info),
> -                                    sysfsPath=sysfs_path)
> +                                    sysfsPath=sysfs_path,
> +                                    initcb=cb)
>                      self._addDevice(device)
> -                except parted.IOException: #drive not initialized?
> -                    if not self.intf:
> -                        self.ignoredDisks.append(name)
> -                    else:
> -                        rc = self.intf.messageWindow(_("Warning"),
> -                                _("Error processing drive %s.\n"
> -                                  "Maybe it needs to be reinitialized."
> -                                  "YOU WILL LOSE ALL DATA ON THIS DRIVE!") % (name,),
> -                                type="custom",
> -                                custom_buttons = [ _("_Ignore drive"),
> -                                                   _("_Re-initialize drive") ],
> -                                custom_icon="question")
> -                        if rc == 0:
> -                            self.ignoredDisks.append(name)
> -                        else:
> -                            device = DiskDevice(name,
> -                                            major=udev_device_get_major(info),
> -                                            minor=udev_device_get_minor(info),
> -                                            sysfsPath=sysfs_path, init = True,
> -                                            labeltype = platform.getPlatform(None).diskType)
> -                            self._addDevice(device)
> +                except DeviceUserDeniedFormatError: #drive not initialized?
> +                    self.ignoredDisks.append(name)
>          elif udev_device_is_partition(info):
>              log.debug("%s is a partition" % name)
>              device = self.getDeviceByName(name)
> @@ -954,27 +954,38 @@ class DeviceTree(object):
>                      # FIXME: Should handle not finding a dmriad dev better
>                      pass
>  
> -                dm_array = self.getDeviceByName(rs.name)
> -                if dm_array is not None:
> -                    # We add the new device.
> -                    dm_array._addDevice(device)
> +                if rs.name not in self.ignoredDisks:
> +                    dm_array = self.getDeviceByName(rs.name)
> +                    if dm_array is not None:
> +                        # We add the new device.
> +                        dm_array._addDevice(device)
> +                    else:
> +                        # Activate the Raid set.
> +                        rs.activate(mknod=True)
> +
> +                        # Create the DMRaidArray
> +                        try:
> +                            cb=lambda:questionInitializeDisk(self.intf,rs.name)
> +                            dm_array = DMRaidArrayDevice(rs.name,
> +                                                major=major, minor=minor,
> +                                                raidSet=rs,
> +                                                level=rs.level,
> +                                                parents=[device],
> +                                                initcb=cb)
> +                        except DeviceUserDeniedFormatError:
> +                            self.ignoredDisks.append(rs.name)
> +                            rs.deactivate()
> +
> +                        self._addDevice(dm_array)
> +
> +                    # Use the rs's object on the device.
> +                    device.format.raidmem = block.getMemFromRaidSet(dm_array, \
> +                            major=major, minor=minor,
> +                            uuid=uuid, name=name)
>                  else:
> -                    # Activate the Raid set.
> -                    rs.activate(mknod=True)
> -
> -                    # Create the DMRaidArray
> -                    dm_array = DMRaidArrayDevice(rs.name,
> -                                                 major=major, minor=minor,
> -                                                 raidSet=rs,
> -                                                 level=rs.level,
> -                                                 parents=[device])
> -
> -                    self._addDevice(dm_array)
> -
> -                # Use the rs's object on the device.
> -                device.format.raidmem = block.getMemFromRaidSet(dm_array, \
> -                        major=major, minor=minor,
> -                        uuid=uuid, name=name)
> +                    # Here we might want to make sure we ignore all of the
> +                    # devices that compose the dmriad.
> +                    pass
>              elif format.type == "lvmpv":
>                  # lookup/create the VG and LVs
>                  try:
> diff --git a/storage/errors.py b/storage/errors.py
> index 692e0ac..8fb57b1 100644
> --- a/storage/errors.py
> +++ b/storage/errors.py
> @@ -21,6 +21,9 @@ class DeviceTeardownError(DeviceError):
>  class DeviceResizeError(DeviceError):
>      pass
>  
> +class DeviceUserDeniedFormatError(DeviceError):
> +    pass
> +
>  # DeviceFormat
>  class DeviceFormatError(Exception):
>      pass
> -- 
> 1.6.0.6
> 
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

-- 
Joel Andres Granados
Brno, Czech Republic, Red Hat.

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux