[Asterisk-code-review] A testsuite test for 3PCC patch for AMI "SIPnotify" (ASTERIS... (testsuite[master])
Yasuhiko Kamata
asteriskteam at digium.com
Thu Dec 21 00:54:10 CST 2017
Yasuhiko Kamata has uploaded this change for review. ( https://gerrit.asterisk.org/7705
Change subject: A testsuite test for 3PCC patch for AMI "SIPnotify" (ASTERISK-27461).
......................................................................
A testsuite test for 3PCC patch for AMI "SIPnotify" (ASTERISK-27461).
This test is somewhat complicated than other tests in AMI;
because the value of "Call-ID" is needed to send "SIPnotify" AMI action.
Change-Id: Idccbf32ed6670a5205ee99bd7413c7fe0804efb1
---
A tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/extensions.conf
A tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/manager.conf
A tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/sip.conf
A tests/channels/SIP/ami/sip_notify/call_id/run-test
A tests/channels/SIP/ami/sip_notify/call_id/sipp/callee.xml
A tests/channels/SIP/ami/sip_notify/call_id/sipp/caller.xml
A tests/channels/SIP/ami/sip_notify/call_id/test-config.yaml
M tests/channels/SIP/ami/sip_notify/tests.yaml
8 files changed, 360 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/05/7705/1
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/extensions.conf b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/extensions.conf
new file mode 100644
index 0000000..106b4ff
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/extensions.conf
@@ -0,0 +1,3 @@
+[default]
+exten => callee,1,Dial(SIP/callee)
+
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/manager.conf b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/manager.conf
new file mode 100644
index 0000000..c6deda4
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/manager.conf
@@ -0,0 +1,10 @@
+[general]
+enabled = yes
+port = 5038
+
+[user]
+secret = mysecret
+permit = 127.0.0.1/255.255.255.255
+read = all
+write = all
+
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/sip.conf b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/sip.conf
new file mode 100644
index 0000000..d782b39
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/configs/ast1/sip.conf
@@ -0,0 +1,21 @@
+[general]
+udpbindaddr=0.0.0.0:5060
+
+[caller]
+type=friend
+host=127.0.0.1
+port=5062
+directmedia=no
+disallow=all
+allow=ulaw
+context=default
+
+[callee]
+type=friend
+host=127.0.0.1
+port=5063
+directmedia=no
+disallow=all
+allow=ulaw
+context=default
+
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/run-test b/tests/channels/SIP/ami/sip_notify/call_id/run-test
new file mode 100755
index 0000000..12e8d82
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/run-test
@@ -0,0 +1,199 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import logging
+import time
+import socket
+import threading
+import errno
+
+sys.path.append("lib/python")
+sys.path.append("utils")
+
+from tempfile import NamedTemporaryFile
+from twisted.internet import reactor
+from asterisk.sipp import SIPpTest
+
+WORKING_DIR = os.path.abspath(os.path.dirname(__file__))
+TEST_DIR = os.path.dirname(os.path.realpath(__file__))
+
+logger = logging.getLogger(__name__)
+
+class DupDict(dict):
+ def __setitem__(self, key, value):
+ try:
+ self[key]
+ except KeyError:
+ super(DupDict, self).__setitem__(key, [])
+ self[key].append(value)
+
+class AmiTestClientThread(threading.Thread):
+ """ AMI test client thread """
+
+ def __init__(self):
+ super(AmiTestClientThread, self).__init__()
+
+ def set_amihost(self, host, port):
+ self.host = host
+ self.port = port
+
+ def connect(self):
+ self.ami_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ while True:
+ try:
+ self.ami_client.connect((self.host, self.port))
+ break
+ except socket.error as serr:
+ if serr.errno != errno.ECONNREFUSED:
+ raise serr
+ time.sleep(0.5) # retry wait
+
+ self.ami_client_file = self.ami_client.makefile()
+
+ def close(self):
+ self.ami_client_file.close()
+ self.ami_client.close()
+
+ def receive_message(self):
+ message = DupDict()
+
+ while True:
+ linedata = self.ami_client_file.readline()
+
+ linedata = linedata.replace("\r", "")
+ linedata = linedata.replace("\n", "")
+
+ if len(linedata) < 1:
+ break
+
+ keyvalues = linedata.split(":", 1)
+ if len(keyvalues) > 1:
+ message[keyvalues[0].strip()] = keyvalues[1].strip()
+ else:
+ message[linedata.strip()] = ""
+
+ return message
+
+ def send_message(self, message):
+ messagetext = ""
+
+ for key, value in message.iteritems():
+ messagetext += key + ": " + value + "\r\n"
+ messagetext += "\r\n"
+
+ self.ami_client.send(messagetext)
+
+ def run(self):
+ # connect and receive banner
+ self.connect()
+ self.banner = self.ami_client_file.readline()
+
+ # login
+ message = { "Action": "Login", "Username": "user", "Secret": "mysecret" }
+ self.send_message(message)
+
+ # wait for "Response: Success"
+ while True:
+ message = self.receive_message()
+ if message.has_key("Response"):
+ if message["Response"][0] == "Success":
+ break
+ else:
+ print "Response is " + str(message["Response"])
+ raise
+
+ # wait for "Event: Newchannel", "Channel: SIP/callee..."
+ while True:
+ message = self.receive_message()
+ if message.has_key("Event"):
+ if message["Event"][0] == "Newchannel":
+ if message["Channel"][0][0:10] == "SIP/callee":
+ break
+ channel = message["Channel"][0]
+
+ # send "Action: Status"
+ message = { "Action": "Status", "Channel": channel, "AllVariables": "true" }
+ self.send_message(message)
+
+ # wait for "Event: Status"
+ call_id = ""
+ while True:
+ message = self.receive_message()
+ if message.has_key("Event"):
+ if message["Event"][0] == "Status":
+ if message.has_key("Variable"):
+ for value in message["Variable"]:
+ if value[0:10] == "SIPCALLID=":
+ call_id = value[10:]
+ break
+ if len(call_id) < 1:
+ raise
+
+ # send "Action: SIPnotify"
+ message = { "Action": "SIPnotify", "Channel": channel, "Variable": "Event=talk", "Call-ID": call_id }
+ self.send_message(message)
+
+ # wait for "Response: Success"
+ while True:
+ message = self.receive_message()
+ if message.has_key("Response"):
+ if message["Response"][0] == "Success":
+ break
+ else:
+ print "Response is " + str(message["Response"])
+ raise
+
+ self.close()
+
+def main():
+ sipplog = NamedTemporaryFile(delete=True)
+
+ SIPP_SCENARIOS = [
+ {
+ 'scenario': 'caller.xml',
+ '-i': '127.0.0.1',
+ '-p': '5062',
+ '-s': '3200000000',
+ '-message_file': '/tmp/caller.log', # sipplog.name,
+ # Cheat and pass two argumentless options as key and value
+ # because the SIPpTest doesn't allow us to pass ordered-args.
+ # We use -pause_msg_ign to ignore messages while being paused
+ # and then check the log (from -trace_msg) for those messages.
+ '-trace_msg': '-pause_msg_ign',
+ },
+ {
+ 'scenario': 'callee.xml',
+ '-i': '127.0.0.1',
+ '-p': '5063',
+ '-s': '3200000000',
+ '-message_file': '/tmp/callee.log', # sipplog.name,
+ # Cheat and pass two argumentless options as key and value
+ # because the SIPpTest doesn't allow us to pass ordered-args.
+ # We use -pause_msg_ign to ignore messages while being paused
+ # and then check the log (from -trace_msg) for those messages.
+ '-trace_msg': '-pause_msg_ign',
+ }
+ ]
+
+ test = SIPpTest(WORKING_DIR, TEST_DIR, SIPP_SCENARIOS)
+ test.reactor_timeout = 10
+
+ ami_client = AmiTestClientThread()
+ ami_client.set_amihost("localhost", 5038)
+ ami_client.start()
+
+ reactor.run()
+
+ # If it failed, bail.
+ if not test.passed:
+ return 1
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
+
+# vim:sw=4:ts=4:expandtab:textwidth=79
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/sipp/callee.xml b/tests/channels/SIP/ami/sip_notify/call_id/sipp/callee.xml
new file mode 100755
index 0000000..d3bff3c
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/sipp/callee.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Notify Request with Call-ID">
+
+ <recv request="INVITE">
+ <action>
+ <ereg regexp=": .*"
+ search_in="hdr"
+ header="Call-ID"
+ check_it="true"
+ assign_to="1"/>
+ <ereg regexp=": .*"
+ search_in="hdr"
+ header="CSeq"
+ check_it="true"
+ assign_to="2"/>
+ <log message="Received INVITE with Call-ID [$1] and CSeq [$2]." />
+ </action>
+ </recv>
+
+ <send>
+ <![CDATA[
+
+ SIP/2.0 180 Ringing
+ [last_Via:]
+ [last_From:]
+ [last_To:];tag=[pid]SIPpTag[call_number]
+ Call-ID: [call_id]
+ [last_CSeq:]
+ Contact: <sip:user1@[local_ip]:[local_port];transport=[transport]>
+ Content-Length: 0
+ ]]>
+ </send>
+
+ <recv request="NOTIFY">
+ <action>
+ <ereg regexp=": .*$"
+ search_in="hdr"
+ header="Call-ID"
+ check_it="true"
+ assign_to="3"/>
+ <log message="Received NOTIFY with Call-ID [$3]." />
+ </action>
+ </recv>
+
+ <send>
+ <![CDATA[
+
+ SIP/2.0 200 OK
+ [last_Via:]
+ [last_From:]
+ [last_To:];tag=[pid]SIPpTag[call_number]
+ Call-ID: [call_id]
+ [last_CSeq:]
+ Contact: <sip:user1@[local_ip]:[local_port];transport=[transport]>
+ Content-Length: 0
+ ]]>
+ </send>
+
+ <send>
+ <![CDATA[
+
+ SIP/2.0 200 OK
+ [last_Via:]
+ [last_From:]
+ [last_To:];tag=[pid]SIPpTag[call_number]
+ Call-ID: [call_id]
+ CSeq[$2]
+ Contact: <sip:user1@[local_ip]:[local_port];transport=[transport]>
+ Content-Type: application/sdp
+ Content-Length: [len]
+ ]]>
+ </send>
+
+</scenario>
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/sipp/caller.xml b/tests/channels/SIP/ami/sip_notify/call_id/sipp/caller.xml
new file mode 100644
index 0000000..373d361
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/sipp/caller.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Notify Request with Call-ID">
+
+ <send retrans="500">
+ <![CDATA[
+ INVITE sip:callee at voxbone.com SIP/2.0
+ Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+ From: caller <sip:caller at voxbone.com>;tag=[call_number]
+ To: callee <sip:callee at voxbone.com:[remote_port]>
+ Call-ID: [call_id]
+ CSeq: 1 INVITE
+ Contact: sip:sipp@[local_ip]:[local_port]
+ Content-Type: application/sdp
+ Content-Length: [len]
+ v=0
+ o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+ s=-
+ c=IN IP[local_ip_type] [local_ip]
+ t=0 0
+ m=audio 9000 RTP/AVP 8
+ a=rtpmap:8 PCMU/8000
+ ]]>
+ </send>
+
+ <recv response="100" optional="true">
+ </recv>
+
+ <recv response="180" optional="true">
+ </recv>
+
+ <recv response="200">
+ </recv>
+</scenario>
diff --git a/tests/channels/SIP/ami/sip_notify/call_id/test-config.yaml b/tests/channels/SIP/ami/sip_notify/call_id/test-config.yaml
new file mode 100644
index 0000000..47c9199
--- /dev/null
+++ b/tests/channels/SIP/ami/sip_notify/call_id/test-config.yaml
@@ -0,0 +1,15 @@
+info:
+ summary: 'Test SIPNotify AMI Action for Call-ID'
+ description: |
+ This Tests the AMI Action SIPNotify in order to make sure
+ that Call-ID header can be specified.
+
+properties:
+ minversion: '12.0.0'
+ dependencies:
+ - sipp :
+ version : 'v3.0'
+ - asterisk : 'chan_sip'
+ tags:
+ - SIP
+
diff --git a/tests/channels/SIP/ami/sip_notify/tests.yaml b/tests/channels/SIP/ami/sip_notify/tests.yaml
index b1a3008..750f6d6 100644
--- a/tests/channels/SIP/ami/sip_notify/tests.yaml
+++ b/tests/channels/SIP/ami/sip_notify/tests.yaml
@@ -2,3 +2,4 @@
tests:
- test: 'custom_headers'
- test: 'content'
+ - test: 'call_id'
--
To view, visit https://gerrit.asterisk.org/7705
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idccbf32ed6670a5205ee99bd7413c7fe0804efb1
Gerrit-Change-Number: 7705
Gerrit-PatchSet: 1
Gerrit-Owner: Yasuhiko Kamata <yasuhiko.kamata at nxtg.co.jp>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171221/03326506/attachment-0001.html>
More information about the asterisk-code-review
mailing list