[asterisk-commits] kmoore: testsuite/asterisk/trunk r5255 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 17 22:32:48 CDT 2014


Author: kmoore
Date: Thu Jul 17 22:32:40 2014
New Revision: 5255

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5255
Log:
Testsuite: Clean up AMI connections

Clean up AMI connections just before shutting down asterisk. This
prevents reference leaks related to manager sessions.

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

Modified:
    asterisk/trunk/lib/python/asterisk/test_case.py

Modified: asterisk/trunk/lib/python/asterisk/test_case.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/test_case.py?view=diff&rev=5255&r1=5254&r2=5255
==============================================================================
--- asterisk/trunk/lib/python/asterisk/test_case.py (original)
+++ asterisk/trunk/lib/python/asterisk/test_case.py Thu Jul 17 22:32:40 2014
@@ -388,18 +388,35 @@
             self._stop_deferred.callback(self)
             return result
 
+        def __stop_ami(result):
+            """Tear down AMI connections"""
+
+            # Call the overridable method now
+            self.stop_asterisk()
+
+            # tear down AMI instances
+            ami_defers = []
+            for ami in self.ami:
+                if ami:
+                    ami_defers.append(ami.logoff())
+
+            defer.DeferredList(ami_defers).addCallback(
+                __stop_instances).addErrback(__ami_stop_fail)
+
+        def __ami_stop_fail(result):
+            """Handle AMI stop failure"""
+            LOGGER.error("Failed to tear down AMI connection(s)")
+            __stop_instances(result)
+
         def __stop_instances(result):
             """Stop the instances"""
 
-            # Call the overridable method now
-            self.stop_asterisk()
             # Gather up the stopped defers; check success failure of stopping
             # when all instances of Asterisk have stopped
             stop_defers = []
             for index, item in enumerate(self.ast):
                 LOGGER.info("Stopping Asterisk instance %d" % (index + 1))
-                temp_defer = self.ast[index].stop()
-                stop_defers.append(temp_defer)
+                stop_defers.append(item.stop())
 
             defer.DeferredList(stop_defers).addCallback(
                 __check_success_failure)
@@ -408,9 +425,9 @@
         self._stop_deferred = defer.Deferred()
         deferred = self.condition_controller.evaluate_post_checks()
         if deferred:
-            deferred.addCallback(__stop_instances)
+            deferred.addCallback(__stop_ami)
         else:
-            __stop_instances(None)
+            __stop_ami(None)
         return self._stop_deferred
 
     def stop_reactor(self):




More information about the asterisk-commits mailing list