[asterisk-commits] tests/rest api/events: Add a subscribe to all WebSocket even... (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 23 12:56:58 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: tests/rest_api/events: Add a subscribe to all WebSocket events test
......................................................................


tests/rest_api/events: Add a subscribe to all WebSocket events test

In addition to being able to subscribe to all events manually via the
applications resource, ARI clients can also implicitly subscribe for all events
via the WebSocket connection URI. This test verifies that we receive all
channel and all bridge events when we specify we want all events when creating
the WebSocket for our application.

ASTERISK-24870

Change-Id: I249f43ebf365f2ef7a7648b1ac15d25dfd6f1f12
---
M lib/python/asterisk/ari.py
A tests/rest_api/events/subscribe-ws/configs/ast1/extensions.conf
A tests/rest_api/events/subscribe-ws/test-config.yaml
M tests/rest_api/events/tests.yaml
4 files changed, 237 insertions(+), 2 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/lib/python/asterisk/ari.py b/lib/python/asterisk/ari.py
index 1d97868..762f993 100644
--- a/lib/python/asterisk/ari.py
+++ b/lib/python/asterisk/ari.py
@@ -64,11 +64,13 @@
         port = test_config.get('port', DEFAULT_PORT)
         userpass = (test_config.get('username', 'testsuite'),
                     test_config.get('password', 'testsuite'))
+        subscribe_all = test_config.get('subscribe-all')
 
         # Create the REST interface and the WebSocket Factory
         self.ari = ARI(host, port=port, userpass=userpass)
         self.ari_factory = AriClientFactory(receiver=self, host=host, port=port,
-                                            apps=self.apps, userpass=userpass)
+                                            apps=self.apps, userpass=userpass,
+                                            subscribe_all=subscribe_all)
 
         self._ws_connection = None
         self._ws_event_handlers = []
@@ -312,7 +314,7 @@
     """Twisted protocol factory for building ARI WebSocket clients."""
 
     def __init__(self, receiver, host, apps, userpass, port=DEFAULT_PORT,
-                 timeout_secs=60):
+                 timeout_secs=60, subscribe_all=False):
         """Constructor
 
         :param receiver The object that will receive events from the protocol
@@ -320,10 +322,13 @@
         :param apps: App names to subscribe to.
         :param port: Port of Asterisk web server.
         :param timeout_secs: Maximum time to try to connect to Asterisk.
+        :param subscribe_all: If true, subscribe to all events.
         """
         url = "ws://%s:%d/ari/events?%s" % \
               (host, port,
                urllib.urlencode({'app': apps, 'api_key': '%s:%s' % userpass}))
+        if subscribe_all:
+            url += '&subscribeAll=true'
         LOGGER.info("WebSocketClientFactory(url=%s)", url)
         WebSocketClientFactory.__init__(self, url, debug=True,
                                         protocols=['ari'], debugCodePaths=True)
diff --git a/tests/rest_api/events/subscribe-ws/configs/ast1/extensions.conf b/tests/rest_api/events/subscribe-ws/configs/ast1/extensions.conf
new file mode 100644
index 0000000..9f9823c
--- /dev/null
+++ b/tests/rest_api/events/subscribe-ws/configs/ast1/extensions.conf
@@ -0,0 +1,13 @@
+[default]
+
+exten => echo,1,NoOp()
+ same => n,Echo()
+
+exten => dial_alice,1,NoOp()
+ same => n,Dial(Local/alice at default)
+ same => n,Hangup()
+
+exten => alice,1,NoOp()
+ same => n,Answer()
+ same => n,Wait(1)
+ same => n,Hangup()
diff --git a/tests/rest_api/events/subscribe-ws/test-config.yaml b/tests/rest_api/events/subscribe-ws/test-config.yaml
new file mode 100644
index 0000000..a02a940
--- /dev/null
+++ b/tests/rest_api/events/subscribe-ws/test-config.yaml
@@ -0,0 +1,216 @@
+testinfo:
+    summary: Test subscribing to all resources
+    description: |
+        This test verifies that we can subscribe to
+        all channels, bridges, endpoints, and device
+        states using the applications resource.
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        config-section: test-object-config
+        typename: ari.AriBaseTestObject
+    modules:
+        -
+            config-section: pluggable-config
+            typename: pluggable_modules.EventActionModule
+        -
+            typename: pluggable_modules.ARIHangupMonitor
+
+test-object-config:
+    subscribe-all: True
+
+pluggable-config:
+    -
+        ari-start:
+        ari-requests:
+            -
+                method: 'post'
+                uri: 'channels'
+                params:
+                    endpoint: 'Local/dial_alice at default'
+                    extension: 'echo'
+                expect: 200
+    -
+        # Matching of endpoint and device state subscriptions
+        ari-events:
+            -
+                match:
+                    type: 'DeviceStateChanged'
+                    device_state:
+                        name: 'Local/dial_alice at default'
+                        state: 'INUSE'
+                count: 2
+            -
+                match:
+                    type: 'DeviceStateChanged'
+                    device_state:
+                        name: 'Local/dial_alice at default'
+                        state: 'NOT_INUSE'
+                count: '>1'
+    -
+        # Matching of channel subscription
+        ari-events:
+            -
+                match:
+                    type: 'ChannelCreated'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;1'
+                count: 1
+            -
+                match:
+                    type: 'ChannelCreated'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;2'
+                count: 1
+            -
+                match:
+                    type: 'ChannelCreated'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                count: 1
+            -
+                match:
+                    type: 'ChannelCreated'
+                    channel:
+                        name: 'Local/alice at default-00000001;2'
+                count: 1
+            -
+                match:
+                    type: 'ChannelStateChange'
+                    channel:
+                        name: 'Local/alice at default-00000001;2'
+                        state: 'Up'
+                count: 1
+            -
+                match:
+                    type: 'ChannelStateChange'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                        state: 'Up'
+                count: 1
+            -
+                match:
+                    type: 'ChannelStateChange'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;2'
+                        state: 'Up'
+                count: 1
+            -
+                match:
+                    type: 'ChannelStateChange'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;1'
+                        state: 'Up'
+                count: 1
+            -
+                match:
+                    type: 'ChannelHangupRequest'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                count: 1
+            -
+                match:
+                    type: 'ChannelDestroyed'
+                    channel:
+                        name: 'Local/alice at default-00000001;2'
+                count: 1
+            -
+                match:
+                    type: 'ChannelHangupRequest'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                count: 1
+            -
+                match:
+                    type: 'ChannelDestroyed'
+                    channel:
+                        name: 'Local/alice at default-00000001;2'
+                count: 1
+            -
+                match:
+                    type: 'ChannelDestroyed'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;1'
+                count: 1
+            -
+                match:
+                    type: 'ChannelDestroyed'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;2'
+                count: 1
+    -
+        # Matching of bridge subscription
+        ari-events:
+            -
+                match:
+                    type: 'BridgeCreated'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+            -
+                match:
+                    type: 'ChannelEnteredBridge'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+            -
+                match:
+                    type: 'ChannelEnteredBridge'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;2'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+            -
+                match:
+                    type: 'ChannelLeftBridge'
+                    channel:
+                        name: 'Local/alice at default-00000001;1'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+            -
+                match:
+                    type: 'ChannelLeftBridge'
+                    channel:
+                        name: 'Local/dial_alice at default-00000000;2'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+            -
+                match:
+                    type: 'BridgeDestroyed'
+                    bridge:
+                        technology: 'simple_bridge'
+                        bridge_type: 'mixing'
+                        bridge_class: 'basic'
+                count: 1
+
+
+properties:
+    minversion: '13.7.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : app_echo
+        - asterisk : app_dial
+    tags:
+        - ARI
+
+
diff --git a/tests/rest_api/events/tests.yaml b/tests/rest_api/events/tests.yaml
index 1ec9f2b..2a76822 100644
--- a/tests/rest_api/events/tests.yaml
+++ b/tests/rest_api/events/tests.yaml
@@ -1,3 +1,4 @@
 # Enter tests here in the order they should be considered for execution:
 tests:
+    - test: 'subscribe-ws'
     - dir:  'user'

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I249f43ebf365f2ef7a7648b1ac15d25dfd6f1f12
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list