[Asterisk-code-review] chanspy barge: rewrite to remove pjsua dependency (testsuite[master])

Jenkins2 asteriskteam at digium.com
Wed Oct 31 09:30:48 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/10553 )

Change subject: chanspy_barge: rewrite to remove pjsua dependency
......................................................................

chanspy_barge: rewrite to remove pjsua dependency

When Asterisk was upgraded to use pjproject 2.8 a patch that was made to pjsua
caused pjsua to default to a TCP transport. This caused any testsuite test that
spawned pjsua as an endpoint to start to fail as they were using UDP (e.g.
chanspy_barge). An easy solution here is to set those particular tests to pass
the '--no-tcp' option to pjsua.

However, at some point we want to remove the dependency to pjsua altogther from
the testsuite. That being the case the chanspy_barge test has been rewritten to
not longer use pjsua. Instead this test just now uses local channels to test the
"barge" functionality.

ASTERISK~28096

Change-Id: Ia4ab4e37b867cc6b4cd7351e22adc3862d4b34eb
---
M tests/apps/chanspy/chanspy_barge/configs/ast1/extensions.conf
D tests/apps/chanspy/chanspy_barge/configs/ast1/rtp.conf
D tests/apps/chanspy/chanspy_barge/configs/ast1/sip.conf
D tests/apps/chanspy/chanspy_barge/run-test
D tests/apps/chanspy/chanspy_barge/sounds/talking.wav
M tests/apps/chanspy/chanspy_barge/test-config.yaml
6 files changed, 71 insertions(+), 214 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Corey Farrell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/tests/apps/chanspy/chanspy_barge/configs/ast1/extensions.conf b/tests/apps/chanspy/chanspy_barge/configs/ast1/extensions.conf
index 89008da..02854d2 100644
--- a/tests/apps/chanspy/chanspy_barge/configs/ast1/extensions.conf
+++ b/tests/apps/chanspy/chanspy_barge/configs/ast1/extensions.conf
@@ -1,25 +1,23 @@
-[general]
+[default]
+exten => create_bridge,1,NoOp()
+	same => n,Dial(Local/detect_barge)
+	same => n,Hangup()
 
-[globals]
+exten => detect_barge,1,NoOp()
+	same => n,Answer()
+	; Transmit silence so the "other" side doesn't detect
+	; its audio from "this" side
+	same => n,BackgroundDetect(silence/10,1)
+	same => n,Log(ERROR, Channel ${CHANNEL} failed to detect barged audio)
+	same => n,Hangup()
 
-[test]
-exten => play_exten,1,Answer()
-exten => play_exten,n,MixMonitor(${TESTAUDIO1}.wav)
-exten => play_exten,n,Wait(3)
-exten => play_exten,n,StopMixMonitor()
-exten => play_exten,n,Hangup()
+exten => talk,1,NoOp()
+	; Once talking is detected wait for the other side. The test will hang
+	; things up once it both sides successfully enter the "talk" extension.
+	same => n,Verbose(Detected barged audio on channel ${CHANNEL})
+	same => n,Echo()
 
-exten => chanspytest,1,ChanSpy(SIP,qB)
-
-exten => detect_audio,1,Answer()
-exten => detect_audio,n,Set(TALK_DETECTED=0) ; initialize TALK_DETECT var
-exten => detect_audio,n,BackgroundDetect(${TALK_AUDIO},1,20,,20000)
-exten => detect_audio,n,GoToIf($[${TALK_DETECTED}=0]?talkdetectfail:talkdetectpass)
-exten => detect_audio,n(talkdetectfail),Hangup()
-
-;PASSED!
-exten => detect_audio,n(talkdetectpass),AGI(agi://127.0.0.1:4573)
-
-exten => play_recording,1,Answer()
-exten => play_recording,n,PlayBack(${TESTAUDIO1})
-exten => play_recording,n,Echo()
\ No newline at end of file
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Playback(hello-world)
+	same => n,Hangup()
diff --git a/tests/apps/chanspy/chanspy_barge/configs/ast1/rtp.conf b/tests/apps/chanspy/chanspy_barge/configs/ast1/rtp.conf
deleted file mode 100644
index fb420ba..0000000
--- a/tests/apps/chanspy/chanspy_barge/configs/ast1/rtp.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-[general]
-; Turn off strictrtp so that DTMF does not get dropped
-strictrtp=no
diff --git a/tests/apps/chanspy/chanspy_barge/configs/ast1/sip.conf b/tests/apps/chanspy/chanspy_barge/configs/ast1/sip.conf
deleted file mode 100644
index c9bcb00..0000000
--- a/tests/apps/chanspy/chanspy_barge/configs/ast1/sip.conf
+++ /dev/null
@@ -1,29 +0,0 @@
-[general]
-directmedia=no
-
-[end_a]
-context=test
-type=friend
-host=127.0.0.1
-port=5065
-insecure=invite
-disallow=all
-allow=ulaw
-
-[end_b]
-context=test
-type=friend
-host=127.0.0.1
-port=5066
-insecure=invite
-disallow=all
-allow=ulaw
-
-[end_c]
-context=test
-type=friend
-host=127.0.0.1
-port=5067
-insecure=invite
-disallow=all
-allow=ulaw
diff --git a/tests/apps/chanspy/chanspy_barge/run-test b/tests/apps/chanspy/chanspy_barge/run-test
deleted file mode 100755
index e1b8bc6..0000000
--- a/tests/apps/chanspy/chanspy_barge/run-test
+++ /dev/null
@@ -1,146 +0,0 @@
-#!/usr/bin/env python
-'''
-Copyright (C) 2010-2014, Digium, Inc.
-David Vossel <dvossel at digium.com>
-Matt Jordan <mjordan at digium.com>
-
-This program is free software, distributed under the terms of
-the GNU General Public License Version 2.
-'''
-
-import sys
-import os
-import signal
-import subprocess
-import logging
-
-from twisted.application import service, internet
-from twisted.internet import reactor, defer
-from starpy import manager
-from starpy import fastagi
-
-sys.path.append("lib/python")
-from asterisk.test_case import TestCase
-
-LOGGER = logging.getLogger(__name__)
-
-class ChanSpyBarge(TestCase):
-    def __init__(self):
-        super(ChanSpyBarge, self).__init__()
-        self.last_step = ""
-        self.passed = False
-        self.numSpyEvents = 0
-        self.expectedSpyEvents = 3
-        self.talkDetected = 0
-        self.test_to = 25
-
-        self.create_asterisk()
-        self.create_fastagi_factory()
-
-        ast_conf_options = {
-            "transmit_silence" : "yes",
-        }
-
-        self.talkingaudio = os.path.join(os.getcwd(), "%s/sounds/talking" % self.test_name)
-        self.audiofile1 = self.ast[0].get_path("astspooldir", "tmp", "testaudio1")
-
-    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)
-        return sequence()
-
-    def readResult(self):
-        self.stop_reactor()
-        LOGGER.info("Reading results")
-        self.ast[0].cli_exec("core show locks")   # get lock output in case of deadlock before tearing down.
-        self.ast[0].cli_exec("core show channels")# if channels are still up for some reason, we want to know that as well
-
-        self.ast[0].cli_exec("core show globals") # The global variables here hold failure conditions
-
-        if self.passed == True:
-            LOGGER.info('SIP ChanSpy test PASSED!')
-        else:
-            LOGGER.error('SIP ChanSpy Test FAILED')
-
-    def chanspyEvent(self, ami, event):
-        LOGGER.info('Received ChanSpyStart event')
-        self.numSpyEvents += 1
-        if event['spyeechannel'].count('end_a') > 0:
-            reactor.callLater(3, self.aHangup)
-            reactor.callLater(4, self.bHangup)
-
-    def ami_connect(self, 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)
-
-        reactor.callLater(1, self.callChanSpy)
-        reactor.callLater(2, self.aCall)
-
-
-    def aCall(self):
-        LOGGER.info("A Calling into Wait")
-        self.pja.stdin.write("m\n")
-        self.pja.stdin.write("sip:play_exten at 127.0.0.1:5060\n")
-
-    def bCall(self):
-        LOGGER.info("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 aHangup(self):
-        LOGGER.info("Hanging up A")
-        self.pja.stdin.write("h\n")
-
-    def bHangup(self): #calls into chanspy extension and plays audio to A using Barge
-        LOGGER.info("Hanging up B")
-        self.pjb.stdin.write("h\n")
-        reactor.callLater(2, self.verifyAudio)
-
-    def startProcesses(self):
-        LOGGER.info("Starting Processes")
-        playfilearg = "--play-file=%s.wav" % (self.talkingaudio)
-        self.pja = subprocess.Popen(['pjsua', '--local-port=5065', '--auto-answer=200', '--null-audio', '--auto-loop'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-        self.pjb = subprocess.Popen(['pjsua', '--local-port=5066', '--auto-answer=200', playfilearg, '--null-audio', '--auto-play'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-
-    def stopProcesses(self):
-        LOGGER.info("Stopping Processes")
-        os.kill(self.pja.pid, signal.SIGKILL)
-        os.kill(self.pjb.pid, signal.SIGKILL)
-
-    def callChanSpy(self):
-        LOGGER.info("Placing call to ChanSpy extension.")
-        self.ast[0].cli_originate("SIP/end_b extension chanspytest at test")
-
-    def verifyAudio(self):
-        LOGGER.info("Verifying Audio")
-        self.ast[0].cli_originate("Local/play_recording at test extension detect_audio at test")
-
-    def stop_asterisk(self):
-        if not self.passed:
-            self.readResult()
-
-    def run(self):
-        self.create_ami_factory()
-
-
-def main():
-    test = ChanSpyBarge()
-    test.startProcesses()
-    reactor.run()
-    test.stopProcesses()
-    if test.passed != True:
-        return 1
-    return 0
-
-if __name__ == "__main__":
-    sys.exit(main() or 0)
-
-
-# vim:sw=4:ts=4:expandtab:textwidth=79
diff --git a/tests/apps/chanspy/chanspy_barge/sounds/talking.wav b/tests/apps/chanspy/chanspy_barge/sounds/talking.wav
deleted file mode 100644
index 6304af0..0000000
--- a/tests/apps/chanspy/chanspy_barge/sounds/talking.wav
+++ /dev/null
Binary files differ
diff --git a/tests/apps/chanspy/chanspy_barge/test-config.yaml b/tests/apps/chanspy/chanspy_barge/test-config.yaml
index e3ec313..83ef805 100644
--- a/tests/apps/chanspy/chanspy_barge/test-config.yaml
+++ b/tests/apps/chanspy/chanspy_barge/test-config.yaml
@@ -1,28 +1,65 @@
 testinfo:
-    summary:     'Test Chanspy with the \"B\" option for barging in on both channels.'
+    summary: 'Test Chanspy with the \"B\" option for barging in on both channels.'
     description: |
-        'This test verifies basic functionality of using ChanSpy with the 
-         barge option set. MixMonitor is used to record the audio on the
-         spied on channel to verify the barging spy channel audio is received.  
-         Also, since the Wait() application is used during barge, this verifies 
-         that the behavior of transmitting silence during ast_safe_sleep works with
-         transmit_silence=yes configured in asterisk.conf. Without transmitting
-         silence during wait, the barge audio will not be mixed and this test will
-         fail.'
+        'This test verifies basic functionality of using ChanSpy with the
+         barge option set. Both sides of the call transmit silence using
+         BackgroundDetect. This ensures that any noise/audio heard only
+         comes from the barging channel.'
+
+test-modules:
+    test-object:
+        config-section: test-config
+        typename: 'test_case.SimpleTestCase'
+    modules:
+        -
+            config-section: event-action-config
+            typename: 'pluggable_modules.EventActionModule'
+
+test-config:
+    test-iterations:
+        -
+            channel: 'Local/detect_barge'
+            context: 'default'
+            exten: 'create_bridge'
+            priority: 1
+
+event-action-config:
+    -
+        ami-events:
+            conditions:
+                match:
+                    Event: 'Newexten'
+                    Application: 'BackgroundDetect'
+            count: '2'
+            trigger-on-count: True
+        ami-actions:
+            action:
+                Action: 'Originate'
+                Channel: 'Local/s'
+                Application: 'ChanSpy'
+                Data: 'Local/detect_barge,qBE'
+    -
+        ami-events:
+            conditions:
+                match:
+                    Event: 'Newexten'
+                    Application: 'Echo'
+            count: '2'
+            trigger-on-count: True
+        ami-actions:
+            action:
+                Action: 'UserEvent'
+                UserEvent: 'Done'
 
 properties:
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
-        - app : 'pjsua'
         - asterisk : 'app_chanspy'
         - asterisk : 'app_echo'
-        - asterisk : 'app_mixmonitor'
         - asterisk : 'app_playback'
         - asterisk : 'app_talkdetect'
-        - asterisk : 'chan_sip'
         - asterisk : 'pbx_config'
-        - asterisk : 'res_agi'
     tags:
-        - SIP
         - chanspy
+

-- 
To view, visit https://gerrit.asterisk.org/10553
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia4ab4e37b867cc6b4cd7351e22adc3862d4b34eb
Gerrit-Change-Number: 10553
Gerrit-PatchSet: 3
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181031/16a57a93/attachment-0001.html>


More information about the asterisk-code-review mailing list