[PATCH 2/7] Use pyanaconda.errors for error handling in storage.

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

 



---
 pyanaconda/install.py              |    3 +-
 pyanaconda/kickstart.py            |    2 +-
 pyanaconda/storage/__init__.py     |   47 ++++++++++++-----------------------
 pyanaconda/storage/partitioning.py |   23 +++++++----------
 4 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/pyanaconda/install.py b/pyanaconda/install.py
index 2727721..86ae076 100644
--- a/pyanaconda/install.py
+++ b/pyanaconda/install.py
@@ -21,7 +21,6 @@
 #
 
 from pyanaconda.constants import ROOT_PATH
-from pyanaconda.errors import errorHandler
 from pyanaconda.storage import turnOnFilesystems
 from pyanaconda.bootloader import writeBootLoader
 from pyanaconda.progress import progress_report
@@ -64,7 +63,7 @@ def doInstall(storage, payload, ksdata, instClass):
     progress.send_init(steps)
 
     # Do partitioning.
-    turnOnFilesystems(storage, errorHandler)
+    turnOnFilesystems(storage)
 
     # Do packaging.
     payload.preInstall(packages=storage.packages)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index de42e4f..3a6a20c 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -245,7 +245,7 @@ class AutoPart(commands.autopart.F16_AutoPart):
         if not self.lvm:
             storage.lvmAutoPart = False
 
-        doAutoPartition(storage, ksdata, errorcb=errorHandler.cb, warningcb=errorHandler.cb)
+        doAutoPartition(storage, ksdata)
 
 class Bootloader(commands.bootloader.F17_Bootloader):
     def execute(self, storage, ksdata, instClass):
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 132785b..c38df6a 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -36,6 +36,7 @@ from pyanaconda.constants import *
 from pykickstart.constants import *
 from pyanaconda.flags import flags
 from pyanaconda import tsort
+from pyanaconda.errors import *
 
 from errors import *
 from devices import *
@@ -208,12 +209,9 @@ def storageComplete(anaconda):
     if rc == 0:
         return DISPATCH_BACK
 
-def turnOnFilesystems(storage, errorcb=None):
+def turnOnFilesystems(storage):
     from pyanaconda.upgrade import bindMountDevDirectory
 
-    if errorcb is None:
-        errorcb = lambda *args,**kwargs: True
-
     upgrade = "preupgrade" in flags.cmdline
 
     if not upgrade:
@@ -232,15 +230,17 @@ def turnOnFilesystems(storage, errorcb=None):
 
     try:
         storage.doIt()
-    except FSResizeError as (msg, device):
+    except FSResizeError as e:
         if os.path.exists("/tmp/resize.out"):
             details = open("/tmp/resize.out", "r").read()
         else:
-            details = "%s" %(msg,)
+            details = e.args[1]
 
-        errorcb(FSResizeError(), device, details=details)
-    except FSMigrateError as (msg, device):
-        errorcb(FSMigrateError(), device, msg)
+        if errorHandler.cb(e, e.args[0], details=details) == ERROR_RAISE:
+            raise
+    except FSMigrateError as e:
+        if errorHandler.cb(e, e.args[0], e.args[1]) == ERROR_RAISE:
+            raise
     except Exception as e:
         raise
 
@@ -2077,15 +2077,8 @@ class FSSet(object):
                         # just write duplicates back out post-install
                         self.preserveLines.append(line)
 
-    def turnOnSwap(self, rootPath="", upgrading=None, errorcb=None):
-        """ Activate the system's swap space.
-
-            errorcb should accept an Exception instance and a Device instance
-            return True if the exception should be fatal, which is the default.
-        """
-        if errorcb is None:
-            errorcb = lambda e,d: True
-
+    def turnOnSwap(self, rootPath="", upgrading=None):
+        """ Activate the system's swap space. """
         for device in self.swapDevices:
             if isinstance(device, FileDevice):
                 # set up FileDevices' parents now that they are accessible
@@ -2105,22 +2098,14 @@ class FSSet(object):
                     device.setup()
                     device.format.setup()
                 except StorageError as e:
-                    if errorcb(e, device):
+                    if errorHandler.cb(e, device) == ERROR_RAISE:
                         raise
                 else:
                     break
 
-    def mountFilesystems(self, rootPath="", readOnly=None, errorcb=None,
+    def mountFilesystems(self, rootPath="", readOnly=None,
                          skipRoot=False, raiseErrors=None):
-        """ Mount the system's filesystems.
-
-            errorcb should accept an Exception instance and a Device instance
-            and return True if the exception should be fatal, which is the
-            default.
-        """
-        if errorcb is None:
-            errorcb = lambda e,d: True
-
+        """ Mount the system's filesystems. """
         devices = self.mountpoints.values() + self.swapDevices
         devices.extend([self.dev, self.devshm, self.devpts, self.sysfs,
                         self.proc, self.selinux, self.usb])
@@ -2157,7 +2142,7 @@ class FSSet(object):
             try:
                 device.setup()
             except Exception as msg:
-                if errorcb(e, device):
+                if errorHandler.cb(e, device) == ERROR_RAISE:
                     raise
                 else:
                     continue
@@ -2171,7 +2156,7 @@ class FSSet(object):
             except Exception as e:
                 log.error("error mounting %s on %s: %s"
                           % (device.path, device.format.mountpoint, e))
-                if errorcb(e, device):
+                if errorHandler.cb(e, device) == ERROR_RAISE:
                     raise
 
         self.active = True
diff --git a/pyanaconda/storage/partitioning.py b/pyanaconda/storage/partitioning.py
index 96b0b26..d656c6b 100644
--- a/pyanaconda/storage/partitioning.py
+++ b/pyanaconda/storage/partitioning.py
@@ -28,6 +28,7 @@ import parted
 from pykickstart.constants import *
 
 from pyanaconda.constants import *
+from pyanaconda.errors import *
 
 from errors import *
 from deviceaction import *
@@ -245,7 +246,7 @@ def scheduleShrinkActions(storage):
         if device.targetSize != size:
             device.format.targetSize = device.targetSize
 
-def doAutoPartition(storage, data, errorcb=None, warningcb=None):
+def doAutoPartition(storage, data):
     log.debug("doAutoPart: %s" % storage.doAutoPart)
     log.debug("encryptedAutoPart: %s" % storage.encryptedAutoPart)
     log.debug("lvmAutoPart: %s" % storage.lvmAutoPart)
@@ -260,11 +261,6 @@ def doAutoPartition(storage, data, errorcb=None, warningcb=None):
     disks = []
     devs = []
 
-    if errorcb is None:
-        errorcb = lambda e: True
-    if warningcb is None:
-        warningcb = lambda e: True
-
     if storage.doAutoPart:
         scheduleShrinkActions(storage)
         clearPartitions(storage)
@@ -290,12 +286,13 @@ def doAutoPartition(storage, data, errorcb=None, warningcb=None):
         growLVM(storage)
     except PartitioningWarning as e:
         log.warning(str(e))
-        warningcb(e)
+        if errorHandler.cb(e) == ERROR_RAISE:
+            raise
     except PartitioningError as e:
         log.error(str(e))
-        errorcb(e)
-        storage.reset()
-        raise
+        if errorHandler.cb(e) == ERROR_RAISE:
+            storage.reset()
+            raise
 
     storage.setUpBootLoader()
 
@@ -307,9 +304,9 @@ def doAutoPartition(storage, data, errorcb=None, warningcb=None):
         log.warning(warning)
     if errors:
         exn = PartitioningError("\n".join(errors))
-        errorcb(exn)
-        storage.reset()
-        raise exn
+        if errorHandler.cb(exn) == ERROR_RAISE:
+            storage.reset()
+            raise exn
 
 def shouldClear(device, clearPartType, clearPartDisks=None):
     if clearPartType not in [CLEARPART_TYPE_LINUX, CLEARPART_TYPE_ALL]:
-- 
1.7.7.6

_______________________________________________
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