[asterisk-commits] mjordan: testsuite/asterisk/trunk r4462 - in /asterisk/trunk/tests/apps/chans...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 15 16:35:47 CST 2013


Author: mjordan
Date: Sun Dec 15 16:35:42 2013
New Revision: 4462

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4462
Log:
chanspy_w_mixmonitor: abandon Console channel driver; update to TestCase

This patch updates the chanspy_w_mixmonitor test such that it no longer uses
the console channel driver. It now uses a Local channel attached to a MoH
source to test the ChanSpy-ing. Additionally, it is now based on the TestCase
class, such that it gains the benefits of using that common base class.


Modified:
    asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/configs/ast1/extensions.conf
    asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test
    asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/test-config.yaml

Modified: asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/configs/ast1/extensions.conf?view=diff&rev=4462&r1=4461&r2=4462
==============================================================================
--- asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/configs/ast1/extensions.conf Sun Dec 15 16:35:42 2013
@@ -9,6 +9,10 @@
 exten => play_exten,n,Playback(${TALK_AUDIO})
 exten => play_exten,n,Playback(${TALK_AUDIO})
 exten => play_exten,n,Playback(${TALK_AUDIO})
+
+exten => generate,1,NoOp()
+exten => generate,n,StartMusicOnHold()
+exten => generate,n,Echo()
 
 exten => chanspytest,1,MixMonitor(${TESTAUDIO1}.gsm)
 exten => chanspytest,n,ChanSpy(SIP,q)

Modified: asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test?view=diff&rev=4462&r1=4461&r2=4462
==============================================================================
--- asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test (original)
+++ asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test Sun Dec 15 16:35:42 2013
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 '''
-Copyright (C) 2010, Digium, Inc.
+Copyright (C) 2010-2013, Digium, Inc.
 David Vossel <dvossel at digium.com>
 
 This program is free software, distributed under the terms of
@@ -11,6 +11,8 @@
 import os
 import signal
 import subprocess
+import logging
+
 from twisted.application import service, internet
 from twisted.internet import reactor, defer
 from starpy import manager
@@ -18,148 +20,153 @@
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
 
-workingdir = "apps/chanspy/chanspy_w_mixmonitor"
-testdir = "tests/%s" % workingdir
+LOGGER = logging.getLogger(__name__)
 
+class ChanSpyMixMonitorTest(TestCase):
 
-class ChanSpyMixMonitorTest:
     def __init__(self):
-        self.last_step = ""
-        self.passed = False
-        self.numSpyEvents = 0
-        self.expectedSpyEvents = 3
-        self.talkDetected = 0
-        self.test_to = 30
+        """Constructor"""
+        super(ChanSpyMixMonitorTest, self).__init__()
 
-        reactor.callWhenRunning(self.run)
-        self.agi = fastagi.FastAGIFactory(self.reportPassed)
-        reactor.listenTCP(4573, self.agi, self.test_to, '127.0.0.1')
+        self.received_spy_events = 0
+        self.expected_spy_events = 3
+        self.talk_detected = 0
+        self.chanspy_channel = ""
 
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
-        self.talkingaudio = os.path.join(os.getcwd(), "%s/sounds/talking" % (testdir))
-        self.audiofile1 = os.path.join(os.getcwd(), "%s/testaudio1" % (testdir))
+        self.talkingaudio = os.path.join(os.getcwd(), "%s/sounds/talking" % self.test_name)
+        self.audiofile1 = os.path.join(os.getcwd(), "%s/testaudio1" % self.test_name)
 
-    def reportPassed(self, agi):
-        print "GOT PASS RESULTS!!!\n"
+        self.create_asterisk()
+
+    def fastagi_connect(self, agi):
+        LOGGER.info("Got pass results!")
+
         sequence = fastagi.InSequence()
         sequence.append(agi.execute, "HangUp")
         sequence.append(agi.finish)
-        self.passed = True
-        reactor.callLater(1, self.readResult)
+
+        self.set_passed(True)
+        reactor.callLater(1, self.read_result)
+
         return sequence()
 
-    def readResult(self):
-        self.stop_reactor()
+    def read_result(self):
         if self.passed == True:
-            print 'SIP ChanSpy test PASSED!'
+            self.stop_reactor()
+            LOGGER.info("SIP ChanSpy test PASSED!")
         else:
-            print 'SIP ChanSpy Test FAILED'
+            LOGGER.warn("SIP ChanSpy test FAILED!")
 
-    def stop_reactor(self):
-        def __finish_stop(result):
-            print "Stopping Reactor ..."
-            if reactor.running:
-                reactor.stop()
-            return result
-        df = self.ast1.stop()
-        df.addCallback(__finish_stop)
+    def handle_chanspy_start(self, ami, event):
+        """Handler for the ChanSpyStart AMI event"""
 
-    def chanspyEvent(self, ami, event):
-        self.numSpyEvents += 1
-        self.logLastStep('Received ChanSpyStart event for %s' % event['spyeechannel'])
-        if event['spyeechannel'].count('end_a') > 0:
-            reactor.callLater(1, self.aHangup)
-            reactor.callLater(3, self.bCall)
-        if event['spyeechannel'].count('end_b') > 0:
-            reactor.callLater(1, self.bHangup)
-            reactor.callLater(3, self.cCall)
-        if event['spyeechannel'].count('end_c') > 0:
-            reactor.callLater(2, self.cHangup)
-            reactor.callLater(3, self.hangupChanSpy)
+        self.received_spy_events += 1
+        LOGGER.info("Received ChanSpyStart event for %s" % event["spyeechannel"])
+        if event["spyeechannel"].count("end_a") > 0:
+            reactor.callLater(1, self.hangup_pjsua, self.pja, "A")
+            reactor.callLater(3, self.call_pjsua, self.pjb, "B")
+        if event["spyeechannel"].count("end_b") > 0:
+            reactor.callLater(1, self.hangup_pjsua, self.pjb, "B")
+            reactor.callLater(3, self.call_pjsua, self.pjc, "C")
+        if event["spyeechannel"].count("end_c") > 0:
+            reactor.callLater(2, self.hangup_pjsua, self.pjc, "C")
+            reactor.callLater(3, self.hangup_chanspy)
 
-    def amiOnConnect(self, ami):
-        self.logLastStep("Connected to the AMI")
-        self.ami = ami
-        self.ami.registerEvent('ChanSpyStart', self.chanspyEvent)
-        self.ami.setVar(channel = "", variable = "TESTAUDIO1", value = self.audiofile1)
-        self.ami.setVar(channel = "", variable = "TALK_AUDIO", value = self.talkingaudio)
+    def handle_newexten(self, ami, event):
+        """Handler for the Newexten AMI event"""
 
-    def amiLoginError(self, ami):
-        self.logLastStep("AMI login failed")
-        reactor.callLater(1, self.readResult)
+        if event["context"] != "test" or event["extension"] != "chanspytest" or event["priority"] != "1":
+            return
+        self.chanspy_channel = event["channel"]
+        LOGGER.debug("ChanSpy channel set to %s." % self.chanspy_channel)
 
-    def amiLogin(self):
-        self.logLastStep("Logging in to the AMI")
-        self.ami_factory = manager.AMIFactory("user", "mysecret")
-        self.ami_factory.login('127.0.0.1', 5038).addCallbacks(self.amiOnConnect, self.amiLoginError)
+    def ami_connect(self, ami):
+        """AMI Connect handler"""
 
-    def aCall(self):
-        self.logLastStep("A Calling into Playback")
-        self.pja.stdin.write("m\n")
-        self.pja.stdin.write("sip:play_exten at 127.0.0.1:5060\n")
+        self.ami_instance = ami
+        self.ami_instance.registerEvent('ChanSpyStart', self.handle_chanspy_start)
+        self.ami_instance.registerEvent('Newexten', self.handle_newexten)
+        self.ami_instance.setVar(channel="", variable="TESTAUDIO1", value=self.audiofile1)
+        self.ami_instance.setVar(channel="", variable="TALK_AUDIO", value=self.talkingaudio)
+        self.start_processes()
+        reactor.callLater(1, self.call_chanspy)
+        reactor.callLater(2, self.call_pjsua, self.pja, "A")
 
-    def bCall(self):
-        self.logLastStep("B Calling into Playback")
-        self.pjb.stdin.write("m\n")
-        self.pjb.stdin.write("sip:play_exten at 127.0.0.1:5060\n")
+    def call_pjsua(self, pjsua, name):
+        """Have some PJSUA instance call into Asterisk
 
-    def cCall(self):
-        self.logLastStep("C Calling into Playback")
-        self.pjc.stdin.write("m\n")
-        self.pjc.stdin.write("sip:play_exten at 127.0.0.1:5060\n")
+        Keyword Arguments:
+        pjsua The instance of pjsua to use
+        name The name to call the instance
+        """
+        LOGGER.info("%s Calling into Playback" % name)
+        pjsua.stdin.write("m\n")
+        pjsua.stdin.write("sip:play_exten at 127.0.0.1:5060\n")
 
-    def aHangup(self):
-        self.pja.stdin.write("h\n")
+    def hangup_pjsua(self, pjsua, name):
+        """Hangup some PJSUA instance
 
-    def bHangup(self):
-        self.pjb.stdin.write("h\n")
+        Keyword Arguments:
+        pjsua The instance of pjsua to use
+        name The name to call the instance
+        """
+        LOGGER.info("Hanging up %s" % name)
+        pjsua.stdin.write("h\n")
 
-    def cHangup(self):
-        self.pjc.stdin.write("h\n")
-
-    def startProcesses(self):
-        self.logLastStep("Starting Processes")
+    def start_processes(self):
+        """Start up the PJSUA processes"""
+        LOGGER.info("Starting Processes")
         self.pja = subprocess.Popen(['pjsua', '--local-port=5065', '--auto-answer=200', '--null-audio'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
         self.pjb = subprocess.Popen(['pjsua', '--local-port=5066', '--auto-answer=200', '--null-audio'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
         self.pjc = subprocess.Popen(['pjsua', '--local-port=5067', '--auto-answer=200', '--null-audio'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 
-    def stopProcesses(self):
-        self.logLastStep("Stopping Processes")
+    def stop_processes(self):
+        """Stop said processes with prejudice"""
+        LOGGER.info("Stopping processes")
         os.kill(self.pja.pid, signal.SIGKILL)
         os.kill(self.pjb.pid, signal.SIGKILL)
         os.kill(self.pjc.pid, signal.SIGKILL)
 
-    def logLastStep(self, step):
-        print step
-        self.lastStep = step
+    def stop_reactor(self):
+        """Override of TestCase.stop_reactor"""
+        super(ChanSpyMixMonitorTest, self).stop_reactor()
+        self.stop_processes()
 
-    def callChanSpy(self):
-        self.logLastStep("Placing call to ChanSpy extension.")
-        self.ast1.cli_exec("console dial chanspytest at test")
+    def call_chanspy(self):
+        """Start spying!"""
 
-    def hangupChanSpy(self):
-        self.logLastStep("Hangup ChanSpy.")
-        self.ast1.cli_exec("console hangup")
-        reactor.callLater(2, self.verifyAudio)
+        LOGGER.info("Placing call to ChanSpy extension.")
+        self.ami_instance.originate(channel="Local/chanspytest at test",
+                           exten="generate",
+                           context="test",
+                           priority="1").addErrback(self.handleOriginateFailure)
 
-    def verifyAudio(self):
-        self.ast1.cli_originate("Local/play_recording at test extension detect_audio at test")
+    def hangup_chanspy(self):
+        """Hangup the current ChanSpy channel"""
+
+        LOGGER.info("Hangup ChanSpy channel %s." % self.chanspy_channel)
+        self.ami_instance.hangup(channel=self.chanspy_channel)
+        reactor.callLater(2, self.verify_audio)
+
+    def verify_audio(self):
+        """Verifies that audio was left appropriately from the last iteration"""
+
+        self.ami_instance.originate(channel="Local/play_recording at test",
+                           exten="detect_audio",
+                           context="test",
+                           priority="1").addErrback(self.handleOriginateFailure)
+
+    def stop_asterisk(self):
+        """Override of TestCase.stop_asterisk"""
+        self.read_result()
 
     def run(self):
-        def __finish_start_ops(result):
-            self.startProcesses()
-            # call extensions
-            self.amiLogin()
-            reactor.callLater(1, self.callChanSpy)
-            reactor.callLater(2, self.aCall)
-            # stop and read results after timeout
-            reactor.callLater(self.test_to, self.readResult)
-            return result
-
-        df = self.ast1.start()
-        df.addCallback(__finish_start_ops)
+        """Override of TestCase.run"""
+        super(ChanSpyMixMonitorTest, self).run()
+        self.create_fastagi_factory()
+        self.create_ami_factory()
 
 def main():
     test = ChanSpyMixMonitorTest()

Modified: asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/test-config.yaml?view=diff&rev=4462&r1=4461&r2=4462
==============================================================================
--- asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/test-config.yaml Sun Dec 15 16:35:42 2013
@@ -16,7 +16,11 @@
         - python : 'starpy'
         - app : 'pjsua'
         - asterisk : 'app_talkdetect'
+        - asterisk : 'res_musiconhold'
+        - asterisk : 'app_mixmonitor'
+        - asterisk : 'app_chanspy'
         - asterisk : 'chan_sip'
+
     tags:
         - SIP
         - chanspy




More information about the asterisk-commits mailing list