[svn-commits] mjordan: testsuite/asterisk/trunk r6033 - in /asterisk/trunk/tests/channels/p...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Dec 6 19:44:52 CST 2014


Author: mjordan
Date: Sat Dec  6 19:44:46 2014
New Revision: 6033

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=6033
Log:
channels/pjsip/transfers/blind_transfer: Fix refer only premature transfer

The callee_refer_only|caller_refer_only tests use PJSUA Python bindings to
initiate a blind transfer of the opposing party. Prior to this patch, the
test would initiate a transfer when it detected that the initiator of the
transfer was up and in a call. However, this does not always mean that the
party is ready to initiate the transfer: in the case of the callee, they
will be answered prior to the caller; in the case of the caller, they may
be answered but not fully in the bridge.

This patch makes it so that the initiator of the transfer does not perform
their action until we receive BridgeEnter events for both of the original
parties. This prevents the Blind Transfer from failing due to not having
the initiator in a bridge with another party.

ASTERISK-24574
Reported by: Joshau Colp

Modified:
    asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/callee_refer_only/transfer.py
    asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/caller_refer_only/transfer.py

Modified: asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/callee_refer_only/transfer.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/callee_refer_only/transfer.py?view=diff&rev=6033&r1=6032&r2=6033
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/callee_refer_only/transfer.py (original)
+++ asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/callee_refer_only/transfer.py Sat Dec  6 19:44:46 2014
@@ -15,6 +15,7 @@
 URI = ["sip:bob at 127.0.0.1", "sip:bob_two at 127.0.0.1", "sip:charlie at 127.0.0.1"]
 ITERATION = 0
 
+
 class CharlieCallback(pj.AccountCallback):
     """Derived callback class for Charlie's account."""
 
@@ -26,11 +27,12 @@
     def on_incoming_call2(self, call, msg):
         self.charlie_call = call
         LOGGER.info("Incoming call for Charlie '%s' from '%s'." %
-                (call.info().uri, call.info().remote_uri))
+                    (call.info().uri, call.info().remote_uri))
         if ITERATION > 0:
             referred_by_hdr = "Referred-By: <sip:bob at 127.0.0.1;ob>"
             if (referred_by_hdr not in msg.msg_info_buffer):
-                LOGGER.warn("Expected header not found: '%s'" % referred_by_hdr)
+                LOGGER.warn("Expected header not found: '%s'" %
+                            referred_by_hdr)
                 self.controller.test_object.set_passed(False)
                 self.controller.test_object.stop_reactor()
 
@@ -44,20 +46,23 @@
         LOGGER.info("Hanging up Charlie")
         self.charlie_call.hangup(code=200, reason="Q.850;cause=16")
 
+
 class BobCallback(pj.AccountCallback):
     """Derived callback class for Bob's account."""
 
     def __init__(self, account=None):
         pj.AccountCallback.__init__(self, account)
         self.bob_call = None
+        self.bob_phone_call = None
 
     def on_incoming_call(self, call):
         self.bob_call = call
         LOGGER.info("Incoming call for Bob '%s' from '%s'." %
-                (call.info().uri, call.info().remote_uri))
-        inbound_cb = BobPhoneCallCallback(call)
-        call.set_callback(inbound_cb)
+                    (call.info().uri, call.info().remote_uri))
+        self.bob_phone_call = BobPhoneCallCallback(call)
+        call.set_callback(self.bob_phone_call)
         call.answer(200)
+
 
 class AlicePhoneCallCallback(pj.CallCallback):
     """Derived callback class for Alice's call."""
@@ -70,6 +75,7 @@
         if self.call.info().state == pj.CallState.DISCONNECTED:
             LOGGER.info("Call disconnected: '%s'" % self.call)
 
+
 class BobPhoneCallCallback(pj.CallCallback):
     """Derived callback class for Bob's call."""
 
@@ -79,9 +85,7 @@
     def on_state(self):
         log_call_info(self.call.info())
         if self.call.info().state == pj.CallState.CONFIRMED:
-            LOGGER.info("Call is up between Alice and Bob. Transferring call" \
-                    " to Charlie.")
-            self.transfer_call()
+            LOGGER.info("Call is up: '%s'." % self.call)
         if self.call.info().state == pj.CallState.DISCONNECTED:
             LOGGER.info("Call disconnected: '%s'" % self.call)
 
@@ -100,11 +104,13 @@
         if code == 200 and reason == "OK" and final == 1 and cont == 0:
             LOGGER.info("Transfer target answered the call.")
             LOGGER.debug("Call uri: '%s'; remote uri: '%s'" %
-                    (self.call.info().uri, self.call.info().remote_uri))
+                         (self.call.info().uri,
+                          self.call.info().remote_uri))
             LOGGER.info("Hanging up Bob")
             self.call.hangup(code=200, reason="Q.850;cause=16")
         return cont
 
+
 class CharliePhoneCallCallback(pj.CallCallback):
     """Derived callback class for Charlie's call."""
 
@@ -115,6 +121,7 @@
         log_call_info(self.call.info())
         if self.call.info().state == pj.CallState.DISCONNECTED:
             LOGGER.info("Call disconnected: '%s'" % self.call)
+
 
 class AMICallback(object):
     """Class to set up callbacks and place calls."""
@@ -123,6 +130,8 @@
         self.test_object = test_object
         self.ami = self.test_object.ami[0]
         self.ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.ami.registerEvent('BridgeEnter', self.bridge_enter_handler)
+        self.ami.registerEvent('BridgeLeave', self.bridge_leave_handler)
         self.alice = accounts.get('alice')
         bob = accounts.get('bob')
         charlie = accounts.get('charlie')
@@ -131,6 +140,27 @@
         bob.account.set_callback(self.bob_cb)
         charlie.account.set_callback(self.charlie_cb)
         self.channels_hungup = 0
+        self.alice_in_bridge = False
+        self.bob_in_bridge = False
+
+    def bridge_enter_handler(self, ami, event):
+        """AMI bridge enter event callback."""
+        channel = event.get('channel')
+        if 'bob' in channel:
+            self.bob_in_bridge = True
+        elif 'alice' in channel:
+            self.alice_in_bridge = True
+        if self.bob_in_bridge and self.alice_in_bridge:
+            LOGGER.info('Both Alice and Bob are in bridge; starting transfer')
+            self.bob_cb.bob_phone_call.transfer_call()
+
+    def bridge_leave_handler(self, ami, event):
+        """AMI bridge leave event callback."""
+        channel = event.get('channel')
+        if 'bob' in channel:
+            self.bob_in_bridge = False
+        elif 'alice' in channel:
+            self.alice_in_bridge = False
 
     def hangup_event_handler(self, ami, event):
         """AMI hang up event callback."""
@@ -165,7 +195,10 @@
     """Log call info."""
     LOGGER.debug("Call '%s' <-> '%s'" % (call_info.uri, call_info.remote_uri))
     LOGGER.debug("Call state: '%s'; last code: '%s'; last reason: '%s'" %
-            (call_info.state_text, call_info.last_code, call_info.last_reason))
+                 (call_info.state_text,
+                  call_info.last_code,
+                  call_info.last_reason))
+
 
 def transfer(test_object, accounts):
     """The test's callback method.

Modified: asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/caller_refer_only/transfer.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/caller_refer_only/transfer.py?view=diff&rev=6033&r1=6032&r2=6033
==============================================================================
--- asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/caller_refer_only/transfer.py (original)
+++ asterisk/trunk/tests/channels/pjsip/transfers/blind_transfer/caller_refer_only/transfer.py Sat Dec  6 19:44:46 2014
@@ -15,6 +15,7 @@
 URI = ["sip:bob at 127.0.0.1", "sip:bob_two at 127.0.0.1", "sip:charlie at 127.0.0.1"]
 ITERATION = 0
 
+
 class CharlieCallback(pj.AccountCallback):
     """Derived callback class for Charlie's account."""
 
@@ -26,11 +27,13 @@
     def on_incoming_call2(self, call, msg):
         self.charlie_call = call
         LOGGER.info("Incoming call for Charlie '%s' from '%s'." %
-                (call.info().uri, call.info().remote_uri))
+                    (call.info().uri,
+                     call.info().remote_uri))
         if ITERATION > 0:
             referred_by_hdr = "Referred-By: alice <sip:alice at 127.0.0.1>"
             if (referred_by_hdr not in msg.msg_info_buffer):
-                LOGGER.warn("Expected header not found: '%s'" % referred_by_hdr)
+                LOGGER.warn("Expected header not found: '%s'" %
+                            referred_by_hdr)
                 self.controller.test_object.set_passed(False)
                 self.controller.test_object.stop_reactor()
 
@@ -55,7 +58,8 @@
     def on_incoming_call(self, call):
         self.bob_call = call
         LOGGER.info("Incoming call for Bob '%s' from '%s'." %
-                (call.info().uri, call.info().remote_uri))
+                    (call.info().uri,
+                     call.info().remote_uri))
         inbound_cb = BobPhoneCallCallback(call)
         call.set_callback(inbound_cb)
         call.answer(200)
@@ -70,9 +74,7 @@
     def on_state(self):
         log_call_info(self.call.info())
         if self.call.info().state == pj.CallState.CONFIRMED:
-            LOGGER.info("Call is up between Alice and Bob. Transferring call" \
-                    " to Charlie.")
-            self.transfer_call()
+            LOGGER.info("Call is up: '%s'" % self.call)
         if self.call.info().state == pj.CallState.DISCONNECTED:
             LOGGER.info("Call disconnected: '%s'" % self.call)
 
@@ -90,7 +92,8 @@
         if code == 200 and reason == "OK" and final == 1 and cont == 0:
             LOGGER.info("Transfer target answered the call.")
             LOGGER.debug("Call uri: '%s'; remote uri: '%s'" %
-                    (self.call.info().uri, self.call.info().remote_uri))
+                         (self.call.info().uri,
+                          self.call.info().remote_uri))
             LOGGER.info("Hanging up Alice")
             self.call.hangup(code=200, reason="Q.850;cause=16")
         return cont
@@ -127,6 +130,8 @@
         self.test_object = test_object
         self.ami = self.test_object.ami[0]
         self.ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.ami.registerEvent('BridgeEnter', self.bridge_enter_handler)
+        self.ami.registerEvent('BridgeLeave', self.bridge_leave_handler)
         self.alice = accounts.get('alice')
         bob = accounts.get('bob')
         charlie = accounts.get('charlie')
@@ -135,6 +140,28 @@
         bob.account.set_callback(self.bob_cb)
         charlie.account.set_callback(self.charlie_cb)
         self.channels_hungup = 0
+        self.alice_in_bridge = False
+        self.bob_in_bridge = False
+        self.alice_phone_call = None
+
+    def bridge_enter_handler(self, ami, event):
+        """AMI bridge enter event callback."""
+        channel = event.get('channel')
+        if 'bob' in channel:
+            self.bob_in_bridge = True
+        elif 'alice' in channel:
+            self.alice_in_bridge = True
+        if self.bob_in_bridge and self.alice_in_bridge:
+            LOGGER.info('Both Alice and Bob are in bridge; starting transfer')
+            self.alice_phone_call.transfer_call()
+
+    def bridge_leave_handler(self, ami, event):
+        """AMI bridge leave event callback."""
+        channel = event.get('channel')
+        if 'bob' in channel:
+            self.bob_in_bridge = False
+        elif 'alice' in channel:
+            self.alice_in_bridge = False
 
     def hangup_event_handler(self, ami, event):
         """AMI hang up event callback."""
@@ -160,7 +187,8 @@
         """
         try:
             LOGGER.info("Making call to '%s'" % uri)
-            acc.make_call(uri, cb=AlicePhoneCallCallback())
+            self.alice_phone_call = AlicePhoneCallCallback()
+            acc.make_call(uri, cb=self.alice_phone_call)
         except pj.Error, err:
             LOGGER.error("Exception: %s" % str(err))
 
@@ -169,7 +197,10 @@
     """Log call info."""
     LOGGER.debug("Call '%s' <-> '%s'" % (call_info.uri, call_info.remote_uri))
     LOGGER.debug("Call state: '%s'; last code: '%s'; last reason: '%s'" %
-            (call_info.state_text, call_info.last_code, call_info.last_reason))
+                 (call_info.state_text,
+                  call_info.last_code,
+                  call_info.last_reason))
+
 
 def transfer(test_object, accounts):
     """The test's callback method.




More information about the svn-commits mailing list