2013-01-23 17:28:19 +00:00
|
|
|
#
|
|
|
|
# exception.py - general exception formatting and saving
|
|
|
|
#
|
2014-04-07 12:38:09 +00:00
|
|
|
# Copyright (C) 2000-2013 Red Hat, Inc.
|
2013-01-23 17:28:19 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Author(s): Chris Lumens <clumens@redhat.com>
|
|
|
|
# David Cantrell <dcantrell@redhat.com>
|
2014-04-07 12:38:09 +00:00
|
|
|
# Vratislav Podzimek <vpodzime@redhat.com>
|
2013-01-23 17:28:19 +00:00
|
|
|
#
|
2014-04-07 12:38:09 +00:00
|
|
|
from meh import Config
|
|
|
|
from meh.handler import ExceptionHandler
|
|
|
|
from meh.dump import ReverseExceptionDump
|
2015-03-23 11:36:12 +00:00
|
|
|
from pyanaconda import iutil, kickstart
|
2013-01-23 17:28:19 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import time
|
2014-04-07 12:38:09 +00:00
|
|
|
import re
|
|
|
|
import errno
|
2015-03-23 11:36:12 +00:00
|
|
|
import glob
|
|
|
|
import traceback
|
2014-04-07 12:38:09 +00:00
|
|
|
import blivet.errors
|
2015-03-23 11:36:12 +00:00
|
|
|
from pyanaconda.errors import CmdlineError
|
2014-04-07 12:38:09 +00:00
|
|
|
from pyanaconda.ui.communication import hubQ
|
2015-05-30 11:20:59 +00:00
|
|
|
from pyanaconda.constants import THREAD_EXCEPTION_HANDLING_TEST, IPMI_FAILED
|
2014-04-07 12:38:09 +00:00
|
|
|
from pyanaconda.threads import threadMgr
|
|
|
|
from pyanaconda.i18n import _
|
|
|
|
from pyanaconda import flags
|
2015-03-23 11:36:12 +00:00
|
|
|
from pyanaconda import startup_utils
|
2014-04-07 12:38:09 +00:00
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
from gi.repository import GLib
|
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger("anaconda")
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
class AnacondaExceptionHandler(ExceptionHandler):
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
def __init__(self, confObj, intfClass, exnClass, tty_num, gui_lock, interactive):
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
|
|
|
:see: python-meh's ExceptionHandler
|
|
|
|
:param tty_num: the number of tty the interface is running on
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
ExceptionHandler.__init__(self, confObj, intfClass, exnClass)
|
2015-03-23 11:36:12 +00:00
|
|
|
self._gui_lock = gui_lock
|
2014-04-07 12:38:09 +00:00
|
|
|
self._intf_tty_num = tty_num
|
2015-05-30 11:20:59 +00:00
|
|
|
self._interactive = interactive
|
2014-04-07 12:38:09 +00:00
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
def _main_loop_handleException(self, dump_info):
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
|
|
|
Helper method with one argument only so that it can be registered
|
|
|
|
with GLib.idle_add() to run on idle or called from a handler.
|
|
|
|
|
|
|
|
:type dump_info: an instance of the meh.DumpInfo class
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
ty = dump_info.exc_info.type
|
|
|
|
value = dump_info.exc_info.value
|
|
|
|
|
|
|
|
if (issubclass(ty, blivet.errors.StorageError) and value.hardware_fault) \
|
|
|
|
or (issubclass(ty, OSError) and value.errno == errno.EIO):
|
|
|
|
# hardware fault or '[Errno 5] Input/Output error'
|
|
|
|
hw_error_msg = _("The installation was stopped due to what "
|
|
|
|
"seems to be a problem with your hardware. "
|
|
|
|
"The exact error message is:\n\n%s.\n\n "
|
|
|
|
"The installer will now terminate.") % str(value)
|
|
|
|
self.intf.messageWindow(_("Hardware error occured"), hw_error_msg)
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
super(AnacondaExceptionHandler, self).handleException(dump_info)
|
|
|
|
return False
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def handleException(self, dump_info):
|
|
|
|
"""
|
|
|
|
Our own handleException method doing some additional stuff before
|
|
|
|
calling the original python-meh's one.
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
:type dump_info: an instance of the meh.DumpInfo class
|
|
|
|
:see: python-meh's ExceptionHandler.handleException
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
log.debug("running handleException")
|
2015-03-23 11:36:12 +00:00
|
|
|
exception_lines = traceback.format_exception(*dump_info.exc_info)
|
|
|
|
log.critical("\n".join(exception_lines))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
ty = dump_info.exc_info.type
|
|
|
|
value = dump_info.exc_info.value
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
try:
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
# XXX: Gtk stopped raising RuntimeError if it fails to
|
|
|
|
# initialize. Horay! But will it stay like this? Let's be
|
|
|
|
# cautious and raise the exception on our own to work in both
|
|
|
|
# cases
|
|
|
|
initialized = Gtk.init_check(None)[0]
|
|
|
|
if not initialized:
|
|
|
|
raise RuntimeError()
|
|
|
|
|
|
|
|
# Attempt to grab the GUI initializing lock, do not block
|
|
|
|
if not self._gui_lock.acquire(False):
|
|
|
|
# the graphical interface is running, don't crash it by
|
|
|
|
# running another one potentially from a different thread
|
|
|
|
log.debug("Gtk running, queuing exception handler to the "
|
|
|
|
"main loop")
|
|
|
|
GLib.idle_add(self._main_loop_handleException, dump_info)
|
|
|
|
else:
|
|
|
|
log.debug("Gtk not running, starting Gtk and running "
|
|
|
|
"exception handler in it")
|
|
|
|
self._main_loop_handleException(dump_info)
|
|
|
|
|
|
|
|
except (RuntimeError, ImportError):
|
|
|
|
log.debug("Gtk cannot be initialized")
|
|
|
|
# X not running (Gtk cannot be initialized)
|
|
|
|
if threadMgr.in_main_thread():
|
|
|
|
log.debug("In the main thread, running exception handler")
|
|
|
|
if issubclass(ty, CmdlineError) or not self._interactive:
|
|
|
|
if issubclass(ty, CmdlineError):
|
2015-03-23 11:36:12 +00:00
|
|
|
cmdline_error_msg = _("\nThe installation was stopped due to "
|
|
|
|
"incomplete spokes detected while running "
|
|
|
|
"in non-interactive cmdline mode. Since there "
|
2015-05-30 11:20:59 +00:00
|
|
|
"cannot be any questions in cmdline mode, "
|
2015-03-23 11:36:12 +00:00
|
|
|
"edit your kickstart file and retry "
|
|
|
|
"installation.\nThe exact error message is: "
|
|
|
|
"\n\n%s.\n\nThe installer will now terminate.") % str(value)
|
|
|
|
else:
|
2015-05-30 11:20:59 +00:00
|
|
|
cmdline_error_msg = _("\nRunning in cmdline mode, no interactive debugging "
|
|
|
|
"allowed.\nThe exact error message is: "
|
|
|
|
"\n\n%s.\n\nThe installer will now terminate.") % str(value)
|
|
|
|
|
|
|
|
# since there is no UI in cmdline mode and it is completely
|
|
|
|
# non-interactive, we can't show a message window asking the user
|
|
|
|
# to acknowledge the error; instead, print the error out and sleep
|
|
|
|
# for a few seconds before exiting the installer
|
|
|
|
print(cmdline_error_msg)
|
|
|
|
time.sleep(10)
|
|
|
|
sys.exit(1)
|
2014-04-07 12:38:09 +00:00
|
|
|
else:
|
2015-05-30 11:20:59 +00:00
|
|
|
print("\nAn unknown error has occured, look at the "
|
|
|
|
"/tmp/anaconda-tb* file(s) for more details")
|
|
|
|
# in the main thread, run exception handler
|
|
|
|
self._main_loop_handleException(dump_info)
|
|
|
|
else:
|
|
|
|
log.debug("In a non-main thread, sending a message with "
|
|
|
|
"exception data")
|
|
|
|
# not in the main thread, just send message with exception
|
|
|
|
# data and let message handler run the exception handler in
|
|
|
|
# the main thread
|
|
|
|
exc_info = dump_info.exc_info
|
|
|
|
hubQ.send_exception((exc_info.type,
|
|
|
|
exc_info.value,
|
|
|
|
exc_info.stack))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
def postWriteHook(self, dump_info):
|
|
|
|
anaconda = dump_info.object
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# See if there is a /root present in the root path and put exception there as well
|
|
|
|
if os.access(iutil.getSysroot() + "/root", os.X_OK):
|
2013-01-23 17:28:19 +00:00
|
|
|
try:
|
2015-03-23 11:36:12 +00:00
|
|
|
dest = iutil.getSysroot() + "/root/%s" % os.path.basename(self.exnFile)
|
2013-01-23 17:28:19 +00:00
|
|
|
shutil.copyfile(self.exnFile, dest)
|
2014-04-07 12:38:09 +00:00
|
|
|
except (shutil.Error, IOError):
|
2015-03-23 11:36:12 +00:00
|
|
|
log.error("Failed to copy %s to %s/root", self.exnFile, iutil.getSysroot())
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
# run kickstart traceback scripts (if necessary)
|
|
|
|
try:
|
|
|
|
kickstart.runTracebackScripts(anaconda.ksdata.scripts)
|
2015-03-23 11:36:12 +00:00
|
|
|
# pylint: disable=bare-except
|
2013-01-23 17:28:19 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
iutil.ipmi_report(IPMI_FAILED)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def runDebug(self, exc_info):
|
|
|
|
if flags.can_touch_runtime_system("switch console") \
|
|
|
|
and self._intf_tty_num != 1:
|
|
|
|
iutil.vtActivate(1)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
iutil.eintr_retry_call(os.open, "/dev/console", os.O_RDWR) # reclaim stdin
|
|
|
|
iutil.eintr_retry_call(os.dup2, 0, 1) # reclaim stdout
|
|
|
|
iutil.eintr_retry_call(os.dup2, 0, 2) # reclaim stderr
|
|
|
|
# ^
|
|
|
|
# |
|
|
|
|
# +------ dup2 is magic, I tells ya!
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
# bring back the echo
|
|
|
|
import termios
|
|
|
|
si = sys.stdin.fileno()
|
|
|
|
attr = termios.tcgetattr(si)
|
|
|
|
attr[3] = attr[3] & termios.ECHO
|
|
|
|
termios.tcsetattr(si, termios.TCSADRAIN, attr)
|
|
|
|
|
|
|
|
print("\nEntering debugger...")
|
|
|
|
print("Use 'continue' command to quit the debugger and get back to "\
|
|
|
|
"the main window")
|
|
|
|
import pdb
|
2014-04-07 12:38:09 +00:00
|
|
|
pdb.post_mortem(exc_info.stack)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
if flags.can_touch_runtime_system("switch console") \
|
|
|
|
and self._intf_tty_num != 1:
|
|
|
|
iutil.vtActivate(self._intf_tty_num)
|
2013-01-23 17:28:19 +00:00
|
|
|
|
|
|
|
def initExceptionHandling(anaconda):
|
|
|
|
fileList = [ "/tmp/anaconda.log", "/tmp/packaging.log",
|
|
|
|
"/tmp/program.log", "/tmp/storage.log", "/tmp/ifcfg.log",
|
2015-03-23 11:36:12 +00:00
|
|
|
"/tmp/dnf.log", "/tmp/dnf.rpm.log",
|
|
|
|
"/tmp/yum.log", iutil.getSysroot() + "/root/install.log",
|
2014-04-07 12:38:09 +00:00
|
|
|
"/proc/cmdline" ]
|
|
|
|
|
|
|
|
if os.path.exists("/tmp/syslog"):
|
2013-01-23 17:28:19 +00:00
|
|
|
fileList.extend(["/tmp/syslog"])
|
|
|
|
|
|
|
|
if anaconda.opts and anaconda.opts.ksfile:
|
|
|
|
fileList.extend([anaconda.opts.ksfile])
|
|
|
|
|
|
|
|
conf = Config(programName="anaconda",
|
2015-03-23 11:36:12 +00:00
|
|
|
programVersion=startup_utils.get_anaconda_version_string(),
|
2014-04-07 12:38:09 +00:00
|
|
|
programArch=os.uname()[4],
|
2013-01-23 17:28:19 +00:00
|
|
|
attrSkipList=["_intf._actions",
|
2014-04-07 12:38:09 +00:00
|
|
|
"_intf._currentAction._xklwrapper",
|
|
|
|
"_intf._currentAction._spokes[\"KeyboardSpoke\"]._xkl_wrapper",
|
2015-03-23 11:36:12 +00:00
|
|
|
"_intf._currentAction._storage_playground",
|
|
|
|
"_intf._currentAction._spokes[\"CustomPartitioningSpoke\"]._storage_playground",
|
2014-04-07 12:38:09 +00:00
|
|
|
"_intf._currentAction.language.translations",
|
|
|
|
"_intf._currentAction.language.locales",
|
|
|
|
"_intf._currentAction._spokes[\"PasswordSpoke\"]._oldweak",
|
|
|
|
"_intf._currentAction._spokes[\"PasswordSpoke\"]._password",
|
|
|
|
"_intf._currentAction._spokes[\"UserSpoke\"]._password",
|
|
|
|
"_intf._currentAction._spokes[\"UserSpoke\"]._oldweak",
|
2013-01-23 17:28:19 +00:00
|
|
|
"_intf.storage.bootloader.password",
|
|
|
|
"_intf.storage.data",
|
|
|
|
"_intf.storage.encryptionPassphrase",
|
|
|
|
"_bootloader.encrypted_password",
|
|
|
|
"_bootloader.password",
|
|
|
|
"payload._groups",
|
|
|
|
"payload._yum"],
|
2014-04-07 12:38:09 +00:00
|
|
|
localSkipList=[ "passphrase", "password", "_oldweak", "_password" ],
|
2013-01-23 17:28:19 +00:00
|
|
|
fileList=fileList)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
conf.register_callback("lsblk_output", lsblk_callback, attchmnt_only=True)
|
|
|
|
conf.register_callback("nmcli_dev_list", nmcli_dev_list_callback,
|
|
|
|
attchmnt_only=True)
|
|
|
|
conf.register_callback("type", lambda: "anaconda", attchmnt_only=True)
|
2015-03-23 11:36:12 +00:00
|
|
|
conf.register_callback("addons", list_addons_callback, attchmnt_only=False)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
if "/tmp/syslog" not in fileList:
|
|
|
|
# no syslog, grab output from journalctl and put it also to the
|
|
|
|
# anaconda-tb file
|
|
|
|
conf.register_callback("journalctl", journalctl_callback, attchmnt_only=False)
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
interactive = not anaconda.displayMode == 'c'
|
2014-04-07 12:38:09 +00:00
|
|
|
handler = AnacondaExceptionHandler(conf, anaconda.intf.meh_interface,
|
2015-03-23 11:36:12 +00:00
|
|
|
ReverseExceptionDump, anaconda.intf.tty_num,
|
2015-05-30 11:20:59 +00:00
|
|
|
anaconda.gui_initialized, interactive)
|
2013-01-23 17:28:19 +00:00
|
|
|
handler.install(anaconda)
|
|
|
|
|
|
|
|
return conf
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def lsblk_callback():
|
|
|
|
"""Callback to get info about block devices."""
|
|
|
|
|
|
|
|
return iutil.execWithCapture("lsblk", ["--perms", "--fs", "--bytes"])
|
|
|
|
|
|
|
|
def nmcli_dev_list_callback():
|
|
|
|
"""Callback to get info about network devices."""
|
|
|
|
|
|
|
|
return iutil.execWithCapture("nmcli", ["device", "show"])
|
|
|
|
|
|
|
|
def journalctl_callback():
|
|
|
|
"""Callback to get logs from journalctl."""
|
|
|
|
|
|
|
|
# regex to filter log messages from anaconda's process (we have that in our
|
|
|
|
# logs)
|
|
|
|
anaconda_log_line = re.compile(r"\[%d\]:" % os.getpid())
|
|
|
|
ret = ""
|
|
|
|
for line in iutil.execReadlines("journalctl", ["-b"]):
|
|
|
|
if anaconda_log_line.search(line) is None:
|
|
|
|
# not an anaconda's message
|
|
|
|
ret += line + "\n"
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
def list_addons_callback():
|
|
|
|
"""
|
|
|
|
Callback to get info about the addons potentially affecting Anaconda's
|
|
|
|
behaviour.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# list available addons and take their package names
|
|
|
|
addon_pkgs = glob.glob("/usr/share/anaconda/addons/*")
|
|
|
|
return ", ".join(addon.rsplit("/", 1)[1] for addon in addon_pkgs)
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
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
|
2014-04-07 12:38:09 +00:00
|
|
|
from pyanaconda.threads import AnacondaThread
|
|
|
|
threadMgr.add(AnacondaThread(name=THREAD_EXCEPTION_HANDLING_TEST,
|
2013-01-23 17:28:19 +00:00
|
|
|
target=raise_exception,
|
|
|
|
args=(msg, non_ascii)))
|