[Asterisk-code-review] tests/channels/SIP/sip channel params: Convert to Python test (testsuite[master])

Joshua Colp asteriskteam at digium.com
Thu Aug 13 15:29:27 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: tests/channels/SIP/sip_channel_params: Convert to Python test
......................................................................


tests/channels/SIP/sip_channel_params: Convert to Python test

This change converts the tests/channels/SIP/sip_channel_params test
to be Python based instead of Lua based. As part of this the way
the test fundamentally works has been changed to be consistent with
other tests and to also reduce the test execution time. Instead of
relying on AMI to query for values this is done as part of the
dialplan execution. Once all values have been checked the test ends
immediately.

Change-Id: I15ce51ddb9bc72ecab37771414b5ab81c7d44c4d
---
M tests/channels/SIP/sip_channel_params/configs/ast1/extensions.conf
M tests/channels/SIP/sip_channel_params/configs/ast1/sip.conf
D tests/channels/SIP/sip_channel_params/run-test
M tests/channels/SIP/sip_channel_params/sipp/call.xml
D tests/channels/SIP/sip_channel_params/sipp/register.xml
M tests/channels/SIP/sip_channel_params/test-config.yaml
D tests/channels/SIP/sip_channel_params/test.lua
7 files changed, 76 insertions(+), 209 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Ashley Sanders: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/tests/channels/SIP/sip_channel_params/configs/ast1/extensions.conf b/tests/channels/SIP/sip_channel_params/configs/ast1/extensions.conf
index 251468c..8efe619 100644
--- a/tests/channels/SIP/sip_channel_params/configs/ast1/extensions.conf
+++ b/tests/channels/SIP/sip_channel_params/configs/ast1/extensions.conf
@@ -1,5 +1,31 @@
-[channel_test]
 
-exten => test,1,Answer
-exten => test,n,Playback(demo-congrats)
-exten => test,n,Hangup
+[default]
+
+exten => test_variable,1,NoOp()
+same => n,Set(field=${LOCAL(ARG1)})
+same => n,Set(actual=${LOCAL(ARG2)})
+same => n,Set(expected=${LOCAL(ARG3)})
+same => n,set(expected_alternate=${LOCAL(ARG4)})
+same => n,GotoIf($["${actual}"="${expected}"]?pass)
+same => n,GotoIf($["${actual}"="${expected_alternate}"]?pass)
+same => n,UserEvent(Result, Status: failed, ${field} did not match expected value ${expected} or ${expected_alternate} - actual ${actual})
+same => n(pass),NoOp()
+same => n,Return()
+
+exten => test,1,NoOp()
+same => n,Answer()
+
+same => n,GoSub(default,test_variable,1(peerip,${CHANNEL(peerip)},127.0.0.1))
+same => n,GoSub(default,test_variable,1(recvip,${CHANNEL(recvip)},127.0.0.1))
+same => n,GoSub(default,test_variable,1(from,${CHANNEL(from)},sip:test at 127.0.0.1:5061))
+same => n,GoSub(default,test_variable,1(uri,${CHANNEL(uri)},sip:kartoffelsalat at 127.0.0.1:5061))
+same => n,GoSub(default,test_variable,1(useragent,${CHANNEL(useragent)},Channel Param Test))
+same => n,GoSub(default,test_variable,1(peername,${CHANNEL(peername)},test))
+same => n,GoSub(default,test_variable,1(t38passthrough,${CHANNEL(t38passthrough)},0))
+same => n,GoSub(default,test_variable,1(rtpdest\,audio,${CHANNEL(rtpdest,audio)},127.0.0.1:6000))
+same => n,GoSub(default,test_variable,1(rtpdest\,video,${CHANNEL(rtpdest,video)},127.0.0.1:6002))
+same => n,GoSub(default,test_variable,1(rtpsource\,audio,${CHANNEL(rtpsource,audio)},127.0.0.1:10000,127.0.0.1:10002))
+same => n,GoSub(default,test_variable,1(rtpvideo\,audio,${CHANNEL(rtpsource,video)},127.0.0.1:10000,127.0.0.1:10002))
+
+same => n,UserEvent(Result, Status: passed)
+same => n,Hangup()
diff --git a/tests/channels/SIP/sip_channel_params/configs/ast1/sip.conf b/tests/channels/SIP/sip_channel_params/configs/ast1/sip.conf
index f4fa75a..0fe6799 100644
--- a/tests/channels/SIP/sip_channel_params/configs/ast1/sip.conf
+++ b/tests/channels/SIP/sip_channel_params/configs/ast1/sip.conf
@@ -3,11 +3,11 @@
 directmedia=no
 videosupport=yes
 
-[test1]
+[test]
 type=friend
 host=dynamic
 dtmf=rfc2833
-context=channel_test
+context=default
 disallow=all
 allow=ulaw
 allow=h263
diff --git a/tests/channels/SIP/sip_channel_params/run-test b/tests/channels/SIP/sip_channel_params/run-test
deleted file mode 100755
index 1b6319f..0000000
--- a/tests/channels/SIP/sip_channel_params/run-test
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-asttest -a /$AST_TEST_ROOT -s `dirname $0` $@
diff --git a/tests/channels/SIP/sip_channel_params/sipp/call.xml b/tests/channels/SIP/sip_channel_params/sipp/call.xml
index ed1dc20..34cf33f 100644
--- a/tests/channels/SIP/sip_channel_params/sipp/call.xml
+++ b/tests/channels/SIP/sip_channel_params/sipp/call.xml
@@ -7,7 +7,7 @@
 
         INVITE sip:test@[remote_ip]:[remote_port] SIP/2.0
         Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
-        From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
+        From: test1 <sip:test@[local_ip]:[local_port]>;tag=[call_number]
         To: test <sip:test@[remote_ip]:[remote_port]>
         Call-ID: [call_id]
         CSeq: 1 INVITE
@@ -47,7 +47,7 @@
 
         ACK sip:test@[remote_ip]:[remote_port] SIP/2.0
         Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
-        From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
+        From: test1 <sip:test@[local_ip]:[local_port]>;tag=[call_number]
         To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
         Call-ID: [call_id]
         CSeq: 1 ACK
@@ -59,27 +59,7 @@
         ]]>
     </send>
 
-    <!-- Pause long enough for our test to run -->
-    <pause milliseconds="4000" />
-
-    <send retrans="500">
-        <![CDATA[
-
-        BYE sip:test@[remote_ip]:[remote_port] SIP/2.0
-        Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
-        From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
-        To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
-        Call-ID: [call_id]
-        CSeq: 2 BYE
-        Contact: sip:kartoffelsalat@[local_ip]:[local_port]
-        Max-Forwards: 70
-        Subject: Performance Test
-        Content-Length: 0
-
-        ]]>
-    </send>
-
-    <recv response="200" crlf="true" />
+    <recv request="BYE" />
 
     <!-- definition of the response time repartition table (unit is ms)   -->
     <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200" />
diff --git a/tests/channels/SIP/sip_channel_params/sipp/register.xml b/tests/channels/SIP/sip_channel_params/sipp/register.xml
deleted file mode 100644
index 6e43896..0000000
--- a/tests/channels/SIP/sip_channel_params/sipp/register.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<!--
-This scenario will execute a sip register with the given parameters.
--->
-<scenario name="Register">
-    <send retrans="500">
-        <![CDATA[
-
-        REGISTER sip:test1@[remote_ip]:[remote_port] SIP/2.0
-        Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
-        From: test1 <sip:test1@[local_ip]:[local_port]>;tag=[call_number]
-        To: test1 <sip:test1@[remote_ip]:[remote_port]>
-        Call-ID: [call_id]
-        CSeq: 1 REGISTER
-        Contact: sip:test1@[local_ip]:[local_port]
-        Content-Length: 0
-        Expires: 120
-
-        ]]>
-    </send>
-
-    <recv response="100" optional="true" />
-    <recv response="200" />
-</scenario>
diff --git a/tests/channels/SIP/sip_channel_params/test-config.yaml b/tests/channels/SIP/sip_channel_params/test-config.yaml
index 6e43973..fc1b665 100644
--- a/tests/channels/SIP/sip_channel_params/test-config.yaml
+++ b/tests/channels/SIP/sip_channel_params/test-config.yaml
@@ -2,18 +2,51 @@
     summary:     'Test Retrieval of SIP CHANNEL parameters'
     description: |
         "This test places a call to Asterisk using SIPp. Asterisk
-        answers the call and then goes into a Wait() application. During
-        this time, we connect to Asterisk using AMI and request various
-        parameters of the channel that has been created. We ensure that
-        the values of the variables match what we expect them to.
-
-        Note that for now, the minimum version of this test is Asterisk
-        trunk. This is because there are fields referenced in the test
-        which do not exist in other branches of Asterisk."
+        answers the call and then checks the various values on the
+        SIP channel. If all values are as expected a UserEvent of
+        passed is raised. If any values differ from what is expected
+        then a UserEvent of failed is raised. The test is considered
+        failed if the failed UserEvent is seen."
     issues:
         -jira : SWP-1016
         -jira : ABE-2103
 
+test-modules:
+    test-object:
+        config-section: sipp-config
+        typename: 'sipp.SIPpTestCase'
+    modules:
+        -
+            config-section: ami-config
+            typename: 'ami.AMIEventModule'
+
+sipp-config:
+    fail-on-any: True
+    test-iterations:
+        -
+            scenarios:
+                - { 'key-args': {'scenario': 'call.xml', '-i': '127.0.0.1', '-p': '5061'} }
+
+ami-config:
+    -
+        id: '0'
+        type: 'headermatch'
+        count: '1'
+        conditions:
+            match:
+                Event: 'UserEvent'
+        requirements:
+            match:
+                Status: 'passed'
+    -
+        id: '0'
+        type: 'headermatch'
+        count: '0'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                Status: 'failed'
+
 properties:
     minversion: '1.8.0.0'
     dependencies:
diff --git a/tests/channels/SIP/sip_channel_params/test.lua b/tests/channels/SIP/sip_channel_params/test.lua
deleted file mode 100644
index 7a9e656..0000000
--- a/tests/channels/SIP/sip_channel_params/test.lua
+++ /dev/null
@@ -1,144 +0,0 @@
-function sipp_exec(scenario, name, local_port)
-	return proc.exec_io("sipp",
-	"127.0.0.1",
-	"-m", "1",
-	"-sf", scenario,
-	"-i", "127.0.0.1",
-	"-p", local_port,
-	"-timeout", "30",
-	"-trace_err"
-	)
-end
-
-function sipp_exec_and_wait(scenario, name, local_port)
-	return sipp_check_error(sipp_exec(scenario, name, local_port), scenario)
-end
-
-function sipp_check_error(p, scenario)
-	local res, err = p:wait()
-
-	if not res then error(err) end
-	if res ~= 0 then
-		error("error while executing " .. scenario .. " sipp scenario (sipp exited with status " .. res .. ")\n" .. p.stderr:read("*a"))
-	end
-
-	return res, err
-end
-
-function manager_setup(a)
-	m,err = a:manager_connect()
-	if not m then
-		fail("error connecting to asterisk: " .. err)
-	end
-
-	local login = ast.manager.action:new("login")
-	login["Username"] = "asttest"
-	login["Secret"] = "asttest"
-
-	local r = m(login)
-	if not r then
-		fail("error logging in to the manager: " .. err)
-	end
-
-	if r["Response"] ~= "Success" then
-		fail("error authenticating: " .. r["Message"])
-	end
-end
-
-function findpattern(text, pattern, start)
-	return string.sub(text, string.find(text, pattern, start))
-end
-
-function check_sip_params(sip_params, chan_name)
-	for key,value in pairs(sip_params) do
-		local variable = "CHANNEL(" .. key .. ")"
-		local getvar = ast.manager.action:new("GetVar")
-		getvar["Channel"] = chan_name
-		getvar["Variable"] = variable
-		local response, err = m(getvar)
-		if not response then
-			fail("error getting variable " .. key .. ": " .. err)
-			break
-		end
-		if response["Response"] ~= "Success" then
-			fail("Response failure: " .. response["Message"])
-		end
-		if response["Variable"] ~= variable then
-			fail("Wrong variable. Expected " .. variable .. " but got " .. response["Variable"])
-		end
-		--Helpful for debugging in case this test starts failing
-		--print ("Got value " ..  response["Value"] .. " for variable " .. response["Variable"])
-		if not findpattern(response["Value"], value) then
-			fail("Expected " .. value .. " for variable " .. response["Variable"] .. " but got " .. response["Value"])
-		end
-	end
-end
-
-function get_channel_name()
-	local chan_name = nil
-	local function set_name(event)
-		chan_name = event["Channel"]
-	end
-	m:register_event("Newchannel", set_name)
-	local res, err = m:pump_messages()
-	if not res then
-		fail("Error pumping messages: " .. err)
-	end
-	m:process_events()
-	m:unregister_event("Newchannel", set_name)
-	return chan_name
-end
-
-function test_call(scenario, name, local_port, sip_params)
-	local t1 = sipp_exec(scenario, name, local_port)
-	local chan_name = nil
-
-	posix.sleep(1)
-	chan_name = get_channel_name()
-	if not chan_name then
-		fail("Failed to get the name of the channel\n");
-	else
-		print("Got channel name " .. chan_name)
-	end
-	check_sip_params(sip_params, chan_name)
-	-- We have what we want. Let the scenario conclude
-	sipp_check_error(t1, scenario)
-end
-
-function call_and_check_sip_params(name)
-	local a = ast.new()
-	local sip_params = {
-		["peerip"] = "127.0.0.1",
-		["recvip"] = "127.0.0.1",
-		["from"] = "sip:wienerschnitzel at 127.0.0.1:5061",
-		["uri"] = "sip:kartoffelsalat at 127.0.0.1:5061",
-		["useragent"] = "Channel Param Test",
-		["peername"] = "test1",
-		["t38passthrough"] = "0",
-		["rtpdest,audio"] = "127.0.0.1:6000",
-		["rtpdest,video"] = "127.0.0.1:6002",
-		["rtpdest,text"] = "",
-		--We have no way to force a specific source
-		--RTP port to be used; we can specify only a
-		--range. Thus, our rtp.conf file limits the
-		--audio and video RTP ports to a selection of
-		--either 10000 or 10002.
-		["rtpsource,audio"] = "127.0.0.1:1000[02]",
-		["rtpsource,video"] = "127.0.0.1:1000[02]",
-		["rtpsource,text"] = ""
-	}
-
-	a:load_config("configs/ast1/sip.conf")
-	a:load_config("configs/ast1/extensions.conf")
-	a:load_config("configs/ast1/rtp.conf")
-	a:generate_manager_conf()
-	a:spawn()
-
-	manager_setup(a)
-	--register our peer
-	sipp_exec_and_wait("sipp/register.xml", name, "5061")
-
-	test_call("sipp/call.xml", name, "5061", sip_params)
-end
-
-call_and_check_sip_params("test1")

-- 
To view, visit https://gerrit.asterisk.org/1083
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I15ce51ddb9bc72ecab37771414b5ab81c7d44c4d
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Ashley Sanders <asanders at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-code-review mailing list