From: "Brian C. Lane" bcl@redhat.com
The second instance of rsyslog is not needed, and it interferes with virtio logging. The yum and rpm file io logging will be dealt with in another patch. --- pyanaconda/backend_log.py | 95 ---------------------------------- pyanaconda/packaging/__init__.py | 27 ---------- pyanaconda/packaging/yumpayload.py | 15 +----- pyanaconda/ui/gui/tools/run-spoke.py | 1 - 4 files changed, 2 insertions(+), 136 deletions(-) delete mode 100644 pyanaconda/backend_log.py
diff --git a/pyanaconda/backend_log.py b/pyanaconda/backend_log.py deleted file mode 100644 index 9125d73..0000000 --- a/pyanaconda/backend_log.py +++ /dev/null @@ -1,95 +0,0 @@ -# backend_log.py -# Logging infrastructure for Anaconda's backend. -# -# Copyright (C) 2009 Red Hat, Inc. -# -# This copyrighted material is made available to anyone wishing to use, -# modify, copy, or redistribute it subject to the terms and conditions of -# the GNU General Public License v.2, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY expressed or implied, including the implied warranties 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, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the -# source code or documentation are not subject to the GNU General Public -# License and may only be used or replicated with the express permission of -# Red Hat, Inc. -# -# Red Hat Author(s): Ales Kozumplik akozumpl@redhat.com -# - -import logging -import os -import signal - -import anaconda_log -import iutil - -SYSLOG_PATH = '/sbin/rsyslogd' -SYSLOG_PIDFILE = '/var/run/rsyslog_backend.pid' -SYSLOG_CFGFILE = '/tmp/rsyslog_backend.conf' - -CFG_TEMPLATE = """ -$ModLoad imuxsock -$InputUnixListenSocketHostName sysimage -$AddUnixListenSocket %(socket)s -+sysimage -*.* %(logfile)s;RSYSLOG_TraditionalFileFormat -%(remote_syslog)s -""" - -global_log = logging.getLogger("anaconda") -class BackendSyslog: - def __init__(self): - pass - - def build_cfg(self, root, log): - socket = "%s/dev/log" % (root, ) - remote_syslog = '' - if anaconda_log.logger.remote_syslog: - remote_syslog = "*.* @@%s" % (anaconda_log.logger.remote_syslog, ) - - cfg = CFG_TEMPLATE % { - 'socket' : socket, - 'logfile' : log, - 'remote_syslog' : remote_syslog - } - with open(SYSLOG_CFGFILE, 'w') as cfg_file: - cfg_file.write(cfg) - - def start(self, root, log): - """ Start an rsyslogd instance dedicated for the sysimage. - - Other possibility would be to change configuration and SIGHUP the - existing instance, but it could lose some of its internal queues and - give us problems with remote logging. - """ - self.build_cfg(root, log) - args = ['-c', '4', - '-f', SYSLOG_CFGFILE, - '-i', str(SYSLOG_PIDFILE)] - status = iutil.execWithRedirect(SYSLOG_PATH, args) - if status == 0: - global_log.info("Backend logger started.") - else: - global_log.error("Unable to start backend logger") - - def stop(self): - try: - with open(SYSLOG_PIDFILE, 'r') as pidfile: - pid = int(pidfile.read()) - os.kill(pid, signal.SIGKILL) - except Exception: - pass - else: - global_log.info("Backend logger stopped.") - - try: - os.unlink(SYSLOG_CFGFILE) - except OSError as e: - global_log.error("Failed to unlink backend logger config file: %s" - % e) - -log = BackendSyslog() diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py index 02a1a5d..19316e3 100644 --- a/pyanaconda/packaging/__init__.py +++ b/pyanaconda/packaging/__init__.py @@ -50,8 +50,6 @@ from pykickstart.parser import Group import logging log = logging.getLogger("anaconda")
-from pyanaconda.backend_log import log as instlog - from pyanaconda.errors import * #from pyanaconda.progress import progress
@@ -472,27 +470,6 @@ class Payload(object): """ Perform pre-installation tasks. """ iutil.mkdirChain(ROOT_PATH + "/root")
- if self.data.upgrade.upgrade: - mode = "upgrade" - else: - mode = "install" - - log_file_name = "%s.log" % mode - log_file_path = "%s/root/%s" % (ROOT_PATH, log_file_name) - try: - shutil.rmtree (log_file_path) - except OSError: - pass - - self.install_log = open(log_file_path, "w+") - - syslogname = "%s.syslog" % log_file_path - try: - shutil.rmtree (syslogname) - except OSError: - pass - instlog.start(ROOT_PATH, syslogname) - if packages is not None: map(self.selectPackage, packages)
@@ -595,10 +572,6 @@ class Payload(object):
self._copyDriverDiskFiles()
- # stop logger - instlog.stop() - - class ImagePayload(Payload): """ An ImagePayload installs an OS image to the target system. """ def __init__(self, data): diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py index 85f534c..0273c1b 100644 --- a/pyanaconda/packaging/yumpayload.py +++ b/pyanaconda/packaging/yumpayload.py @@ -1002,13 +1002,8 @@ reposdir=%s self._yum.ts.order() self._yum.ts.clean()
- # set up rpm logging to go to our log - self._yum.ts.ts.scriptFd = self.install_log.fileno() - rpm.setLogFile(self.install_log) - # create the install callback - rpmcb = RPMCallback(self._yum, self.install_log, - upgrade=self.data.upgrade.upgrade) + rpmcb = RPMCallback(self._yum, upgrade=self.data.upgrade.upgrade)
if flags.testing: self._yum.ts.setFlags(rpm.RPMTRANS_FLAG_TEST) @@ -1038,10 +1033,8 @@ reposdir=%s raise exn else: log.info("transaction complete") - self.install_log.write("*** FINISHED INSTALLING PACKAGES ***") progress.send_step() finally: - self.install_log.close() self._yum.ts.close() iutil.resetRpmDb()
@@ -1069,9 +1062,8 @@ reposdir=%s super(YumPayload, self).postInstall()
class RPMCallback(object): - def __init__(self, yb, log, upgrade=False): + def __init__(self, yb, upgrade=False): self._yum = yb # yum.YumBase - self.install_log = log # file instance self.upgrade = upgrade # boolean
self.package_file = None # file instance (package file management) @@ -1134,9 +1126,6 @@ class RPMCallback(object): self.completed_actions, self.total_actions) log.info(log_msg) - self.install_log.write("%s %s\n" % (time.strftime("%H:%M:%S"), - log_msg)) - self.install_log.flush() progress.send_message(progress_msg)
self.package_file = None diff --git a/pyanaconda/ui/gui/tools/run-spoke.py b/pyanaconda/ui/gui/tools/run-spoke.py index 6114155..5f5a44a 100755 --- a/pyanaconda/ui/gui/tools/run-spoke.py +++ b/pyanaconda/ui/gui/tools/run-spoke.py @@ -98,7 +98,6 @@ instclass = DefaultInstall()
payload = YumPayload(ksdata) payload.setup(storage) -payload.install_log = sys.stdout
spoke = spokeClass(ksdata, storage, payload, instclass) if hasattr(spoke, "register_event_cb"):
From: "Brian C. Lane" bcl@redhat.com
This adds a new logfile for packaging (/tmp/packaging.log) which will contain everything related to yum and rpm as well as other package systems when they are added. This also re-adds logging of the rpm scriptlet output.
The 'Installing ...' messages end up being logged twice. Because rpm only logs to a file we capture the scriptlet output along with the package install message so that you can associate scriptlet problems with their package. This adds this file's log to our logs after the transaction is complete (or fails). --- data/post-scripts/95-copy-logs.ks | 1 + pyanaconda/anaconda_log.py | 8 ++++++++ pyanaconda/packaging/__init__.py | 2 +- pyanaconda/packaging/yumpayload.py | 26 +++++++++++++++++++++++--- 4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/data/post-scripts/95-copy-logs.ks b/data/post-scripts/95-copy-logs.ks index 016b70c..7c98662 100644 --- a/data/post-scripts/95-copy-logs.ks +++ b/data/post-scripts/95-copy-logs.ks @@ -5,6 +5,7 @@ mkdir -p /mnt/sysimage/var/log/anaconda [ -e /tmp/syslog ] && cp /tmp/syslog $ANA_INSTALL_PATH/var/log/anaconda/syslog [ -e /tmp/X.log ] && cp /tmp/X.log $ANA_INSTALL_PATH/var/log/anaconda.anaconda.xlog [ -e /tmp/program.log ] && cp /tmp/program.log $ANA_INSTALL_PATH/var/log/anaconda/anaconda.program.log +[ -e /tmp/packaging.log ] && cp /tmp/packaging.log $ANA_INSTALL_PATH/var/log/anaconda/anaconda.packaging.log [ -e /tmp/storage.log ] && cp /tmp/storage.log $ANA_INSTALL_PATH/var/log/anaconda/anaconda.storage.log [ -e /tmp/ifcfg.log ] && cp /tmp/ifcfg.log $ANA_INSTALL_PATH/var/log/anaconda/anaconda.ifcfg.log [ -e /tmp/yum.log ] && cp /tmp/yum.log $ANA_INSTALL_PATH/var/log/anaconda/anaconda.yum.log diff --git a/pyanaconda/anaconda_log.py b/pyanaconda/anaconda_log.py index 68b0f70..40c1938 100644 --- a/pyanaconda/anaconda_log.py +++ b/pyanaconda/anaconda_log.py @@ -44,6 +44,7 @@ MAIN_LOG_FILE = "/tmp/anaconda.log" MAIN_LOG_TTY = "/dev/tty3" PROGRAM_LOG_FILE = "/tmp/program.log" STORAGE_LOG_FILE = "/tmp/storage.log" +PACKAGING_LOG_FILE = "/tmp/packaging.log" ANACONDA_SYSLOG_FACILITY = SysLogHandler.LOG_LOCAL1
logLevelMap = {"debug": logging.DEBUG, "info": logging.INFO, @@ -151,6 +152,13 @@ class AnacondaLog: minLevel=logging.DEBUG) self.forwardToSyslog(program_logger)
+ # Create the packaging logger. + packaging_logger = logging.getLogger("packaging") + packaging_logger.setLevel(logging.DEBUG) + self.addFileHandler(PACKAGING_LOG_FILE, packaging_logger, + minLevel=logging.DEBUG) + self.forwardToSyslog(packaging_logger) + # Create a second logger for just the stuff we want to dup on # stdout. Anything written here will also get passed up to the # parent loggers for processing and possibly be written to the diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py index 19316e3..b983626 100644 --- a/pyanaconda/packaging/__init__.py +++ b/pyanaconda/packaging/__init__.py @@ -48,7 +48,7 @@ from pyanaconda.iutil import ProxyString, ProxyStringError from pykickstart.parser import Group
import logging -log = logging.getLogger("anaconda") +log = logging.getLogger("packaging")
from pyanaconda.errors import * #from pyanaconda.progress import progress diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py index 0273c1b..84b4b84 100644 --- a/pyanaconda/packaging/yumpayload.py +++ b/pyanaconda/packaging/yumpayload.py @@ -42,11 +42,12 @@ import os import shutil import time +import tempfile
from . import *
import logging -log = logging.getLogger("anaconda") +log = logging.getLogger("packaging")
try: import rpm @@ -1002,8 +1003,14 @@ reposdir=%s self._yum.ts.order() self._yum.ts.clean()
+ # Write scriptlet output to a file to be logged later + script_log = tempfile.NamedTemporaryFile(delete=False) + self._yum.ts.ts.scriptFd = script_log.fileno() + rpm.setLogFile(script_log) + # create the install callback - rpmcb = RPMCallback(self._yum, upgrade=self.data.upgrade.upgrade) + rpmcb = RPMCallback(self._yum, script_log, + upgrade=self.data.upgrade.upgrade)
if flags.testing: self._yum.ts.setFlags(rpm.RPMTRANS_FLAG_TEST) @@ -1037,6 +1044,15 @@ reposdir=%s finally: self._yum.ts.close() iutil.resetRpmDb() + script_log.close() + + # log the contents of the scriptlet logfile + log.info("==== start rpm scriptlet logs ====") + with open(script_log.name) as f: + for l in f: + log.info(l) + log.info("==== end rpm scriptlet logs ====") + os.unlink(script_log.name)
def postInstall(self): """ Perform post-installation tasks. """ @@ -1062,8 +1078,9 @@ reposdir=%s super(YumPayload, self).postInstall()
class RPMCallback(object): - def __init__(self, yb, upgrade=False): + def __init__(self, yb, log, upgrade=False): self._yum = yb # yum.YumBase + self.install_log = log # logfile for yum script logs self.upgrade = upgrade # boolean
self.package_file = None # file instance (package file management) @@ -1126,6 +1143,9 @@ class RPMCallback(object): self.completed_actions, self.total_actions) log.info(log_msg) + self.install_log.write(log_msg+"\n") + self.install_log.flush() + progress.send_message(progress_msg)
self.package_file = None
anaconda-patches@lists.fedorahosted.org