[Asterisk-code-review] pjsip/ami/pjsip_notify/cli: Added a test for SIP Notify via the CLI (...testsuite[master])

Friendly Automation asteriskteam at digium.com
Tue Jul 23 09:28:19 CDT 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/testsuite/+/11596 )

Change subject: pjsip/ami/pjsip_notify/cli: Added a test for SIP Notify via the CLI
......................................................................

pjsip/ami/pjsip_notify/cli: Added a test for SIP Notify via the CLI

Also added two more pluggable modules to use with the EventAction framework:

  SIPpStartEventModule - Triggers when a SIPp scenario starts
  CLIPluggableActionModule - executes CLI commands

Change-Id: I94312ba52b24020a29f609bbff75198b74475a6f
---
M lib/python/asterisk/asterisk.py
M lib/python/asterisk/sipp.py
A tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip.conf
A tests/channels/pjsip/ami/pjsip_notify/cli/configs/ast1/pjsip_notify.conf
A tests/channels/pjsip/ami/pjsip_notify/cli/sipp/notify.xml
A tests/channels/pjsip/ami/pjsip_notify/cli/test-config.yaml
M tests/channels/pjsip/ami/pjsip_notify/tests.yaml
7 files changed, 181 insertions(+), 0 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



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

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

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Change-Id: I94312ba52b24020a29f609bbff75198b74475a6f
Gerrit-Change-Number: 11596
Gerrit-PatchSet: 3
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190723/acabe707/attachment-0001.html>


More information about the asterisk-code-review mailing list