[asterisk-commits] mjordan: testsuite/asterisk/trunk r3810 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 31 09:02:09 CDT 2013


Author: mjordan
Date: Fri May 31 09:02:07 2013
New Revision: 3810

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3810
Log:
Only create pcap files if told to do so

While making pcaps on every test run seems like a good idea, there's a few
downsides to this.
(1) More artifacts than you may need
(2) More importantly, yappcap will report a packet for each dump file being
    created. This means that if you create two listeners, each listener gets
    each packet twice. Three listeners; three instances of the same packet.
    While this is certainly a bug in yappcap, it's trivial enough to only create
    a single listener - but that also means we shouldn't be creating one by
    default.

This patch also lets derived tests register pcap observers, if they are
content with the default listener created by the base class.

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

Modified: asterisk/trunk/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestCase.py?view=diff&rev=3810&r1=3809&r2=3810
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestCase.py Fri May 31 09:02:07 2013
@@ -89,11 +89,13 @@
         self.testStateController = None
         self.pcap = None
         self.pcapfilename = None
+        self.create_pcap = False
         self._stopping = False
         self.testlogdir = os.path.join(Asterisk.test_suite_root, self.base, str(os.getpid()))
         self.ast_version = AsteriskVersion()
         self._stop_callbacks = []
         self._ami_callbacks = []
+        self._pcap_callbacks = []
 
         """ Pull additional configuration from YAML config if possible """
         if test_config and 'reactor-timeout' in test_config:
@@ -113,7 +115,7 @@
             print "WARNING: no logging.conf file found; using default configuration"
             logging.basicConfig(level=self.defaultLogLevel)
 
-        if PCAP_AVAILABLE:
+        if PCAP_AVAILABLE and self.create_pcap:
             self.pcapfilename = os.path.join(self.testlogdir, "dumpfile.pcap")
             self.pcap = self.create_pcap_listener(dumpfile=self.pcapfilename)
 
@@ -444,6 +446,8 @@
 
     def __pcap_callback(self, packet):
         self.pcap_callback(packet)
+        for callback in self._pcap_callbacks:
+            callback(packet)
 
     def handleOriginateFailure(self, reason):
         """
@@ -488,6 +492,16 @@
             self.passed = False
 
         return self.passed
+
+    def register_pcap_observer(self, callback):
+        ''' Register an observer that will be called when a packet is received
+        from a created pcap listener
+
+        Parameters:
+        callback The callback to receive the packet. The callback function
+        should take in a single parameter, which will be the packet received
+        '''
+        self._pcap_callbacks.append(callback)
 
     def register_stop_observer(self, callback):
         ''' Register an observer that will be called when Asterisk is stopped




More information about the asterisk-commits mailing list