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

Re: [PATCH 3/3] Display progress or wait window when creating devices.



Hi,

On 11/25/2009 11:59 PM, David Lehman wrote:
For devices created using an external utility we can display a
pulsing progressWindow. For devices created using a python module
we display a waitWindow.
---
  storage/devices.py |  128 +++++++++++++++++++++++++++++++++++++---------------
  1 files changed, 92 insertions(+), 36 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index ff7698f..81708ce 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -1165,17 +1165,28 @@ class PartitionDevice(StorageDevice):
          self.createParents()
          self.setupParents()

-        self.disk.format.addPartition(self.partedPartition)
-        self.disk.format.commit()
+        w = None
+        if intf:
+            w = intf.waitWindow(_("Creating"),
+                                _("Creating device %s") % (self.path,))

-        # Ensure old metadata which lived in freespace so did not get
-        # explictly destroyed by a destroyformat action gets wiped
-        DeviceFormat(device=self.path, exists=True).destroy()
+        try:
+            self.disk.format.addPartition(self.partedPartition)
+            self.disk.format.commit()

-        self.partedPartition = self.disk.format.partedDisk.getPartitionByPath(self.path)
+            # Ensure old metadata which lived in freespace so did not get
+            # explictly destroyed by a destroyformat action gets wiped
+            DeviceFormat(device=self.path, exists=True).destroy()
+        except Exception:
+            raise
+        else:
+            self.partedPartition = self.disk.format.partedDisk.getPartitionByPath(self.path)

-        self.exists = True
-        self.setup()
+            self.exists = True
+            self.setup()
+        finally:
+            if w:
+                w.pop()

      def _computeResize(self, partition):
          log_method_call(self, self.name, status=self.status)
@@ -1745,6 +1756,12 @@ class LVMVolumeGroupDevice(DMDevice):
          if self.exists:
              raise DeviceError("device already exists", self.name)

+        w = None
+        if intf:
+            w = intf.progressWindow(_("Creating"),
+                                    _("Creating device %s")
+                                    % (self.path,),
+                                    100, pulse = True)
          pv_list = []
          #for pv in self.parents:
              # This is a little bit different from other devices in that
@@ -1756,10 +1773,17 @@ class LVMVolumeGroupDevice(DMDevice):
          pv_list = [pv.path for pv in self.parents]
          self.createParents()
          self.setupParents()
-        lvm.vgcreate(self.name, pv_list, self.peSize)
-        # FIXME set / update self.uuid here
-        self.exists = True
-        self.setup()
+        try:
+            lvm.vgcreate(self.name, pv_list, self.peSize, progress=w)
+        except Exception:
+            raise
+        else:
+            # FIXME set / update self.uuid here
+            self.exists = True
+            self.setup()
+        finally:
+            if w:
+                w.pop()

      def destroy(self):
          """ Destroy the device. """
@@ -2127,14 +2151,27 @@ class LVMLogicalVolumeDevice(DMDevice):
          if self.exists:
              raise DeviceError("device already exists", self.name)

+        w = None
+        if intf:
+            w = intf.progressWindow(_("Creating"),
+                                    _("Creating device %s")
+                                    % (self.path,),
+                                    100, pulse = True)
          self.createParents()
          self.setupParents()


You create the window here before the createParents() and setuParents(), but
those could fail, and the window never gets popped, I think you should put
these below the try too.

-        # should we use --zero for safety's sake?
-        lvm.lvcreate(self.vg.name, self._name, self.size)
-        # FIXME set / update self.uuid here
-        self.exists = True
-        self.setup()
+        try:
+            # should we use --zero for safety's sake?
+            lvm.lvcreate(self.vg.name, self._name, self.size, progress=w)
+        except Exception:
+            raise
+        else:
+            # FIXME set / update self.uuid here
+            self.exists = True
+            self.setup()
+        finally:
+            if w:
+                w.pop()

      def destroy(self):
          """ Destroy the device. """
@@ -2551,23 +2588,38 @@ class MDRaidArrayDevice(StorageDevice):
          if self.exists:
              raise DeviceError("device already exists", self.name)

+        w = None
+        if intf:
+            w = intf.progressWindow(_("Creating"),
+                                    _("Creating device %s")
+                                    % (self.path,),
+                                    100, pulse = True)
          disks = [disk.path for disk in self.devices]
          self.createParents()
          self.setupParents()
          spares = len(self.devices) - self.memberDevices

The same.
-        mdraid.mdcreate(self.path,
-                        self.level,
-                        disks,
-                        spares)
-        self.exists = True
-        # the array is automatically activated upon creation, but...
-        self.setup()
-        udev_settle()
-        self.updateSysfsPath()
-        info = udev_get_block_device(self.sysfsPath)
-        self.uuid = udev_device_get_md_uuid(info)
-        for member in self.devices:
-            member.mdUuid = self.uuid
+
+        try:
+            mdraid.mdcreate(self.path,
+                            self.level,
+                            disks,
+                            spares,
+                            progress=w)
+        except Exception:
+            raise
+        else:
+            self.exists = True
+            # the array is automatically activated upon creation, but...
+            self.setup()
+            udev_settle()
+            self.updateSysfsPath()
+            info = udev_get_block_device(self.sysfsPath)
+            self.uuid = udev_device_get_md_uuid(info)
+            for member in self.devices:
+                member.mdUuid = self.uuid
+        finally:
+            if w:
+                w.pop()

      @property
      def formatArgs(self):
@@ -2969,24 +3021,28 @@ class FileDevice(StorageDevice):
          if self.exists:
              raise DeviceError("device already exists", self.name)

+        w = None
+        if intf:
+            w = intf.waitWindow(_("Creating"),
+                                _("Creating file %s") % (self.path,))
+
          # this only checks that parents exist
          self.createParents()
          self.setupParents()


And once more the same.


          try:
              fd = os.open(self.path, os.O_RDWR)
-        except OSError as e:
-            raise DeviceError(e, self.name)
-
-        try:
              buf = '\0' * 1024 * 1024 * self.size
              os.write(fd, buf)
          except (OSError, TypeError) as e:
              log.error("error writing out %s: %s" % (self.path, e))
+            raise DeviceError(e, self.name)
+        else:
+            self.exists = True
          finally:
              os.close(fd)
-
-        self.exists = True
+            if w:
+                w.pop()

      def destroy(self):
          """ Destroy the device. """

Regards,

Hans


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