[svn-commits] jpeeler: branch jpeeler/event_watcher r260 - /asterisk/team/jpeeler/event_wat...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Apr 28 17:59:34 CDT 2010


Author: jpeeler
Date: Wed Apr 28 17:59:31 2010
New Revision: 260

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=260
Log:
allow the test to be run inside and outside of testsuite

Modified:
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py?view=diff&rev=260&r1=259&r2=260
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py Wed Apr 28 17:59:31 2010
@@ -5,7 +5,24 @@
 from starpy import manager, fastagi, utilapplication, menu
 import os, logging, pprint, time, sys
 
+try:
+    sys.path.append("lib/python")
+    from asterisk.asterisk import Asterisk
+except ImportError:
+    print "Running in standalone mode"
+    STANDALONE = True
+
 class EventWatcher():
+
+    def start_asterisk(self):
+        self.log.debug("Starting Asterisk")
+        self.asterisk.start()
+        self.asterisk.cli_exec("core set verbose 10")
+        self.asterisk.cli_exec("core set debug 3")
+
+    def stop_asterisk(self):
+        if not STANDALONE:
+            self.asterisk.stop()
 
     def clear_vars(self):
  
@@ -22,6 +39,17 @@
         self.passed = True
 
         self.clear_vars()
+
+        if STANDALONE:
+            return
+
+        print "Creating Asterisk instance ..."
+        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
+                                                   "tests/ami-monitor/tmp"))
+        self.asterisk.install_config("tests/ami-monitor/configs/manager.conf")
+        self.asterisk.install_config("tests/ami-monitor/configs/logger.conf")
+
+        self.start_asterisk()
 
     def next_test(self, cb):
         self.next_test = cb
@@ -67,6 +95,7 @@
         print "DEBUG: timed out"
         self.passed = False
         reactor.stop()
+        self.stop_asterisk()
 
     def dict_in_dict(self, d_set, d_subset):
         #log.critical("JPEELER: Checking dictionaries")
@@ -85,6 +114,8 @@
 
     def onAMIFailure(self, ami):
         self.log.critical("Stop asterisk")
+        self.passed = False
+        self.stop_asterisk()
 
     def onAMIConnect(self, ami):
         """Register for AMI events"""
@@ -109,10 +140,10 @@
         self.sendEvents(ami)
 
     def onSentResponse(self, result):
-        print "result ---------------------------->", result
         # don't care about connection terminated event
         if result.__str__() != "Connection was closed cleanly: FastAGI connection terminated.":
-        	self.onAnyEvent(self.ami, result)
+            print "result ---------------------------->", result
+            self.onAnyEvent(self.ami, result)
         else:
             print "DEBUG: aborted because connection close event"
 
@@ -151,6 +182,7 @@
         if reactor.running:
             reactor.stop()
         self.log.critical("DEBUG: DONE, end_test")
+        self.stop_asterisk()
 
     def loadNextTest(self, ami, firstrun=None):
         if not firstrun:




More information about the svn-commits mailing list