[asterisk-commits] wdoekes: testsuite/asterisk/trunk r3006 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 24 15:28:18 CST 2012


Author: wdoekes
Date: Tue Jan 24 15:28:14 2012
New Revision: 3006

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3006
Log:
Add option to silence cli_exec() warnings.

Fixes the "Exited non-zero [1] while ... waitfullybooted']" warnings.
Sometimes the waitfullybooted call is executed before asterisk has had
time to create an asterisk.ctl. Previously this would cause a warning
to be emitted, even though the while loop in start() ensures that the
call is retried.

Modified:
    asterisk/trunk/lib/python/asterisk/asterisk.py

Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=3006&r1=3005&r2=3006
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Tue Jan 24 15:28:14 2012
@@ -141,7 +141,7 @@
         while True:
             # This command should stall until completed, but if an
             # exception occurs, it returns the empty string.
-            if not self.cli_exec("core waitfullybooted"):
+            if not self.cli_exec("core waitfullybooted", warn_on_fail=False):
                 if time.time() - start > 5:
                     logger.error("Unknown state of asterisk. Stopping waitfullybooted...")
                     break
@@ -349,7 +349,7 @@
         else:
             self.cli_exec("channel originate %s" % argstr, blocking=blocking)
 
-    def cli_exec(self, cli_cmd, blocking=True):
+    def cli_exec(self, cli_cmd, blocking=True, warn_on_fail=True):
         """Execute a CLI command on this instance of Asterisk.
 
         Keyword Arguments:
@@ -360,6 +360,9 @@
         Example Usage:
         asterisk.cli_exec("core set verbose 10")
         """
+        # Downplay warnings if the caller requests it
+        warn = (logger.debug, logger.warn)[bool(warn_on_fail)]
+
         cmd = [
             self.ast_binary,
             "-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf"),
@@ -375,20 +378,20 @@
             process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
         except OSError:
-            logger.warn("Failed to execute command: %s" % str(cmd))
+            warn("Failed to execute command: %s" % str(cmd))
             return ""
 
         output = ""
         try:
             for l in process.stdout.readlines():
-                logger.debug(l),
+                logger.debug(l.rstrip())
                 output += l
         except IOError:
             pass
         try:
             res = process.wait()
             if res != None and res != 0:
-                logger.warn("Exited non-zero [%d] while executing command %s" % (res, str(cmd)))
+                warn("Exited non-zero [%d] while executing command %s" % (res, str(cmd)))
                 output = ""
         except OSError:
             pass




More information about the asterisk-commits mailing list