[newui 2/2] Add packaging log and scriptlet logging

Brian C. Lane bcl at redhat.com
Wed Aug 1 19:09:00 UTC 2012


From: "Brian C. Lane" <bcl at 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
-- 
1.7.7.6



More information about the anaconda-patches mailing list