[asterisk-commits] testsuite: Allow log files to be disabled by tests. (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 16 13:11:20 CST 2015


Anonymous Coward #1000019 has submitted this change and it was merged.

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, 20 insertions(+), 10 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Mark Michelson: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Ashley Sanders: Looks good to me, approved



diff --git a/lib/python/asterisk/test_case.py b/lib/python/asterisk/test_case.py
index f123826..ea24e0c 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:
+        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:
+        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,15 @@
             if 'reactor-timeout' in test_config:
                 self.reactor_timeout = test_config['reactor-timeout']
             self.ast_conf_options = test_config.get('ast-config-options')
+            log_full = test_config.get('log-full', True)
+            log_messages = test_config.get('log-messages', True)
         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: merged
Gerrit-Change-Id: I55924b1f68373204617f26dd2ac8c1cef5ae4468
Gerrit-PatchSet: 2
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Ashley Sanders <asanders at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list