aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2011-10-05 16:30:24 +0000
committerRob Austein <sra@hactrn.net>2011-10-05 16:30:24 +0000
commit72e42a6508ff19a315a0257dda4a710bc195dffa (patch)
tree34785d51be76bdb31b72784dd527125145b1ebc9
parent03d8dcaf85e21fe621f020c4fb34fdecb6ac4cca (diff)
Add global traceback control; this closes #95. Clean up some
"except:" clauses that should have been "except Exception:". svn path=/rpkid/rpki-sql-setup.py; revision=4014
-rw-r--r--rpkid/rpki-sql-setup.py2
-rw-r--r--rpkid/rpki/adns.py6
-rw-r--r--rpkid/rpki/async.py4
-rw-r--r--rpkid/rpki/cli.py4
-rw-r--r--rpkid/rpki/config.py9
-rw-r--r--rpkid/rpki/http.py31
-rw-r--r--rpkid/rpki/irdbd.py16
-rw-r--r--rpkid/rpki/left_right.py10
-rw-r--r--rpkid/rpki/log.py34
-rw-r--r--rpkid/rpki/pubd.py10
-rw-r--r--rpkid/rpki/rootd.py2
-rw-r--r--rpkid/rpki/rpkid.py6
-rw-r--r--rpkid/rpki/x509.py6
-rw-r--r--rpkid/tests/smoketest.py8
-rw-r--r--rpkid/tests/testpoke.py5
15 files changed, 84 insertions, 69 deletions
diff --git a/rpkid/rpki-sql-setup.py b/rpkid/rpki-sql-setup.py
index a7fb2d25..7e4abec6 100644
--- a/rpkid/rpki-sql-setup.py
+++ b/rpkid/rpki-sql-setup.py
@@ -51,7 +51,7 @@ def sql_setup(name):
cur = rootdb.cursor()
try:
cur.execute("DROP DATABASE IF EXISTS %s" % database)
- except:
+ except Exception:
pass
cur.execute("CREATE DATABASE %s" % database)
cur.execute("GRANT ALL ON %s.* TO %s@localhost IDENTIFIED BY %%s" % (database, username), (password,))
diff --git a/rpkid/rpki/adns.py b/rpkid/rpki/adns.py
index f627ac7a..7200f435 100644
--- a/rpkid/rpki/adns.py
+++ b/rpkid/rpki/adns.py
@@ -4,7 +4,7 @@ dnspython package.
$Id$
-Copyright (C) 2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2010--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -65,12 +65,12 @@ for ns in resolver.nameservers:
try:
nameservers.append((socket.AF_INET, dns.ipv4.inet_aton(ns)))
continue
- except:
+ except Exception:
pass
try:
nameservers.append((socket.AF_INET6, dns.ipv6.inet_aton(ns)))
continue
- except:
+ except Exception:
pass
rpki.log.error("Couldn't parse nameserver address %r" % ns)
diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py
index 2f0ea15f..a7de6b25 100644
--- a/rpkid/rpki/async.py
+++ b/rpkid/rpki/async.py
@@ -3,7 +3,7 @@ Utilities for event-driven programming.
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -51,7 +51,7 @@ class iterator(object):
self.iterator = iter(iterable)
except (ExitNow, SystemExit):
raise
- except:
+ except Exception:
rpki.log.debug("Problem constructing iterator for %r" % (iterable,))
raise
self.doit()
diff --git a/rpkid/rpki/cli.py b/rpkid/rpki/cli.py
index d31f7204..10b4edb3 100644
--- a/rpkid/rpki/cli.py
+++ b/rpkid/rpki/cli.py
@@ -3,7 +3,7 @@ Utilities for writing command line tools.
$Id$
-Copyright (C) 2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2010--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -55,7 +55,7 @@ class Cmd(cmd.Cmd):
return cmd.Cmd.onecmd(self, line)
except SystemExit:
raise
- except:
+ except Exception:
traceback.print_exc()
def do_EOF(self, arg):
diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py
index 59ac6efd..f0129573 100644
--- a/rpkid/rpki/config.py
+++ b/rpkid/rpki/config.py
@@ -4,7 +4,7 @@ ConfigParser module.
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -195,7 +195,7 @@ class parser(object):
its data is less silly than the available alternatives.
"""
- import rpki.http, rpki.x509, rpki.sql, rpki.async
+ import rpki.http, rpki.x509, rpki.sql, rpki.async, rpki.log
try:
rpki.http.debug_http = self.getboolean("debug_http")
@@ -261,3 +261,8 @@ class parser(object):
rpki.async.gc_summary(self.getint("gc_summary"), self.getint("gc_summary_threshold", 0))
except ConfigParser.NoOptionError:
pass
+
+ try:
+ rpki.log.enable_tracebacks = self.getboolean("enable_tracebacks")
+ except ConfigParser.NoOptionError:
+ pass
diff --git a/rpkid/rpki/http.py b/rpkid/rpki/http.py
index 1638449a..71bb02f2 100644
--- a/rpkid/rpki/http.py
+++ b/rpkid/rpki/http.py
@@ -453,9 +453,7 @@ class http_stream(asynchat.async_chat):
etype = sys.exc_info()[0]
if etype in (SystemExit, rpki.async.ExitNow):
raise
- if self.show_tracebacks:
- self.log("Error in HTTP stream handler", rpki.log.warn)
- rpki.log.traceback()
+ rpki.log.traceback(self.show_tracebacks)
if etype is not rpki.exceptions.HTTPClientAborted:
self.log("Closing due to error", rpki.log.warn)
self.close()
@@ -536,8 +534,7 @@ class http_server(http_stream):
except (rpki.async.ExitNow, SystemExit):
raise
except Exception, e:
- if self.show_tracebacks:
- rpki.log.traceback()
+ rpki.log.traceback(self.show_tracebacks)
self.send_error(500, "Unhandled exception %s" % e)
else:
self.send_error(code = error[0], reason = error[1])
@@ -606,10 +603,9 @@ class http_listener(asyncore.dispatcher):
self.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
self.bind(sockaddr)
self.listen(5)
- except:
- self.log("Couldn't set up HTTP listener", rpki.log.warn)
- if self.show_tracebacks:
- rpki.log.traceback()
+ except Exception, e:
+ self.log("Couldn't set up HTTP listener: %s" % e, rpki.log.warn)
+ rpki.log.traceback(self.show_tracebacks)
self.close()
for h in handlers:
self.log("Handling %s" % h[0])
@@ -625,8 +621,8 @@ class http_listener(asyncore.dispatcher):
http_server(sock = s, handlers = self.handlers)
except (rpki.async.ExitNow, SystemExit):
raise
- except:
- self.log("Unable to accept connection")
+ except Exception, e:
+ self.log("Unable to accept connection: %s" % e)
self.handle_error()
def handle_error(self):
@@ -636,8 +632,7 @@ class http_listener(asyncore.dispatcher):
if sys.exc_info()[0] in (SystemExit, rpki.async.ExitNow):
raise
self.log("Error in HTTP listener", rpki.log.warn)
- if self.show_tracebacks:
- rpki.log.traceback()
+ rpki.log.traceback(self.show_tracebacks)
class http_client(http_stream):
"""
@@ -702,7 +697,7 @@ class http_client(http_stream):
self.update_timeout()
except (rpki.async.ExitNow, SystemExit):
raise
- except:
+ except Exception:
self.handle_error()
def handle_connect(self):
@@ -925,13 +920,15 @@ class http_queue(object):
req.errback(result)
except (rpki.async.ExitNow, SystemExit):
raise
- except:
+ except Exception:
#
# If we get here, we may have lost the event chain. Not
- # obvious what we can do about it at this point.
+ # obvious what we can do about it at this point, but force a
+ # traceback so that it will be somewhat obvious that something
+ # really bad happened.
#
self.log("Exception in exception callback", rpki.log.warn)
- rpki.log.traceback()
+ rpki.log.traceback(True)
self.log("Queue: %r" % self.queue)
diff --git a/rpkid/rpki/irdbd.py b/rpkid/rpki/irdbd.py
index a8a17649..c2e01287 100644
--- a/rpkid/rpki/irdbd.py
+++ b/rpkid/rpki/irdbd.py
@@ -166,29 +166,29 @@ class main(object):
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
- #rpki.log.traceback()
- r_msg.append(rpki.left_right.report_error_elt.from_exception(data, q_pdu.self_handle, q_pdu.tag))
+ except Exception, e:
+ rpki.log.traceback()
+ r_msg.append(rpki.left_right.report_error_elt.from_exception(e, q_pdu.self_handle, q_pdu.tag))
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
- #rpki.log.traceback()
- r_msg.append(rpki.left_right.report_error_elt.from_exception(data))
+ except Exception, e:
+ rpki.log.traceback()
+ r_msg.append(rpki.left_right.report_error_elt.from_exception(e))
cb(200, body = rpki.left_right.cms_msg().wrap(r_msg, self.irdbd_key, self.irdbd_cert))
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
+ except Exception, e:
rpki.log.traceback()
# We only get here in cases where we couldn't or wouldn't generate
# <report_error/>, so just return HTTP failure.
- cb(500, reason = "Unhandled exception %s: %s" % (data.__class__.__name__, data))
+ cb(500, reason = "Unhandled exception %s: %s" % (e.__class__.__name__, e))
def __init__(self):
diff --git a/rpkid/rpki/left_right.py b/rpkid/rpki/left_right.py
index f26f4adc..72412cbe 100644
--- a/rpkid/rpki/left_right.py
+++ b/rpkid/rpki/left_right.py
@@ -393,7 +393,7 @@ class self_elt(data_elt):
rpki.async.iterator(r_msg.payload.classes, class_loop, class_done)
def list_failed(e):
- #rpki.log.traceback()
+ rpki.log.traceback()
rpki.log.warn("Couldn't get resource class list from parent %r, skipping: %s" % (parent, e))
parent_iterator()
@@ -589,7 +589,7 @@ class self_elt(data_elt):
self.gctx.sql.sweep()
def publication_failed(e):
- #rpki.log.traceback()
+ rpki.log.traceback()
rpki.log.warn("Couldn't publish Ghostbuster updates for %s, skipping: %s" % (self.self_handle, e))
self.gctx.checkpoint()
cb()
@@ -687,7 +687,7 @@ class self_elt(data_elt):
self.gctx.sql.sweep()
def publication_failed(e):
- #rpki.log.traceback()
+ rpki.log.traceback()
rpki.log.warn("Couldn't publish for %s, skipping: %s" % (self.self_handle, e))
self.gctx.checkpoint()
cb()
@@ -1133,9 +1133,9 @@ class child_elt(data_elt):
raise
except rpki.exceptions.NoActiveCA, data:
done(q_msg.serve_error(data))
- except Exception, data:
+ except Exception, e:
rpki.log.traceback()
- done(q_msg.serve_error(data))
+ done(q_msg.serve_error(e))
class list_resources_elt(rpki.xml_utils.base_elt, left_right_namespace):
"""
diff --git a/rpkid/rpki/log.py b/rpkid/rpki/log.py
index 658ee984..72d185e7 100644
--- a/rpkid/rpki/log.py
+++ b/rpkid/rpki/log.py
@@ -3,7 +3,7 @@ Logging facilities for RPKI libraries.
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -50,6 +50,12 @@ use_syslog = True
show_python_ids = False
+## @var enable_tracebacks
+# Whether tracebacks are enabled globally. Individual classes and
+# modules may choose to override this.
+
+enable_tracebacks = False
+
tag = ""
pid = 0
@@ -102,18 +108,26 @@ def trace():
bt = tb.extract_stack(limit = 3)
return debug("[%s() at %s:%d from %s:%d]" % (bt[1][2], bt[1][0], bt[1][1], bt[0][0], bt[0][1]))
-def traceback():
+def traceback(do_it = None):
"""
- Consolidated backtrace facility with a bit of extra info.
+ Consolidated backtrace facility with a bit of extra info. Argument
+ specifies whether or not to log the traceback (some modules and
+ classes have their own controls for this, this lets us provide a
+ unified interface). If no argument is specified, we use the global
+ default value rpki.log.enable_tracebacks.
"""
- assert sys.exc_info() != (None, None, None), "rpki.log.traceback() called without valid trace on stack, this is a programming error"
- bt = tb.extract_stack(limit = 3)
- error("Exception caught in %s() at %s:%d called from %s:%d" % (bt[1][2], bt[1][0], bt[1][1], bt[0][0], bt[0][1]))
- bt = tb.format_exc()
- assert bt is not None, "Apparently I'm still not using the right test for null backtrace"
- for line in bt.splitlines():
- warn(line)
+ if do_it is None:
+ do_it = enable_tracebacks
+
+ if do_it:
+ assert sys.exc_info() != (None, None, None), "rpki.log.traceback() called without valid trace on stack, this is a programming error"
+ bt = tb.extract_stack(limit = 3)
+ error("Exception caught in %s() at %s:%d called from %s:%d" % (bt[1][2], bt[1][0], bt[1][1], bt[0][0], bt[0][1]))
+ bt = tb.format_exc()
+ assert bt is not None, "Apparently I'm still not using the right test for null backtrace"
+ for line in bt.splitlines():
+ warn(line)
def log_repr(obj, *tokens):
"""
diff --git a/rpkid/rpki/pubd.py b/rpkid/rpki/pubd.py
index 513c1c3e..bde1260e 100644
--- a/rpkid/rpki/pubd.py
+++ b/rpkid/rpki/pubd.py
@@ -7,7 +7,7 @@ Usage: python pubd.py [ { -c | --config } configfile ]
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -132,9 +132,9 @@ class main(object):
self.handler_common(query, None, done, (self.bpki_ta, self.irbe_cert))
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
+ except Exception, e:
rpki.log.traceback()
- cb(500, reason = "Unhandled exception %s" % data)
+ cb(500, reason = "Unhandled exception %s" % e)
client_url_regexp = re.compile("/client/([-A-Z0-9_/]+)$", re.I)
@@ -162,6 +162,6 @@ class main(object):
self.handler_common(query, client, done, (self.bpki_ta, client.bpki_cert, client.bpki_glue), config.bpki_crl)
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
+ except Exception, e:
rpki.log.traceback()
- cb(500, reason = "Could not process PDU: %s" % data)
+ cb(500, reason = "Could not process PDU: %s" % e)
diff --git a/rpkid/rpki/rootd.py b/rpkid/rpki/rootd.py
index 53f9be1a..b71a81bb 100644
--- a/rpkid/rpki/rootd.py
+++ b/rpkid/rpki/rootd.py
@@ -7,7 +7,7 @@ Usage: python rootd.py [ { -c | --config } configfile ] [ { -h | --help } ]
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/rpkid/rpki/rpkid.py b/rpkid/rpki/rpkid.py
index c9cd8bdc..75624a3c 100644
--- a/rpkid/rpki/rpkid.py
+++ b/rpkid/rpki/rpkid.py
@@ -7,7 +7,7 @@ Usage: python rpkid.py [ { -c | --config } configfile ]
$Id$
-Copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2009--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -240,9 +240,9 @@ class main(object):
q_msg.serve_top_level(self, done)
except (rpki.async.ExitNow, SystemExit):
raise
- except Exception, data:
+ except Exception, e:
rpki.log.traceback()
- cb(500, reason = "Unhandled exception %s" % data)
+ cb(500, reason = "Unhandled exception %s" % e)
up_down_url_regexp = re.compile("/up-down/([-A-Z0-9_]+)/([-A-Z0-9_]+)$", re.I)
diff --git a/rpkid/rpki/x509.py b/rpkid/rpki/x509.py
index bcaa3646..65031d9e 100644
--- a/rpkid/rpki/x509.py
+++ b/rpkid/rpki/x509.py
@@ -907,7 +907,7 @@ class CMS_object(DER_object):
cms = self.get_POW()
except (rpki.async.ExitNow, SystemExit):
raise
- except:
+ except Exception:
if self.print_on_der_error:
rpki.log.debug("Problem parsing DER CMS message, might not really be DER: %r" % self.get_DER())
raise rpki.exceptions.UnparsableCMSDER
@@ -969,7 +969,7 @@ class CMS_object(DER_object):
content = cms.verify(store)
except (rpki.async.ExitNow, SystemExit):
raise
- except:
+ except Exception:
if self.dump_on_verify_failure:
if self.dump_using_dumpasn1:
dbg = self.dumpasn1()
@@ -1000,7 +1000,7 @@ class CMS_object(DER_object):
cms = self.get_POW()
except (rpki.async.ExitNow, SystemExit):
raise
- except:
+ except Exception:
raise rpki.exceptions.UnparsableCMSDER
if cms.eContentType() != self.econtent_oid:
diff --git a/rpkid/tests/smoketest.py b/rpkid/tests/smoketest.py
index bcb6d699..127e3f79 100644
--- a/rpkid/tests/smoketest.py
+++ b/rpkid/tests/smoketest.py
@@ -82,7 +82,7 @@ if yaml_script is None:
yaml_script = cfg.get("yaml_script", "smoketest.yaml")
try:
yaml_script = [y for y in yaml.safe_load_all(open(yaml_script))]
-except:
+except Exception:
print __doc__
raise
@@ -704,7 +704,7 @@ class allocation(object):
for sql in rpki_sql:
try:
cur.execute(sql)
- except:
+ except Exception:
if not sql.upper().startswith("DROP TABLE"):
raise
db.close()
@@ -714,7 +714,7 @@ class allocation(object):
for sql in irdb_sql:
try:
cur.execute(sql)
- except:
+ except Exception:
if not sql.upper().startswith("DROP TABLE"):
raise
for s in [self] + self.hosts:
@@ -1170,7 +1170,7 @@ def setup_publication(pubd_sql):
for sql in pubd_sql:
try:
cur.execute(sql)
- except:
+ except Exception:
if not sql.upper().startswith("DROP TABLE"):
raise
db.close()
diff --git a/rpkid/tests/testpoke.py b/rpkid/tests/testpoke.py
index 0e9c06cd..26cd29aa 100644
--- a/rpkid/tests/testpoke.py
+++ b/rpkid/tests/testpoke.py
@@ -12,7 +12,7 @@ Default configuration file is testpoke.yaml, override with --yaml option.
$Id$
-Copyright (C) 2010 Internet Systems Consortium ("ISC")
+Copyright (C) 2010--2011 Internet Systems Consortium ("ISC")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -151,8 +151,7 @@ def do_revoke():
dispatch = { "list" : do_list, "issue" : do_issue, "revoke" : do_revoke }
def fail(e):
- if debug:
- rpki.log.traceback()
+ rpki.log.traceback(debug)
sys.exit("Testpoke failed: %s" % e)
cms_ta = get_PEM("cms-ca-cert", rpki.x509.X509)