[asterisk-commits] mjordan: testsuite/asterisk/trunk r2225 - in /asterisk/trunk: ./ lib/python/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 14 15:55:45 CDT 2011


Author: mjordan
Date: Wed Sep 14 15:55:41 2011
New Revision: 2225

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2225
Log:
Added archiving of Asterisk logs on test failure

On a test failure, runtests will attempt to create a hard link to the
Asterisk logs for the test that failed.  If it fails to create the
hard link, it will copy the logs to the archival directory.

Review: https://reviewboard.asterisk.org/r/1431/

Modified:
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/runtests.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=2225&r1=2224&r2=2225
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Wed Sep 14 15:55:41 2011
@@ -45,9 +45,7 @@
     asterisk.conf.
     """
 
-    """The base working directory of this instance of Asterisk
-    """
-    baseDirectory = ""
+    test_suite_root = "/tmp/asterisk-testsuite"
 
     def __init__(self, base=None, ast_conf_options=None, host="127.0.0.1"):
         """Construct an Asterisk instance.
@@ -63,7 +61,8 @@
         self.directories = {}
         self.ast_version = AsteriskVersion()
 
-        self.base = "/tmp/asterisk-testsuite"
+        self.base = Asterisk.test_suite_root
+        self.baseDirectory = self.base
         self.astetcdir = "/etc/asterisk"
         self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
         self.host = host

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=2225&r1=2224&r2=2225
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Wed Sep 14 15:55:41 2011
@@ -15,6 +15,7 @@
 import time
 import yaml
 import socket
+import shutil
 
 sys.path.append("lib/python")
 
@@ -65,9 +66,39 @@
             self.__parse_run_output(self.stdout)
 
             self.passed = (p.returncode == 0 and self.test_config.expectPass) or (p.returncode and not self.test_config.expectPass)
+            if not self.passed:
+                self.__archive_ast_logs()
+
         else:
             print "FAILED TO EXECUTE %s, it must exist and be executable" % cmd
         self.time = time.time() - start_time
+
+    def __archive_ast_logs(self):
+        ast_directories = "%s/%s" % (Asterisk.test_suite_root, self.test_name.lstrip("tests/"))
+        i = 1
+        while True:
+            if os.path.isdir("%s/ast%d" % (ast_directories, i)):
+                ast_dir = "%s/ast%d/var/log/asterisk" % (ast_directories, i)
+                dest_dir = "./logs/%s/ast%d/var/log/asterisk" % (self.test_name.lstrip("tests/"), i)
+                """ Only archive the logs if we havent archived it for this test run yet """
+                if not os.path.exists(dest_dir):
+                    try:
+                        os.makedirs(dest_dir)
+                        os.link(ast_dir + "/messages", dest_dir + "/messages")
+                        os.link(ast_dir + "/full", dest_dir + "/full")
+                    except OSError as (errno, strerror):
+                        """ Different partitions can cause this to fail """
+                        print "OSError occurred while copying %s ([%d]: %s)" % (ast_dir, errno, strerror)
+                        print "Attempting copy"
+                        try:
+                            shutil.copy(ast_dir + "/messages", dest_dir + "/messages")
+                            shutil.copy(ast_dir + "/full", dest_dir + "/full")
+                        except shutil.Error, err:
+                            for e in err:
+                                print "Exception occurred while archiving logs from %s to %s: %s" % (e[0], e[1], e[2])
+            else:
+                break
+            i += 1
 
     def __check_deps(self, ast_version):
         self.can_run = self.test_config.check_deps(ast_version)




More information about the asterisk-commits mailing list