[asterisk-commits] mmichelson: testsuite/asterisk/trunk r4783 - in /asterisk/trunk: lib/python/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 4 16:24:03 CST 2014


Author: mmichelson
Date: Tue Mar  4 16:23:56 2014
New Revision: 4783

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4783
Log:
Add a test for MWI state aggregation.

Tests that the mwi_aggregate option works as expected for PJSIP endpoints.
This is done by having two configured PJSIP endpoints: one that aggregates
MWI state and one that does not. Two mailboxes have their states updated. We
ensure that the mailbox counts reported to the endpoints are what we would
expect them to be.

Review: https://reviewboard.asterisk.org/r/3238


Added:
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf   (with props)
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf   (with props)
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py   (with props)
    asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml   (with props)
    asterisk/trunk/tests/channels/pjsip/mwi_sol_unsol/
Modified:
    asterisk/trunk/lib/python/asterisk/pjsua_mod.py
    asterisk/trunk/tests/channels/pjsip/tests.yaml

Modified: asterisk/trunk/lib/python/asterisk/pjsua_mod.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/pjsua_mod.py?view=diff&rev=4783&r1=4782&r2=4783
==============================================================================
--- asterisk/trunk/lib/python/asterisk/pjsua_mod.py (original)
+++ asterisk/trunk/lib/python/asterisk/pjsua_mod.py Tue Mar  4 16:23:56 2014
@@ -57,15 +57,7 @@
 
         if status >= 200 and status < 300:
             LOGGER.info("Detected successful registration from %s" % uri)
-            self.test_plugin.num_regs += 1
-
-        if self.test_plugin.num_regs == self.test_plugin.num_accts:
-            callback_module = __import__(self.test_plugin.callback_module)
-            callback_method = getattr(callback_module,
-                                      self.test_plugin.callback_method)
-            reactor.callFromThread(callback_method,
-                                   self.test_plugin.test_object,
-                                   self.test_plugin.pj_accounts)
+            reactor.callFromThread(self.test_plugin.reg_success)
 
 
 class PJsuaAccount(object):
@@ -121,7 +113,6 @@
         self.num_regs = 0
         self.num_accts = 0
         self.ami = None
-        self.acct_cb = RegDetector(self)
         self.callback_module = instance_config['callback_module']
         self.callback_method = instance_config['callback_method']
 
@@ -224,7 +215,7 @@
 
         LOGGER.info("Creating PJSUA account %s@%s" % (username, domain))
         account = PJsuaAccount(self.lib.create_account(pj_acct_cfg, False,
-                                                       self.acct_cb))
+                                                       RegDetector(self)))
         account.add_buddies(acct_cfg.get('buddies', []))
         return account
 
@@ -247,3 +238,10 @@
                 LOGGER.error("Account configuration has no name")
                 self.test_object.stop_reactor()
             self.pj_accounts[name] = self.__create_account(acct)
+
+    def reg_success(self):
+        self.num_regs += 1
+        if self.num_regs == self.num_accts:
+            callback_module = __import__(self.callback_module)
+            callback_method = getattr(callback_module, self.callback_method)
+            callback_method(self.test_object, self.pj_accounts)

Added: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf?view=auto&rev=4783
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf (added)
+++ asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf Tue Mar  4 16:23:56 2014
@@ -1,0 +1,9 @@
+[modules]
+autoload=yes
+
+noload => chan_alsa.so
+noload => chan_oss.so
+noload => chan_console.so
+noload => chan_sip.so
+
+noload => app_voicemail.so

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/modules.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf?view=auto&rev=4783
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf (added)
+++ asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf Tue Mar  4 16:23:56 2014
@@ -1,0 +1,31 @@
+[globals]
+type=global
+debug=yes
+
+[local-transport]
+type=transport
+bind=127.0.0.1
+protocol=udp
+
+[alice]
+type=endpoint
+allow=g722,ulaw,alaw
+context=default
+aors=alice
+mailboxes=mailbox_a,mailbox_b
+
+[alice]
+type=aor
+max_contacts=5
+
+[bob]
+type=endpoint
+allow=g722,ulaw,alaw
+context=default
+aors=bob
+mailboxes=mailbox_a,mailbox_b
+aggregate_mwi=no
+
+[bob]
+type=aor
+max_contacts=5

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/configs/ast1/pjsip.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py?view=auto&rev=4783
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py (added)
+++ asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py Tue Mar  4 16:23:56 2014
@@ -1,0 +1,108 @@
+#!/usr/bin/env python
+
+import sys
+import logging
+import pjsua as pj
+
+sys.path.append("lib/python")
+
+from twisted.internet import reactor
+
+LOGGER = logging.getLogger(__name__)
+
+ALICE_RESULTS = [
+    {'waiting': 'yes', 'msgs': '2/1'},
+    {'waiting': 'yes', 'msgs': '5/4'},
+]
+
+BOB_RESULTS = [
+    {'waiting': 'yes', 'msgs': '2/1'},
+    {'waiting': 'yes', 'msgs': '3/3'},
+]
+
+class PJMWICallback(pj.AccountCallback):
+    def __init__(self, account, results, controller):
+        pj.AccountCallback.__init__(self, account)
+        self.result_pos = 0
+        self.results = results
+        self.controller = controller
+        self.checked_in = False
+
+    def check_mwi(self, body):
+        waiting = "Messages-Waiting: %s\r\n" % \
+            self.results[self.result_pos]['waiting']
+
+        msgs = "Voice-Message: %s (0/0)\r\n" % \
+            self.results[self.result_pos]['msgs']
+
+        if not waiting in body:
+            LOGGER.error("Could not find pattern %s in MWI body %s" %
+                         (waiting, body))
+            controller.fail_test()
+        if not msgs in body:
+            LOGGER.error("Could not find pattern %s in MWI body %s" %
+                         (msgs, body))
+            controller.fail_test()
+            self.test_object.set_passed(False)
+            self.test_object.stop_reactor()
+
+        self.result_pos += 1
+
+    def on_mwi_info(self, body):
+        self.check_mwi(body)
+        self.controller.next_mwi(self)
+
+
+class MWICallback(object):
+    def __init__(self, test_object, accounts):
+        self.mwis = [
+            {'mailbox': 'mailbox_a', 'new': '2', 'old': '1'},
+            {'mailbox': 'mailbox_b', 'new': '3', 'old': '3'},
+        ]
+        self.pos = 0
+        self.ami = test_object.ami[0]
+        self.test_object = test_object
+
+        alice = accounts.get('alice')
+        self.alice_cb = PJMWICallback(alice, ALICE_RESULTS, self)
+        alice.account.set_callback(self.alice_cb)
+        bob = accounts.get('bob')
+        self.bob_cb = PJMWICallback(bob, BOB_RESULTS, self)
+        bob.account.set_callback(self.bob_cb)
+
+    def next_mwi(self, account):
+        reactor.callFromThread(self._next_mwi_reactor, account);
+
+    def _next_mwi_reactor(self, account):
+        account.checked_in = True
+        if self.alice_cb.checked_in and self.bob_cb.checked_in:
+            self.send_mwi()
+
+    def send_mwi(self):
+        if self.pos >= len(self.mwis):
+            self.test_object.set_passed(True)
+            self.test_object.stop_reactor()
+            return
+
+        self.alice_cb.checked_in = False
+        self.bob_cb.checked_in = False
+
+        LOGGER.info("Sending MWI update. new: %s, old %s" %
+                    (self.mwis[self.pos]['new'],
+                     self.mwis[self.pos]['old']))
+        message = {
+            'Action': 'MWIUpdate',
+            'Mailbox': self.mwis[self.pos]['mailbox'],
+            'NewMessages': self.mwis[self.pos]['new'],
+            'OldMessages': self.mwis[self.pos]['old']
+        }
+        self.pos += 1
+        self.ami.sendMessage(message)
+
+    def fail_test(self):
+        self.test_object.set_passed(False)
+        self.test_object.stop_reactor()
+
+def mwi_callback(test_object, accounts):
+    cb = MWICallback(test_object, accounts)
+    cb.send_mwi()

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/mwi_check.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml?view=auto&rev=4783
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml (added)
+++ asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml Tue Mar  4 16:23:56 2014
@@ -1,0 +1,58 @@
+testinfo:
+    summary:     'Ensures mailbox state is aggregated or not aggregated when appropriate'
+    description: |
+        "Alice and Bob both receive mailbox updates for mailbox_a and mailbox_b. However, Alice
+        receives the aggregated state of both mailboxes and Bob receives individual mailbox notifications
+        that are not aggregated. The test consists of first changing the state of mailbox_a so that it has
+        2 new messages and 1 old message. Alice and Bob should each receive the same MWI update. Next,
+        mailbox_b is updated to have 3 new messages and 3 old messages. Alice should receive an MWI
+        notification with the combined mailbox state (5 new messages, 4 old messages) and Bob should
+        receive an MWI notification with just the new mailbox state (3 new messages, 3 old messages)."
+
+
+properties:
+    minversion: '12.0.0'
+    dependencies:
+        - python: 'twisted'
+        - python: 'starpy'
+        - python: 'pjsua'
+        - asterisk: 'res_pjsip'
+        - asterisk: 'res_pjsip_mwi'
+        - asterisk: 'res_mwi_external'
+        - asterisk: 'res_mwi_external_ami'
+    tags:
+        - pjsip
+        - mwi_external
+
+test-modules:
+    add-test-to-search-path: 'True'
+    test-object:
+        config-section: test-case-config
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            config-section: 'pjsua-config'
+            typename: 'pjsua_mod.PJsua'
+
+test-case-config:
+    connect-ami: 'True'
+
+pjsua-config:
+    callback_module: 'mwi_check'
+    callback_method: 'mwi_callback'
+    transports:
+        -
+            name: 'local-ipv4'
+            bind: '127.0.0.1'
+            bindport: '5061'
+    accounts:
+        -
+            name: 'alice'
+            username: 'alice'
+            password: 'alice'
+            domain: '127.0.0.1'
+        -
+            name: 'bob'
+            username: 'bob'
+            password: 'bob'
+            domain: '127.0.0.1'

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/pjsip/mwi_aggregate/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/channels/pjsip/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/tests.yaml?view=diff&rev=4783&r1=4782&r2=4783
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/tests.yaml (original)
+++ asterisk/trunk/tests/channels/pjsip/tests.yaml Tue Mar  4 16:23:56 2014
@@ -18,4 +18,5 @@
     - test: 'presence_pidf'
     - test: 'presence_xpidf'
     - test: 'mwi'
+    - test: 'mwi_aggregate'
     - test: 'refer_send_to_vm'




More information about the asterisk-commits mailing list