[PATCH 2/2] Add a way to test exception handling

Vratislav Podzimek vpodzime at redhat.com
Wed Sep 12 19:21:46 UTC 2012


Instead of adding command line option throwing exception in one place
of the code, let's use SIGURS1 as signal for raising exception in anaconda.
This way, it is possible to raise exception in different phases of the
installation and we can add code to prepare worst case scenario testing
as much resolved bugs in exception handling as possible.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 anaconda                |  6 ++++--
 anaconda.spec.in        |  2 +-
 pyanaconda/exception.py | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/anaconda b/anaconda
index c1f6ba8..f3b5112 100755
--- a/anaconda
+++ b/anaconda
@@ -906,12 +906,14 @@ if __name__ == "__main__":
     # sets yum's multilib_policy to "all" (as opposed to "best")
     ksdata.packages.multiLib = opts.multiLib
 
+    from pyanaconda import exception
     if anaconda.displayMode == 'g':
         # comment out the next line to make exceptions non-fatal
-        from pyanaconda.exception import initExceptionHandling
-        anaconda.mehConfig = initExceptionHandling(anaconda)
+        anaconda.mehConfig = exception.initExceptionHandling(anaconda)
 
     # add our own additional signal handlers
+    signal.signal(signal.SIGUSR1, lambda signum, frame:
+                                         exception.test_exception_handling())
     signal.signal(signal.SIGUSR2, lambda signum, frame: anaconda.dumpState())
 
     if opts.lang:
diff --git a/anaconda.spec.in b/anaconda.spec.in
index 3aabfde..f14c7e0 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -40,7 +40,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 %define yumutilsver 1.1.11-3
 %define iscsiver 6.2.0.870-3
 %define pythoncryptsetupver 0.1.1
-%define mehver 0.15-1
+%define mehver 0.16-1
 %define sckeyboardver 1.3.1
 %define libblkidver 2.17.1-1
 %define fcoeutilsver 1.0.12-3.20100323git
diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index 98575f3..3940e0e 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -28,6 +28,7 @@ import sys
 import os
 import shutil
 import signal
+import time
 from flags import flags
 import kickstart
 import storage.errors
@@ -165,3 +166,35 @@ def initExceptionHandling(anaconda):
     handler.install(anaconda)
 
     return conf
+
+def test_exception_handling():
+    """
+    Function that can be used for testing exception handling in anaconda. It
+    tries to prepare a worst case scenario designed from bugs seen so far.
+
+    """
+
+    # XXX: this is a huge hack, but probably the only way, how we can get
+    #      "unique" stack and thus unique hash and new bugreport
+    def raise_exception(msg, non_ascii):
+        timestamp = str(time.time()).split(".", 1)[0]
+
+        code = """
+def f%s(msg, non_ascii):
+        raise RuntimeError(msg)
+
+f%s(msg, non_ascii)
+""" % (timestamp, timestamp)
+
+        eval(compile(code, "str_eval", "exec"))
+
+    # test non-ascii characters dumping
+    non_ascii = u'\u0159'
+
+    msg = "NOTABUG: testing exception handling"
+
+    # raise exception from a separate thread
+    # XXX: may create a circular dependency if imported globally
+    from pyanaconda.threads import AnacondaThread, threadMgr
+    threadMgr.add(AnacondaThread(target=raise_exception,
+                                 args=(msg, non_ascii)))
-- 
1.7.11.4



More information about the anaconda-patches mailing list