diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-02-28 15:51:37 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-02-28 15:51:37 -0500 |
commit | b3522f1044b6023fbcaf8ddf7aaff7f0166ed4b3 (patch) | |
tree | 4b896528586c79019ab0d7a52a2641dddae0a581 /cloudinit/__init__.py | |
parent | 3b3386dd794c9063db99fc0c9422119e8536b18d (diff) | |
parent | f54e9394e9d9dd0496d8084f9ca9ff5abee5f41c (diff) | |
download | vyos-cloud-init-b3522f1044b6023fbcaf8ddf7aaff7f0166ed4b3.tar.gz vyos-cloud-init-b3522f1044b6023fbcaf8ddf7aaff7f0166ed4b3.zip |
Catch exceptions from part-handlers and log the error before continuing.
This branch also adds tests for part-handler registration and part-handler
handling.
Diffstat (limited to 'cloudinit/__init__.py')
-rw-r--r-- | cloudinit/__init__.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 0fc61795..ccaa28c8 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -60,7 +60,6 @@ import cPickle import sys import os.path import errno -import pwd import subprocess import yaml import logging @@ -572,10 +571,14 @@ def handler_handle_part(mod, data, ctype, filename, payload, frequency): if not (modfreq == per_always or (frequency == per_instance and modfreq == per_instance)): return - if mod.handler_version == 1: - mod.handle_part(data, ctype, filename, payload) - else: - mod.handle_part(data, ctype, filename, payload, frequency) + try: + if mod.handler_version == 1: + mod.handle_part(data, ctype, filename, payload) + else: + mod.handle_part(data, ctype, filename, payload, frequency) + except: + util.logexc(log) + traceback.print_exc(file=sys.stderr) def partwalker_handle_handler(pdata, _ctype, _filename, payload): @@ -586,15 +589,13 @@ def partwalker_handle_handler(pdata, _ctype, _filename, payload): modfname = modname + ".py" util.write_file("%s/%s" % (pdata['handlerdir'], modfname), payload, 0600) - pdata['handlercount'] = curcount + 1 - try: mod = __import__(modname) handler_register(mod, pdata['handlers'], pdata['data'], frequency) + pdata['handlercount'] = curcount + 1 except: util.logexc(log) traceback.print_exc(file=sys.stderr) - return def partwalker_callback(pdata, ctype, filename, payload): |