yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1040619-yum-cron-reporting.patch

5e9bef
commit 1fb713cdabf46694e76df4092615607fa09016fe
5e9bef
Author: Zdenek Pavlas <zpavlas@redhat.com>
5e9bef
Date:   Thu Dec 19 10:43:07 2013 +0100
5e9bef
5e9bef
    yum-cron: initialize both debuglevel and errorlevel
5e9bef
    
5e9bef
    When warnings or errors are disabled in verbose
5e9bef
    logger, disable them in error logger too.
5e9bef
5e9bef
diff --git a/yum-cron/yum-cron.py b/yum-cron/yum-cron.py
5e9bef
index a1fd10b..19436e5 100755
5e9bef
--- a/yum-cron/yum-cron.py
5e9bef
+++ b/yum-cron/yum-cron.py
5e9bef
@@ -380,16 +380,16 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
             self.preconf.fn = self.opts.yum_config_file
5e9bef
 
5e9bef
             # This needs to be set early, errors are handled later.
5e9bef
-            try: self.preconf.debuglevel = int(self._confparser.get('base', 'debuglevel'))
5e9bef
-            except: pass
5e9bef
+            try: level = int(self._confparser.get('base', 'debuglevel'))
5e9bef
+            except: level = -2
5e9bef
+            self.preconf.debuglevel = level
5e9bef
+            if -4 <= level <= -2:
5e9bef
+                self.preconf.errorlevel = level + 4
5e9bef
 
5e9bef
             # if we are not root do the special subdir thing
5e9bef
             if os.geteuid() != 0:
5e9bef
                 self.setCacheDir()
5e9bef
 
5e9bef
-            # Create the configuration
5e9bef
-            self.conf
5e9bef
-
5e9bef
             # override base yum options
5e9bef
             self.conf.populate(self._confparser, 'base')
5e9bef
             del self._confparser
5e9bef
commit d0441397dc5a5e4f4d3ccc3a99c4cda57b228009
5e9bef
Author: Valentina Mukhamedzhanova <vmukhame@redhat.com>
5e9bef
Date:   Mon Jan 6 14:12:46 2014 +0100
5e9bef
5e9bef
    Remove emitCheckFailed(), change it to logger.warn(). BZ 1048391
5e9bef
    
5e9bef
    Make acquireLock() respect debuglevel.
5e9bef
5e9bef
diff --git a/yum-cron/yum-cron.py b/yum-cron/yum-cron.py
5e9bef
index b96dd13..386a7a0 100755
5e9bef
--- a/yum-cron/yum-cron.py
5e9bef
+++ b/yum-cron/yum-cron.py
5e9bef
@@ -86,17 +86,6 @@ class UpdateEmitter(object):
5e9bef
                            % errmsg)
5e9bef
         self.sendMessages()
5e9bef
 
5e9bef
-    def lockFailed(self, errmsg):
5e9bef
-        """Append a message to the output list stating that the
5e9bef
-        program failed to acquire the yum lock, then call sendMessages
5e9bef
-        to emit the output.
5e9bef
-
5e9bef
-        :param errmsg: a string that contains the error message
5e9bef
-        """
5e9bef
-        self.output.append("Failed to acquire the yum lock with the following error message: \n%s"
5e9bef
-                           % errmsg)
5e9bef
-        self.sendMessages()
5e9bef
-
5e9bef
     def checkFailed(self, errmsg):
5e9bef
         """Append a message to the output stating that checking for
5e9bef
         updates failed, then call sendMessages to emit the output.
5e9bef
@@ -196,16 +185,6 @@ class EmailEmitter(UpdateEmitter):
5e9bef
         self.subject = "Yum: Failed to perform setup on %s" % self.opts.system_name
5e9bef
         super(EmailEmitter, self).setupFailed(errmsg)
5e9bef
 
5e9bef
-    def lockFailed(self, errmsg):
5e9bef
-        """Append a message to the output list stating that the
5e9bef
-        program failed to acquire the yum lock, then call sendMessages
5e9bef
-        to emit the output, and set an appropriate subject line.
5e9bef
-
5e9bef
-        :param errmsg: a string that contains the error message
5e9bef
-        """
5e9bef
-        self.subject = "Yum: Failed to  acquire the yum lock on %s" % self.opts.system_name
5e9bef
-        super(EmailEmitter, self).lockFailed(errmsg)
5e9bef
-
5e9bef
     def checkFailed(self, errmsg):
5e9bef
         """Append a message to the output stating that checking for
5e9bef
         updates failed, then call sendMessages to emit the output, and
5e9bef
@@ -406,7 +385,7 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
         try:
5e9bef
             self.doLock()
5e9bef
         except yum.Errors.LockError, e:
5e9bef
-            self.emitLockFailed("%s" % e)
5e9bef
+            self.logger.warn("Failed to acquire the yum lock: %s", e)
5e9bef
             sys.exit(1)
5e9bef
 
5e9bef
     def populateUpdateMetadata(self):
5e9bef
@@ -675,10 +654,6 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
         """Emit a notice stating that checking for updates failed."""
5e9bef
         map(lambda x: x.setupFailed(error), self.emitters)
5e9bef
 
5e9bef
-    def emitLockFailed(self, errmsg):
5e9bef
-        """Emit a notice that we failed to acquire the yum lock."""
5e9bef
-        map(lambda x: x.lockFailed(errmsg), self.emitters)
5e9bef
-
5e9bef
     def emitCheckFailed(self, error):
5e9bef
         """Emit a notice stating that checking for updates failed."""
5e9bef
         map(lambda x: x.checkFailed(error), self.emitters)
5e9bef
commit 13f69f68876fade7611bcbab6f612937e1c02bff
5e9bef
Author: Zdenek Pavlas <zpavlas@redhat.com>
5e9bef
Date:   Wed Jan 15 09:11:30 2014 +0100
5e9bef
5e9bef
    yum-cron: emitUpdateFailed() expects str, not an array.
5e9bef
    
5e9bef
    Avoid Python noise in the report.  Also, use implicit conversion
5e9bef
    instead of str() for unicode interoperability.
5e9bef
5e9bef
diff --git a/yum-cron/yum-cron.py b/yum-cron/yum-cron.py
5e9bef
index 87b3e69..6cbed94 100755
5e9bef
--- a/yum-cron/yum-cron.py
5e9bef
+++ b/yum-cron/yum-cron.py
5e9bef
@@ -545,7 +545,7 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
                 try:
5e9bef
                     self.getKeyForPackage(po)
5e9bef
                 except yum.Errors.YumBaseError, errmsg:
5e9bef
-                    self.emitUpdateFailed([str(errmsg)])
5e9bef
+                    self.emitUpdateFailed(errmsg)
5e9bef
                     return False
5e9bef
             else:
5e9bef
                 self.emitUpdateFailed(err)
5e9bef
@@ -563,8 +563,7 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
         try:
5e9bef
             self.runTransaction(cb=cb)
5e9bef
         except yum.Errors.YumBaseError, err:
5e9bef
-            
5e9bef
-            self.emitUpdateFailed([str(err)])
5e9bef
+            self.emitUpdateFailed(err)
5e9bef
             sys.exit(1)
5e9bef
 
5e9bef
         if emit :
5e9bef
@@ -675,9 +674,9 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
         """Emit a notice stating that downloading the updates failed."""
5e9bef
         map(lambda x: x.downloadFailed(error), self.emitters)
5e9bef
 
5e9bef
-    def emitUpdateFailed(self, errmsgs):
5e9bef
+    def emitUpdateFailed(self, errmsg):
5e9bef
         """Emit a notice stating that automatic updates failed."""
5e9bef
-        map(lambda x: x.updatesFailed(errmsgs), self.emitters)
5e9bef
+        map(lambda x: x.updatesFailed(errmsg), self.emitters)
5e9bef
 
5e9bef
     def emitMessages(self):
5e9bef
         """Emit the messages from the emitters."""
5e9bef
commit 048af21d6704d40e93e09c65f5c1b547a68e431e
5e9bef
Author: Zdenek Pavlas <zpavlas@redhat.com>
5e9bef
Date:   Mon Jan 20 10:59:58 2014 +0100
5e9bef
5e9bef
    yum-cron: EmailEmitter failure should not be fatal. BZ 1055042
5e9bef
5e9bef
diff --git a/yum-cron/yum-cron.py b/yum-cron/yum-cron.py
5e9bef
index 6cbed94..bfa580e 100755
5e9bef
--- a/yum-cron/yum-cron.py
5e9bef
+++ b/yum-cron/yum-cron.py
5e9bef
@@ -146,8 +146,9 @@ class UpdateEmitter(object):
5e9bef
 class EmailEmitter(UpdateEmitter):
5e9bef
     """Emitter class to send messages via email."""
5e9bef
 
5e9bef
-    def __init__(self, opts):
5e9bef
+    def __init__(self, opts, logger):
5e9bef
         super(EmailEmitter, self).__init__(opts)        
5e9bef
+        self.logger = logger
5e9bef
         self.subject = ""
5e9bef
 
5e9bef
     def updatesAvailable(self, summary):
5e9bef
@@ -229,10 +230,13 @@ class EmailEmitter(UpdateEmitter):
5e9bef
         msg['To'] = ",".join(self.opts.email_to)
5e9bef
 
5e9bef
         # Send the email
5e9bef
-        s = smtplib.SMTP()
5e9bef
-        s.connect(self.opts.email_host)
5e9bef
-        s.sendmail(self.opts.email_from, self.opts.email_to, msg.as_string())
5e9bef
-        s.close()
5e9bef
+        try:
5e9bef
+            s = smtplib.SMTP()
5e9bef
+            s.connect(self.opts.email_host)
5e9bef
+            s.sendmail(self.opts.email_from, self.opts.email_to, msg.as_string())
5e9bef
+            s.close()
5e9bef
+        except Exception, e:
5e9bef
+            self.logger.error("Failed to send an email to %s: %s" % (self.opts.email_host, e))
5e9bef
 
5e9bef
 
5e9bef
 class StdIOEmitter(UpdateEmitter):
5e9bef
@@ -293,7 +297,7 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
         # Create the emitters, and add them to the list
5e9bef
         self.emitters = []
5e9bef
         if 'email' in self.opts.emit_via:
5e9bef
-            self.emitters.append(EmailEmitter(self.opts))
5e9bef
+            self.emitters.append(EmailEmitter(self.opts, self.logger))
5e9bef
         if 'stdio' in self.opts.emit_via:
5e9bef
             self.emitters.append(StdIOEmitter(self.opts))
5e9bef
 
5e9bef
commit 8d21de54f5b267af8710c1358fd3a0475aed6bbb
5e9bef
Author: Zdenek Pavlas <zpavlas@redhat.com>
5e9bef
Date:   Mon Jan 20 11:41:15 2014 +0100
5e9bef
5e9bef
    yum-cron: Add a retry loop around doLock().
5e9bef
5e9bef
diff --git a/yum-cron/yum-cron.py b/yum-cron/yum-cron.py
5e9bef
index bfa580e..e1028be 100755
5e9bef
--- a/yum-cron/yum-cron.py
5e9bef
+++ b/yum-cron/yum-cron.py
5e9bef
@@ -262,6 +262,8 @@ class YumCronConfig(BaseConfig):
5e9bef
     system_name = Option(gethostname())
5e9bef
     output_width = IntOption(80)
5e9bef
     random_sleep = IntOption(0)
5e9bef
+    lock_retries = IntOption(5)
5e9bef
+    lock_sleep = IntOption(60)
5e9bef
     emit_via = ListOption(['email','stdio'])
5e9bef
     email_to = ListOption(["root"])
5e9bef
     email_from = Option("root")
5e9bef
@@ -386,9 +388,14 @@ class YumCronBase(yum.YumBase, YumOutput):
5e9bef
     def acquireLock(self):
5e9bef
         """ Wrapper method around doLock to emit errors correctly."""
5e9bef
 
5e9bef
-        try:
5e9bef
-            self.doLock()
5e9bef
-        except yum.Errors.LockError, e:
5e9bef
+        i = 0
5e9bef
+        while True:
5e9bef
+            try: self.doLock(); break
5e9bef
+            except yum.Errors.LockError, e:
5e9bef
+                i += 1
5e9bef
+                if i < self.opts.lock_retries:
5e9bef
+                    sleep(self.opts.lock_sleep)
5e9bef
+                    continue
5e9bef
             self.logger.warn("Failed to acquire the yum lock: %s", e)
5e9bef
             sys.exit(1)
5e9bef