Skip to content

Instantly share code, notes, and snippets.

@bwann
Last active April 21, 2016 21:20
Show Gist options
  • Save bwann/fbf9d752b2d0c3c050f7 to your computer and use it in GitHub Desktop.
Save bwann/fbf9d752b2d0c3c050f7 to your computer and use it in GitHub Desktop.
Kickstart %traceback scripts
# Can have multiple %traceback per kickstart
# Bash example:
%traceback
#
# traceback/common: custom traceback handler
#
echo "wann.net traceback handler firing"
ls -l /tmp/anaconda-tb*
echo "hello world!"
%end
# Python example:
%traceback --interpreter=/usr/bin/python
#!/usr/bin/env python
#
# Finds and parses any traceback files from anaconda in tmp, passes the error
# and stack to scribe category
#
import glob
import json
from pyanaconda.scribe_logger import scribe_log, scribe_traceback
# Find our traceback files. If we have anaconda-tb-all.log, prefer it.
# We should only ever have this one plus a alternative?
tracebacks = glob.glob('/tmp/anaconda-tb*')
if '/tmp/anaconda-tb-all.log' in tracebacks:
tb_file = '/tmp/anaconda-tb-all.log'
else:
tb_file = tracebacks.pop()
buffering = False
tldr = ''
errors = []
with open(tb_file, 'r') as f:
for line in f:
if 'Traceback' in line:
buffering = True
continue
if buffering:
# Error messages always start on left column ?
if line.startswith(' '):
errors.append(line.rstrip())
else:
tldr = line.strip()
break
# for err in errors:
# print 'err: ' + err
#
# print 'tldr: ' + tldr
scribe_traceback(tldr, errors)
%end
{
"timestamp": 1453120100,
"hostname": "raptor2.wann.net",
"type": "traceback",
"stack": [
" File \"str_eval\", line 3, in f1453120096",
" File \"str_eval\", line 5, in <module>",
" File \"/usr/lib64/python2.7/site-packages/pyanaconda/exception.py\", line 346, in raise_exception",
" eval(compile(code, \"str_eval\", \"exec\"))",
" File \"/usr/lib64/python2.7/threading.py\", line 764, in run",
" self.__target(*self.__args, **self.__kwargs)",
" File \"/usr/lib64/python2.7/site-packages/pyanaconda/threads.py\", line 227, in run",
" threading.Thread.run(self, *args, **kwargs)"
],
"error": "RuntimeError: NOTABUG: testing exception handling"
}
{"timestamp": 1453120100, "message": "All kickstart %%traceback script(s) have been run", "hostname": "raptor2.wann.net", "type": "log"}
[root@basic08 ~]# tail -F /var/scribe/anaconda/anaconda_current
{"timestamp": 1453120072, "message": "Setting up the installation environment", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120075, "message": "Created disklabel on /dev/sda", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120076, "message": "Created xfs on /dev/sda1", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120081, "message": "Created xfs on /dev/sda3", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120082, "message": "Created swap on /dev/sda2", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120083, "message": "Starting package installation process", "hostname": "raptor2.wann.net", "type": "log"}
# shoot anaconda in the head with 'killall -USR1 anaconda', watch our traceback from python traceback show up here...
{"timestamp": 1453120100, "message": "Running kickstart %%traceback script(s)", "hostname": "raptor2.wann.net", "type": "log"}
{"hostname": "raptor2.wann.net", "timestamp": 1453120100, "message": "%traceback fired"}\n
{"timestamp": 1453120100, "hostname": "raptor2.wann.net", "type": "traceback", "stack": [" File \"str_eval\", line 3, in f1453120096", " File \"str_eval\", line 5, in <module>", " File \"/usr/lib64/python2.7/site-packages/pyanaconda/exception.py\", line 346, in raise_exception", " eval(compile(code, \"str_eval\", \"exec\"))", " File \"/usr/lib64/python2.7/threading.py\", line 764, in run", " self.__target(*self.__args, **self.__kwargs)", " File \"/usr/lib64/python2.7/site-packages/pyanaconda/threads.py\", line 227, in run", " threading.Thread.run(self, *args, **kwargs)"], "error": "RuntimeError: NOTABUG: testing exception handling"}
{"timestamp": 1453120100, "message": "All kickstart %%traceback script(s) have been run", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120476, "message": "Installing boot loader", "hostname": "raptor2.wann.net", "type": "log"}
{"timestamp": 1453120476, "message": "Performing post-installation setup tasks", "hostname": "raptor2.wann.net", "type": "log"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment