[PATCH 4/4] Show zFCP errors in dialog boxes rather than tracebacks (#598087)

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

 



Rather than raise an exception, show error messages in dialog boxes.
---
 storage/__init__.py |    2 +-
 storage/zfcp.py     |  164 ++++++++++++++++++++++++++++++++------------------
 2 files changed, 106 insertions(+), 60 deletions(-)

diff --git a/storage/__init__.py b/storage/__init__.py
index dfe8a78..9db055a 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -359,7 +359,7 @@ class Storage(object):
                                           _("Finding storage devices"))
         self.iscsi.startup(self.anaconda.intf)
         self.fcoe.startup(self.anaconda.intf)
-        self.zfcp.startup()
+        self.zfcp.startup(self.anaconda.intf)
         self.dasd.startup(self.anaconda.intf, self.exclusiveDisks, self.zeroMbr)
         if self.anaconda.id.getUpgrade():
             clearPartType = CLEARPART_TYPE_NONE
diff --git a/storage/zfcp.py b/storage/zfcp.py
index 3c315e8..7d17b89 100644
--- a/storage/zfcp.py
+++ b/storage/zfcp.py
@@ -42,17 +42,26 @@ scsidevsysfs = "/sys/bus/scsi/devices"
 zfcpconf = "/etc/zfcp.conf"
 
 class ZFCPDevice:
-    def __init__(self, devnum, wwpn, fcplun):
+    def __init__(self, intf, devnum, wwpn, fcplun):
+        self.intf = intf
         self.devnum = self.sanitizeDeviceInput(devnum)
         self.wwpn = self.sanitizeWWPNInput(wwpn)
         self.fcplun = self.sanitizeFCPLInput(fcplun)
 
         if not self.checkValidDevice(self.devnum):
-            raise ValueError, _("You have not specified a device number or the number is invalid")
+            self.intf.messageWindow(_("Error"),
+                                    _("You have not specified a device "
+                                      "number or the number is invalid"))
+
         if not self.checkValidWWPN(self.wwpn):
-            raise ValueError, _("You have not specified a worldwide port name or the name is invalid.")
+            self.intf.messageWindow(_("Error"),
+                                    _("You have not specified a worldwide "
+                                      "port name or the name is invalid."))
+
         if not self.checkValidFCPLun(self.fcplun):
-            raise ValueError, _("You have not specified a FCP LUN or the number is invalid.")
+            self.intf.messageWindow(_("Error"),
+                                    _("You have not specified a FCP LUN or "
+                                      "the number is invalid."))
 
     def __str__(self):
         return "%s %s %s" %(self.devnum, self.wwpn, self.fcplun)
@@ -129,9 +138,10 @@ class ZFCPDevice:
                                    stdout="/dev/tty5", stderr="/dev/tty5")
 
         if not os.path.exists(online):
-            raise ValueError, _(
-                "zFCP device %s not found, not even in device ignore list."
-                %(self.devnum,))
+            self.intf.messageWindow(_("Error"),
+                                    _("zFCP device %s not found, not even in "
+                                      "device ignore list.") % self.devnum)
+            return False
 
         try:
             f = open(online, "r")
@@ -140,9 +150,11 @@ class ZFCPDevice:
             if devonline != "1":
                 loggedWriteLineToFile(online, "1")
         except IOError as e:
-            raise ValueError, _("Could not set zFCP device %(devnum)s "
-                                "online (%(e)s).") \
-                              % {'devnum': self.devnum, 'e': e}
+            self.intf.messageWindow(_("Error"),
+                                    _("Could not set zFCP device %(devnum)s "
+                                      "online (%(e)s).") \
+                                    % {'devnum': self.devnum, 'e': e})
+            return False
 
         if not os.path.exists(portdir):
             if os.path.exists(portadd):
@@ -151,16 +163,22 @@ class ZFCPDevice:
                     loggedWriteLineToFile(portadd, self.wwpn)
                     udev_settle()
                 except IOError as e:
-                    raise ValueError, _("Could not add WWPN %(wwpn)s to zFCP "
-                                        "device %(devnum)s (%(e)s).") \
-                                      % {'wwpn': self.wwpn,
-                                         'devnum': self.devnum,
-                                         'e': e}
+                    self.intf.messageWindow(_("Error"),
+                                            _("Could not add WWPN %(wwpn)s "
+                                              "to zFCP device %(devnum)s "
+                                              "(%(e)s).") \
+                                            % {'wwpn': self.wwpn,
+                                               'devnum': self.devnum,
+                                               'e': e})
+                    return False
             else:
                 # newer zfcp sysfs interface with auto port scan
-                raise ValueError, _("WWPN %(wwpn)s not found at zFCP device "
-                                    "%(devnum)s.") % {'wwpn': self.wwpn,
-                                                      'devnum': self.devnum}
+                self.intf.messageWindow(_("Error"),
+                                        _("WWPN %(wwpn)s not found at zFCP "
+                                          "device %(devnum)s.") \
+                                        % {'wwpn': self.wwpn,
+                                           'devnum': self.devnum})
+                return False
         else:
             if os.path.exists(portadd):
                 # older zfcp sysfs interface
@@ -173,17 +191,24 @@ class ZFCPDevice:
                 loggedWriteLineToFile(unitadd, self.fcplun)
                 udev_settle()
             except IOError as e:
-                raise ValueError, _("Could not add LUN %(fcplun)s to WWPN "
-                                    "%(wwpn)s on zFCP device %(devnum)s "
-                                    "(%(e)s).") \
-                                  % {'fcplun': self.fcplun, 'wwpn': self.wwpn,
-                                     'devnum': self.devnum, 'e': e}
+                self.intf.messageWindow(_("Error"),
+                                        _("Could not add LUN %(fcplun)s to "
+                                          "WWPN %(wwpn)s on zFCP device "
+                                          "%(devnum)s (%(e)s).") \
+                                        % {'fcplun': self.fcplun,
+                                           'wwpn': self.wwpn,
+                                           'devnum': self.devnum,
+                                           'e': e})
+                return False
         else:
-            raise ValueError, _("LUN %(fcplun)s at WWPN %(wwpn)s on zFCP "
-                                "device %(devnum)s already configured.") \
-                              % {'fcplun': self.fcplun,
-                                 'wwpn': self.wwpn,
-                                 'devnum': self.devnum}
+            self.intf.messageWindow(_("Error"),
+                                    _("LUN %(fcplun)s at WWPN %(wwpn)s on "
+                                      "zFCP device %(devnum)s already "
+                                      "configured." \
+                                    % {'fcplun': self.fcplun,
+                                       'wwpn': self.wwpn,
+                                       'devnum': self.devnum})
+            return False
 
         fail = "0"
         try:
@@ -191,20 +216,26 @@ class ZFCPDevice:
             fail = f.readline().strip()
             f.close()
         except IOError as e:
-            raise ValueError, _("Could not read failed attribute of LUN "
-                                "%(fcplun)s at WWPN %(wwpn)s on zFCP device "
-                                "%(devnum)s (%(e)s).") \
-                              % {'fcplun': self.fcplun,
-                                 'wwpn': self.wwpn,
-                                 'devnum': self.devnum,
-                                 'e': e}
+            self.intf.messageWindow(_("Error"),
+                                    _("Could not read failed attribute of LUN "
+                                      "%(fcplun)s at WWPN %(wwpn)s on zFCP "
+                                      "device %(devnum)s (%(e)s).") \
+                                    % {'fcplun': self.fcplun,
+                                       'wwpn': self.wwpn,
+                                       'devnum': self.devnum,
+                                       'e': e})
+            return False
+
         if fail != "0":
             self.offlineDevice()
-            raise ValueError, _("Failed LUN %(fcplun)s at WWPN %(wwpn)s on "
-                                "zFCP device %(devnum)s removed again.") \
-                              % {'fcplun': self.fcplun,
-                                 'wwpn': self.wwpn,
-                                 'devnum': self.devnum}
+            self.intf.messageWindow(_("Error"),
+                                    _("Failed LUN %(fcplun)s at WWPN %(wwpn)s "
+                                      "on zFCP device %(devnum)s removed "
+                                      "again.") \
+                                    % {'fcplun': self.fcplun,
+                                       'wwpn': self.wwpn,
+                                       'devnum': self.devnum})
+            return False
 
         return True
 
@@ -257,20 +288,28 @@ class ZFCPDevice:
         try:
             self.offlineSCSIDevice()
         except IOError as e:
-            raise ValueError, _("Could not correctly delete SCSI device of "
-                                "zFCP %(devnum)s %(wwpn)s %(fcplun)s "
-                                "(%(e)s).") \
-                              % {'devnum': self.devnum, 'wwpn': self.wwpn,
-                                 'fcplun': self.fcplun, 'e': e}
+            self.intf.messageWindow(_("Error"),
+                                    _("Could not correctly delete SCSI "
+                                      "device of zFCP %(devnum)s %(wwpn)s "
+                                      "%(fcplun)s (%(e)s).") \
+                                    % {'devnum': self.devnum,
+                                       'wwpn': self.wwpn,
+                                       'fcplun': self.fcplun,
+                                       'e': e})
+            return False
 
         try:
             loggedWriteLineToFile(unitremove, self.fcplun)
         except IOError as e:
-            raise ValueError, _("Could not remove LUN %(fcplun)s at WWPN "
-                                "%(wwpn)s on zFCP device %(devnum)s "
-                                "(%(e)s).") \
-                              % {'fcplun': self.fcplun, 'wwpn': self.wwpn,
-                                 'devnum': self.devnum, 'e': e}
+            self.intf.messageWindow(_("Error"),
+                                    _("Could not remove LUN %(fcplun)s at "
+                                      "WWPN %(wwpn)s on zFCP device "
+                                      "%(devnum)s (%(e)s).") \
+                                    % {'fcplun': self.fcplun,
+                                       'wwpn': self.wwpn,
+                                       'devnum': self.devnum,
+                                       'e': e})
+            return False
 
         if os.path.exists(portadd):
             # only try to remove ports with older zfcp sysfs interface
@@ -284,10 +323,13 @@ class ZFCPDevice:
             try:
                 loggedWriteLineToFile(portremove, self.wwpn)
             except IOError as e:
-                raise ValueError, _("Could not remove WWPN %(wwpn)s on zFCP "
-                                    "device %(devnum)s (%(e)s).") \
-                                  % {'wwpn': self.wwpn,
-                                     'devnum': self.devnum, 'e': e}
+                self.intf.messageWindow(_("Error"),
+                                        _("Could not remove WWPN %(wwpn)s on "
+                                          "zFCP device %(devnum)s (%(e)s).") \
+                                        % {'wwpn': self.wwpn,
+                                           'devnum': self.devnum,
+                                           'e': e})
+                return False
 
         if os.path.exists(portadd):
             # older zfcp sysfs interface
@@ -310,9 +352,11 @@ class ZFCPDevice:
         try:
             loggedWriteLineToFile(offline, "0")
         except IOError as e:
-            raise ValueError, _("Could not set zFCP device %(devnum)s "
-                                "offline (%(e)s).") \
-                              % {'devnum': self.devnum, 'e': e}
+            self.intf.messageWindow(_("Error"),
+                                    _("Could not set zFCP device %(devnum)s "
+                                      "offline (%(e)s).") \
+                                    % {'devnum': self.devnum, 'e': e})
+            return False
 
         return True
 
@@ -329,6 +373,7 @@ class ZFCP:
     """
 
     def __init__(self):
+        self.intf = None
         self.fcpdevs = set()
         self.hasReadConfig = False
         self.down = True
@@ -364,7 +409,7 @@ class ZFCP:
                 continue
 
     def addFCP(self, devnum, wwpn, fcplun):
-        d = ZFCPDevice(devnum, wwpn, fcplun)
+        d = ZFCPDevice(self.intf, devnum, wwpn, fcplun)
         if d.onlineDevice():
             self.fcpdevs.add(d)
 
@@ -380,7 +425,8 @@ class ZFCP:
             except ValueError, e:
                 log.warn(str(e))
 
-    def startup(self):
+    def startup(self, intf):
+        self.intf = intf
         if not self.down:
             return
         self.down = False
-- 
1.7.0.1

_______________________________________________
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