<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9968">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">agi: add nominal agi test<br><br>This test proves that multiple AGI scripts<br>run in parallel all execute to completion.<br><br>Change-Id: Icb02e66d91e12521638698b3f5e1fd101bae92d1<br>---<br>A tests/agi/nominal/configs/ast1/extensions.conf<br>A tests/agi/nominal/nominal.agi<br>A tests/agi/nominal/run-test<br>A tests/agi/nominal/test-config.yaml<br>M tests/agi/tests.yaml<br>5 files changed, 131 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/agi/nominal/configs/ast1/extensions.conf b/tests/agi/nominal/configs/ast1/extensions.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..29bcdac</span><br><span>--- /dev/null</span><br><span>+++ b/tests/agi/nominal/configs/ast1/extensions.conf</span><br><span>@@ -0,0 +1,8 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[default]</span><br><span style="color: hsl(120, 100%, 40%);">+; ----------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+; Nominal AGI call flow - answer and pass control to agi</span><br><span style="color: hsl(120, 100%, 40%);">+; ----------------------------------------------------------------------</span><br><span style="color: hsl(120, 100%, 40%);">+exten => nominal,1,NoOp()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Answer()</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,AGI(nominal.agi)</span><br><span style="color: hsl(120, 100%, 40%);">+ same => n,Hangup()</span><br><span>diff --git a/tests/agi/nominal/nominal.agi b/tests/agi/nominal/nominal.agi</span><br><span>new file mode 100755</span><br><span>index 0000000..97ff948</span><br><span>--- /dev/null</span><br><span>+++ b/tests/agi/nominal/nominal.agi</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env bash</span><br><span style="color: hsl(120, 100%, 40%);">+# TODO: fully implement AGI and check results of each command</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+echo "EXEC PLAYBACK silence/3"</span><br><span style="color: hsl(120, 100%, 40%);">+echo "EXEC UserEvent AgiCompleted"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+exit 0</span><br><span>diff --git a/tests/agi/nominal/run-test b/tests/agi/nominal/run-test</span><br><span>new file mode 100755</span><br><span>index 0000000..a78fda4</span><br><span>--- /dev/null</span><br><span>+++ b/tests/agi/nominal/run-test</span><br><span>@@ -0,0 +1,99 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env python</span><br><span style="color: hsl(120, 100%, 40%);">+"""</span><br><span style="color: hsl(120, 100%, 40%);">+Copyright (C) 2018, Digium, Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+Scott Griepentrog <scott@griepentrog.com></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This progream is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+the GNU General Public License Version 2.</span><br><span style="color: hsl(120, 100%, 40%);">+"""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import os</span><br><span style="color: hsl(120, 100%, 40%);">+import sys</span><br><span style="color: hsl(120, 100%, 40%);">+import logging</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from twisted.internet import reactor</span><br><span style="color: hsl(120, 100%, 40%);">+from shutil import copy</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+sys.path.append("lib/python")</span><br><span style="color: hsl(120, 100%, 40%);">+from asterisk.test_case import TestCase</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LOGGER = logging.getLogger(__name__)</span><br><span style="color: hsl(120, 100%, 40%);">+PATH = os.path.dirname(os.path.realpath(__file__))</span><br><span style="color: hsl(120, 100%, 40%);">+TEST_CALLS = 10</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class AGITest(TestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ This is the class that contains all the methods needed to run the test.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Initialization for class.</span><br><span style="color: hsl(120, 100%, 40%);">+ call_count keeps track of all successful tests.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.__init__(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.call_count = 0</span><br><span style="color: hsl(120, 100%, 40%);">+ self.reactor_timeout = TEST_CALLS + 10</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_asterisk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Creates the AMI connection with Asterisk.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ TestCase.run(self)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.copy_files()</span><br><span style="color: hsl(120, 100%, 40%);">+ self.create_ami_factory()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def copy_files(self):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Copy agi script files to the path of the current test"""</span><br><span style="color: hsl(120, 100%, 40%);">+ for filename in os.listdir(PATH):</span><br><span style="color: hsl(120, 100%, 40%);">+ if filename[-4:] == '.agi':</span><br><span style="color: hsl(120, 100%, 40%);">+ copy("%s/%s" % (PATH, filename),</span><br><span style="color: hsl(120, 100%, 40%);">+ "%s/var/lib/asterisk/agi-bin/"</span><br><span style="color: hsl(120, 100%, 40%);">+ "%s" % (self.ast[0].base, filename))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def ami_connect(self, ami):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Sets up the AMI for Asterisk.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.registerEvent('UserEvent', self.user_event_handler)</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.info("---Starting AGI nominal test---")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def originate(call):</span><br><span style="color: hsl(120, 100%, 40%);">+ ami.originate(channel="Local/nominal@default",</span><br><span style="color: hsl(120, 100%, 40%);">+ application="Echo"</span><br><span style="color: hsl(120, 100%, 40%);">+ ).addErrback(self.handle_originate_failure)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for call in range(TEST_CALLS):</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.callLater(call, originate, call)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def user_event_handler(self, result, event):</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Checks to see if the AGI script was completed as expected.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ if event['userevent'] != 'AgiCompleted':</span><br><span style="color: hsl(120, 100%, 40%);">+ print event['userevent']</span><br><span style="color: hsl(120, 100%, 40%);">+ return</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.call_count += 1</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.info("Successful AGI: %d " % self.call_count)</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.call_count == TEST_CALLS:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.stop_reactor()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def main():</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ Main method, run by default, determines if test passes or fails.</span><br><span style="color: hsl(120, 100%, 40%);">+ """</span><br><span style="color: hsl(120, 100%, 40%);">+ test = AGITest()</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor.run()</span><br><span style="color: hsl(120, 100%, 40%);">+ if test.call_count != TEST_CALLS:</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGGER.error("The expected amount of calls did not complete. "</span><br><span style="color: hsl(120, 100%, 40%);">+ "Expected successes: %d Actual: "</span><br><span style="color: hsl(120, 100%, 40%);">+ "%d" % (TEST_CALLS, test.call_count))</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == "__main__":</span><br><span style="color: hsl(120, 100%, 40%);">+ sys.exit(main() or 0)</span><br><span>diff --git a/tests/agi/nominal/test-config.yaml b/tests/agi/nominal/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..c476227</span><br><span>--- /dev/null</span><br><span>+++ b/tests/agi/nominal/test-config.yaml</span><br><span>@@ -0,0 +1,16 @@</span><br><span style="color: hsl(120, 100%, 40%);">+testinfo:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test AGI with multiple calls in parallel'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ 'This test checks to make certain that multiple overlapping AGIs are executed'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+properties:</span><br><span style="color: hsl(120, 100%, 40%);">+ dependencies:</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'twisted'</span><br><span style="color: hsl(120, 100%, 40%);">+ - python : 'starpy'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'app_userevent'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'func_cdr'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'func_logic'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'pbx_config'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'res_agi'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - AGI</span><br><span>diff --git a/tests/agi/tests.yaml b/tests/agi/tests.yaml</span><br><span>index 9dc2985..7f831ed 100644</span><br><span>--- a/tests/agi/tests.yaml</span><br><span>+++ b/tests/agi/tests.yaml</span><br><span>@@ -1,3 +1,4 @@</span><br><span> # Enter tests here in the order they should be considered for execution:</span><br><span> tests:</span><br><span> - test: 'exit_status'</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'nominal'</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9968">change 9968</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9968"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Icb02e66d91e12521638698b3f5e1fd101bae92d1 </div>
<div style="display:none"> Gerrit-Change-Number: 9968 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Scott Griepentrog <scott@griepentrog.com> </div>