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

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