[Asterisk-code-review] testsuite: Allow log files to be disabled by tests. (testsuite[master])

Joshua Colp asteriskteam at digium.com
Mon Nov 16 10:21:47 CST 2015


Joshua Colp has uploaded a new change for review.

  https://gerrit.asterisk.org/1637

Change subject: testsuite: Allow log files to be disabled by tests.
......................................................................

testsuite: Allow log files to be disabled by tests.

The testsuite currently always creates a full log file with
debug and higher log output as well as a messages log file with
info and higher. For tests that generate a lot of output this
can overwhelm python itself. This change allows tests to disable
either of these log files if they want.

The con of doing so is that you have to rely on the Asterisk log
files to understand what is going on instead.

ASTERISK-25562 #close

Change-Id: I55924b1f68373204617f26dd2ac8c1cef5ae4468
---
M lib/python/asterisk/test_case.py
M sample-yaml/test-config.yaml.sample
2 files changed, 22 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/37/1637/1

diff --git a/lib/python/asterisk/test_case.py b/lib/python/asterisk/test_case.py
index f123826..f86d354 100644
--- a/lib/python/asterisk/test_case.py
+++ b/lib/python/asterisk/test_case.py
@@ -34,7 +34,7 @@
 LOGGER = None
 
 
-def setup_logging(log_dir):
+def setup_logging(log_dir, log_full, log_messages):
     """Initialize the logger"""
 
     global LOGGER
@@ -64,15 +64,17 @@
     datefmt = '%b %d %H:%M:%S'
     form = logging.Formatter(fmt=fmt, datefmt=datefmt)
 
-    full_handler = logging.FileHandler(os.path.join(log_dir, 'full.txt'))
-    full_handler.setLevel(logging.DEBUG)
-    full_handler.setFormatter(form)
-    root_logger.addHandler(full_handler)
+    if log_full == 'True':
+        full_handler = logging.FileHandler(os.path.join(log_dir, 'full.txt'))
+        full_handler.setLevel(logging.DEBUG)
+        full_handler.setFormatter(form)
+        root_logger.addHandler(full_handler)
 
-    messages_handler = logging.FileHandler(os.path.join(log_dir, 'messages.txt'))
-    messages_handler.setLevel(logging.INFO)
-    messages_handler.setFormatter(form)
-    root_logger.addHandler(messages_handler)
+    if log_messages == 'True':
+        messages_handler = logging.FileHandler(os.path.join(log_dir, 'messages.txt'))
+        messages_handler.setLevel(logging.INFO)
+        messages_handler.setFormatter(form)
+        root_logger.addHandler(messages_handler)
 
 
 class TestCase(object):
@@ -138,6 +140,8 @@
         self._ami_callbacks = []
         self._pcap_callbacks = []
         self._stop_deferred = None
+        log_full = 'True'
+        log_messages = 'True'
 
         if os.getenv("VALGRIND_ENABLE") == "true":
             self.reactor_timeout *= 20
@@ -147,13 +151,17 @@
             if 'reactor-timeout' in test_config:
                 self.reactor_timeout = test_config['reactor-timeout']
             self.ast_conf_options = test_config.get('ast-config-options')
+            if 'log-full' in test_config:
+                log_full = test_config['log-full']
+            if 'log-messages' in test_config:
+                log_messages = test_config['log-messages']
         else:
             self.ast_conf_options = None
 
         os.makedirs(self.testlogdir)
 
         # Set up logging
-        setup_logging(self.testlogdir)
+        setup_logging(self.testlogdir, log_full, log_messages)
 
         LOGGER.info("Executing " + self.test_name)
 
diff --git a/sample-yaml/test-config.yaml.sample b/sample-yaml/test-config.yaml.sample
index 6c1acf6..f282248 100644
--- a/sample-yaml/test-config.yaml.sample
+++ b/sample-yaml/test-config.yaml.sample
@@ -213,6 +213,10 @@
 test-object-config:
     reactor-timeout: 30
     spawn-after-hangup: True
+    # Whether a full log file containg DEBUG level should be created, defaults to True
+    log-full: True
+    # Whether a messages log file containing INFO level should be created, defaults to True
+    log-messages: True
     test-iterations:
         -
             channel: 'Local/play at default'

-- 
To view, visit https://gerrit.asterisk.org/1637
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55924b1f68373204617f26dd2ac8c1cef5ae4468
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list