<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/testsuite/+/11598">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip/ami/pjsip_notify/cli: Added a test for SIP Notify via the CLI<br><br>Also added two more pluggable modules to use with the EventAction framework:<br><br> SIPpStartEventModule - Triggers when a SIPp scenario starts<br> CLIPluggableActionModule - executes CLI commands<br><br>Change-Id: I94312ba52b24020a29f609bbff75198b74475a6f<br>---<br>M lib/python/asterisk/asterisk.py<br>M lib/python/asterisk/sipp.py<br>A tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip.conf<br>A tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip_notify.conf<br>A tests/channels/pjsip/ami/pjsip_notify/cli/sipp/notify.xml<br>A tests/channels/pjsip/ami/pjsip_notify/cli/test-config.yaml<br>M tests/channels/pjsip/ami/pjsip_notify/tests.yaml<br>7 files changed, 181 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/lib/python/asterisk/asterisk.py b/lib/python/asterisk/asterisk.py</span><br><span>index 131a0ab..d9bb0d9 100644</span><br><span>--- a/lib/python/asterisk/asterisk.py</span><br><span>+++ b/lib/python/asterisk/asterisk.py</span><br><span>@@ -37,6 +37,9 @@</span><br><span> # things if we don't need the SSH connection to a remote Asterisk instance</span><br><span> REMOTE_ERROR = ie</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+from .pluggable_registry import PLUGGABLE_EVENT_REGISTRY,\</span><br><span style="color: hsl(120, 100%, 40%);">+ PLUGGABLE_ACTION_REGISTRY, var_replace</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span> LOGGER = logging.getLogger(__name__)</span><br><span> </span><br><span>@@ -1071,4 +1074,35 @@</span><br><span> self._makedirs(os.path.join(target_dir, short_dirname, dirname))</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+class CLIPluggableActionModule(object):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Pluggable CLI action module.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ Options:</span><br><span style="color: hsl(120, 100%, 40%);">+ id - The Asterisk id to execute the command on. This is optional and,</span><br><span style="color: hsl(120, 100%, 40%);">+ if not specified defaults to 0 (ast1).</span><br><span style="color: hsl(120, 100%, 40%);">+ cmd - The CLI command to execute</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 __init__(self, test_object, config):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Setup the CLI event observer"""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_object = test_object</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if not isinstance(config, list):</span><br><span style="color: hsl(120, 100%, 40%);">+ config = [config]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.cmds = config</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def run(self, triggered_by, source, extra):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Callback called when this action is triggered."""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for cmd in self.cmds:</span><br><span style="color: hsl(120, 100%, 40%);">+ text = cmd.get('cmd')</span><br><span style="color: hsl(120, 100%, 40%);">+ if text:</span><br><span style="color: hsl(120, 100%, 40%);">+ instance = cmd.get('id', 0)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_object.ast[instance].cli_exec(text)</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%);">+PLUGGABLE_ACTION_REGISTRY.register("cli-cmds", CLIPluggableActionModule)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> # vim: set ts=8 sw=4 sts=4 et ai tw=79:</span><br><span>diff --git a/lib/python/asterisk/sipp.py b/lib/python/asterisk/sipp.py</span><br><span>index 200cac6..1341132 100644</span><br><span>--- a/lib/python/asterisk/sipp.py</span><br><span>+++ b/lib/python/asterisk/sipp.py</span><br><span>@@ -16,6 +16,9 @@</span><br><span> from twisted.internet import reactor, defer, protocol, error</span><br><span> from .test_case import TestCase</span><br><span> from .utils_socket import get_available_port</span><br><span style="color: hsl(120, 100%, 40%);">+from .pluggable_registry import PLUGGABLE_EVENT_REGISTRY,\</span><br><span style="color: hsl(120, 100%, 40%);">+ PLUGGABLE_ACTION_REGISTRY, var_replace</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span> LOGGER = logging.getLogger(__name__)</span><br><span> </span><br><span>@@ -920,3 +923,42 @@</span><br><span> deferds.append(deferred)</span><br><span> </span><br><span> defer.DeferredList(deferds).addCallback(__set_pass_fail)</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 SIPpStartEventModule(object):</span><br><span style="color: hsl(120, 100%, 40%);">+ """An event module that triggers when SIPp scenario(s) starts.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ Optional options:</span><br><span style="color: hsl(120, 100%, 40%);">+ count - trigger event after 'count' scenarios</span><br><span style="color: hsl(120, 100%, 40%);">+ name - trigger event after matching 'name' to a scenario's name</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ If no options are specified then this event is triggered once the first</span><br><span style="color: hsl(120, 100%, 40%);">+ scenario has been started. If both options are set then the event is</span><br><span style="color: hsl(120, 100%, 40%);">+ triggered when 'count' scenarios named 'name' have started.</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 __init__(self, test_object, triggered_callback, config):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Setup the test start observer"""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if not isinstance(test_object, SIPpTestCase):</span><br><span style="color: hsl(120, 100%, 40%);">+ raise TypeError("Test case must be of type SIPpTestCase")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.test_object = test_object</span><br><span style="color: hsl(120, 100%, 40%);">+ self.triggered_callback = triggered_callback</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ self.count = config and config.get('count', 0) or 0</span><br><span style="color: hsl(120, 100%, 40%);">+ self.name = config and config.get('name') or None</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ test_object.register_scenario_started_observer(self.handle_start)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def handle_start(self, scenario):</span><br><span style="color: hsl(120, 100%, 40%);">+ """Notify the event-action mapper that the test has started."""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.count > 0:</span><br><span style="color: hsl(120, 100%, 40%);">+ self.count -= 1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if self.count == 0 and (not self.name or self.name == scenario.name):</span><br><span style="color: hsl(120, 100%, 40%);">+ self.triggered_callback(self, scenario)</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%);">+PLUGGABLE_EVENT_REGISTRY.register("sipp-start", SIPpStartEventModule)</span><br><span>diff --git a/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip.conf b/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..017933d</span><br><span>--- /dev/null</span><br><span>+++ b/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip.conf</span><br><span>@@ -0,0 +1,24 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[global]</span><br><span style="color: hsl(120, 100%, 40%);">+debug=yes</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[transport-template](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=transport</span><br><span style="color: hsl(120, 100%, 40%);">+bind=127.0.0.1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[transport-udp](transport-template)</span><br><span style="color: hsl(120, 100%, 40%);">+protocol=udp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[aor-template](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=aor</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[endpoint-template](!)</span><br><span style="color: hsl(120, 100%, 40%);">+type=endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+context=default</span><br><span style="color: hsl(120, 100%, 40%);">+direct_media=false</span><br><span style="color: hsl(120, 100%, 40%);">+allow=!all,ulaw</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[alice](aor-template)</span><br><span style="color: hsl(120, 100%, 40%);">+contact=sip:alice@127.0.0.1:5061</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[alice](endpoint-template)</span><br><span style="color: hsl(120, 100%, 40%);">+aors=alice</span><br><span>diff --git a/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip_notify.conf b/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip_notify.conf</span><br><span>new file mode 100644</span><br><span>index 0000000..a940fcd</span><br><span>--- /dev/null</span><br><span>+++ b/tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip_notify.conf</span><br><span>@@ -0,0 +1,8 @@</span><br><span style="color: hsl(120, 100%, 40%);">+[test]</span><br><span style="color: hsl(120, 100%, 40%);">+Event=>message-summary</span><br><span style="color: hsl(120, 100%, 40%);">+Content-Type=lettuce/varieties</span><br><span style="color: hsl(120, 100%, 40%);">+Content=Bibb</span><br><span style="color: hsl(120, 100%, 40%);">+Content=Boston</span><br><span style="color: hsl(120, 100%, 40%);">+Content=Iceberg</span><br><span style="color: hsl(120, 100%, 40%);">+Content=Romaine</span><br><span style="color: hsl(120, 100%, 40%);">+Content=></span><br><span>diff --git a/tests/channels/pjsip/ami/pjsip_notify/cli/sipp/notify.xml b/tests/channels/pjsip/ami/pjsip_notify/cli/sipp/notify.xml</span><br><span>new file mode 100644</span><br><span>index 0000000..4551bcf</span><br><span>--- /dev/null</span><br><span>+++ b/tests/channels/pjsip/ami/pjsip_notify/cli/sipp/notify.xml</span><br><span>@@ -0,0 +1,37 @@</span><br><span style="color: hsl(120, 100%, 40%);">+<?xml version="1.0" encoding="ISO-8859-1" ?></span><br><span style="color: hsl(120, 100%, 40%);">+<!DOCTYPE scenario SYSTEM "sipp.dtd"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+<scenario name="Notify Request"></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <recv request="NOTIFY"></span><br><span style="color: hsl(120, 100%, 40%);">+ <action></span><br><span style="color: hsl(120, 100%, 40%);">+ <ereg regexp=": lettuce/varieties"</span><br><span style="color: hsl(120, 100%, 40%);">+ search_in="hdr"</span><br><span style="color: hsl(120, 100%, 40%);">+ header="Content-Type"</span><br><span style="color: hsl(120, 100%, 40%);">+ check_it="true"</span><br><span style="color: hsl(120, 100%, 40%);">+ assign_to="1"/></span><br><span style="color: hsl(120, 100%, 40%);">+ <log message="Received NOTIFY [$1]." /></span><br><span style="color: hsl(120, 100%, 40%);">+ <ereg regexp="Bibb\r\nBoston\r\nIceberg\r\nRomaine"</span><br><span style="color: hsl(120, 100%, 40%);">+ search_in="body"</span><br><span style="color: hsl(120, 100%, 40%);">+ check_it="true"</span><br><span style="color: hsl(120, 100%, 40%);">+ assign_to="2"/></span><br><span style="color: hsl(120, 100%, 40%);">+ <log message="Received NOTIFY [$2]." /></span><br><span style="color: hsl(120, 100%, 40%);">+ </action></span><br><span style="color: hsl(120, 100%, 40%);">+ </recv></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ <send></span><br><span style="color: hsl(120, 100%, 40%);">+ <![CDATA[</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP/2.0 200 OK</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Via:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_From:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_To:];tag=[pid]SIPpTag[call_number]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_Call-ID:]</span><br><span style="color: hsl(120, 100%, 40%);">+ [last_CSeq:]</span><br><span style="color: hsl(120, 100%, 40%);">+ Contact: <sip:user1@[local_ip]:[local_port];transport=[transport]></span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Type: application/sdp</span><br><span style="color: hsl(120, 100%, 40%);">+ Content-Length: [len]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]]></span><br><span style="color: hsl(120, 100%, 40%);">+ </send></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</scenario></span><br><span>diff --git a/tests/channels/pjsip/ami/pjsip_notify/cli/test-config.yaml b/tests/channels/pjsip/ami/pjsip_notify/cli/test-config.yaml</span><br><span>new file mode 100644</span><br><span>index 0000000..e533b85</span><br><span>--- /dev/null</span><br><span>+++ b/tests/channels/pjsip/ami/pjsip_notify/cli/test-config.yaml</span><br><span>@@ -0,0 +1,35 @@</span><br><span style="color: hsl(120, 100%, 40%);">+info:</span><br><span style="color: hsl(120, 100%, 40%);">+ summary: 'Test pjsip send notify CLI command'</span><br><span style="color: hsl(120, 100%, 40%);">+ description: |</span><br><span style="color: hsl(120, 100%, 40%);">+ This Tests the 'pjsip send notify' command in order to make sure the</span><br><span style="color: hsl(120, 100%, 40%);">+ notify is properly formed and sent.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+test-modules:</span><br><span style="color: hsl(120, 100%, 40%);">+ test-object:</span><br><span style="color: hsl(120, 100%, 40%);">+ config-section: test-config</span><br><span style="color: hsl(120, 100%, 40%);">+ typename: 'sipp.SIPpTestCase'</span><br><span style="color: hsl(120, 100%, 40%);">+ modules:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ config-section: event-action-config</span><br><span style="color: hsl(120, 100%, 40%);">+ typename: 'pluggable_modules.EventActionModule'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+test-config:</span><br><span style="color: hsl(120, 100%, 40%);">+ reactor-timeout: 15</span><br><span style="color: hsl(120, 100%, 40%);">+ test-iterations:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ scenarios:</span><br><span style="color: hsl(120, 100%, 40%);">+ - { 'key-args': {'scenario': 'notify.xml', '-p': '5061'} }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+event-action-config:</span><br><span style="color: hsl(120, 100%, 40%);">+ -</span><br><span style="color: hsl(120, 100%, 40%);">+ sipp-start:</span><br><span style="color: hsl(120, 100%, 40%);">+ cli-cmds:</span><br><span style="color: hsl(120, 100%, 40%);">+ cmd: "pjsip send notify test endpoint alice"</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%);">+ - sipp :</span><br><span style="color: hsl(120, 100%, 40%);">+ version : 'v3.0'</span><br><span style="color: hsl(120, 100%, 40%);">+ - asterisk : 'res_pjsip'</span><br><span style="color: hsl(120, 100%, 40%);">+ tags:</span><br><span style="color: hsl(120, 100%, 40%);">+ - pjsip</span><br><span>diff --git a/tests/channels/pjsip/ami/pjsip_notify/tests.yaml b/tests/channels/pjsip/ami/pjsip_notify/tests.yaml</span><br><span>index 2bb7308..f8dd140 100644</span><br><span>--- a/tests/channels/pjsip/ami/pjsip_notify/tests.yaml</span><br><span>+++ b/tests/channels/pjsip/ami/pjsip_notify/tests.yaml</span><br><span>@@ -1,5 +1,6 @@</span><br><span> # Enter tests here in the order they should be considered for execution:</span><br><span> tests:</span><br><span style="color: hsl(120, 100%, 40%);">+ - test: 'cli'</span><br><span> - test: 'custom_headers'</span><br><span> - test: 'reserved_headers'</span><br><span> - test: 'content'</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/testsuite/+/11598">change 11598</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/c/testsuite/+/11598"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I94312ba52b24020a29f609bbff75198b74475a6f </div>
<div style="display:none"> Gerrit-Change-Number: 11598 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>