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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 23 13:57:44 CDT 2010


Author: jpeeler
Date: Fri Apr 23 13:57:41 2010
New Revision: 249

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=249
Log:
add ability to be able to send events to monitor responses for

Modified:
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/server.py
    asterisk/team/jpeeler/event_watcher/tests/ami-monitor/test.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=249&r1=248&r2=249
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py Fri Apr 23 13:57:41 2010
@@ -5,9 +5,6 @@
 from starpy import manager, fastagi, utilapplication, menu
 import os, logging, pprint, time, sys
 from basicproperty import common, propertied, basic
-import subprocess
-
-
 
 class EventWatcher(propertied.Propertied):
 
@@ -17,6 +14,8 @@
         self.ordered = False
         self.log = logging.getLogger('TestAMI')
         self.log.setLevel(logging.INFO)
+        self.sendEventList = list()
+        self.ami = None
 
     def set_ordered(self, ordered):
         self.ordered = ordered
@@ -24,6 +23,9 @@
     def add_event(self, event):
         self.eventList.append(event)
         self.count = self.count + 1
+
+    def add_send_event(self, event):
+        self.sendEventList.append(event)
 
     def set_events(self, ordered, list):
         self.eventList = list
@@ -79,6 +81,21 @@
 
         ami.registerEvent(None, self.onAnyEvent)
 
+        self.ami = ami
+        if self.sendEventList:
+            for amessage in self.sendEventList:
+                id = ami.sendMessage(amessage, self.onSentResponse)
+                self.log.debug("SENDING %s with id %s" % (amessage, id))
+
+    def onSentResponse(self, result):
+        print "result ---------------------------->", result
+        # don't care about connection terminated event
+        if self.ami:
+        	self.onAnyEvent(self.ami, result)
+
+    def connectionLost(reason):
+        self.log.critical("UNPLANNED? connection lost")
+
     def onAnyEvent(self, ami, event):
 
         self.log.critical("DEBUG: RUNNING onAnyEvent")
@@ -87,12 +104,15 @@
             for next_events in self.eventList:
                 for next_event in next_events:
                     #self.log.critical("DEBUG: Looking at %s of type %s and count %s" % (next_events, type(next_events), len(next_events)))
+                    self.log.critical("!!!!!!!!!!!!!!! DEBUG: Looking at %s vs %s" % (next_event, event))
                     if self.dict_in_dict(event, next_event):
                         next_event.update({"match": time.time()})
                         self.log.critical("new event %s" % next_event)
                         self.count = self.count - 1
                         if self.count == 0:
                             self.stopMonitoring(ami)
+                    #else:
+                        #self.log.critical("??????????? NO MATCH ")
         else:
             index = abs(self.count - len(self.eventList))
             for next_event in self.eventList[index]:
@@ -105,6 +125,8 @@
                     continue
 
     def stopMonitoring(self, ami):
+        self.log.debug("About to shut down all monitoring")
+        self.ami = None
         ami.deregisterEvent(None, None)
         if reactor.running:
             reactor.stop()
@@ -119,12 +141,6 @@
                 self.log.debug("Received event: %s", event)
 
 APPLICATION = utilapplication.UtilApplication()
-
-class EventSender:
-
-    def __init__(self):
-        self.test = 0
-
 
 def main():
     logging.basicConfig()

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/server.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/server.py?view=diff&rev=249&r1=248&r2=249
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/server.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/server.py Fri Apr 23 13:57:41 2010
@@ -119,6 +119,10 @@
                 self.transport.write("Event: StatusComplete\r\nActionID: " + d['actionid'] + "\r\nItems: 0\r\n\r\n")
                 print "Response: Success\r\nActionID: " + d['actionid'] + "\r\nMessage: Channel status will follow\r\n\r\n"
                 print "Event: StatusComplete\r\nActionID: " + d['actionid'] + "\r\nItems: 0\r\n\r\n"
+            if d['action'] == "ping" and d['actionid']:
+                self.transport.write("Response: Success\r\nActionID: " + d['actionid'] + "\r\nPing: Pong\r\n\r\n")
+                #self.transport.write("Response: Success\r\nPing: Pong\r\n\r\n")
+                print "Response: Success\r\nPing: pong\r\n\r\n"
 
     def lineReceived(self, data):
         if data == '':

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/test.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/test.py?view=diff&rev=249&r1=248&r2=249
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/test.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/test.py Fri Apr 23 13:57:41 2010
@@ -13,19 +13,36 @@
 
 def main():
     logging.basicConfig()
+
+    manager.log.setLevel(logging.DEBUG)
     watcher = client.EventWatcher()
+    watcher.log.setLevel(logging.DEBUG)
 
     #scenario 2 with optional event matching
-    event1 = [{'event' : 'Alarm', 'channel' : '18' }]
-    event2 = [{'event' : 'Alarm', 'channel' : '17' }]
-    event3 = [{'event' : 'Alarm', 'channel' : '20' }, {'event' : 'Alarm', 'channel' : '19'}]
+    #event1 = [{'event' : 'Alarm', 'channel' : '18' }]
+    #event2 = [{'event' : 'Alarm', 'channel' : '17' }]
+    #event3 = [{'event' : 'Alarm', 'channel' : '20' }, {'event' : 'Alarm', 'channel' : '19'}]
+    #watcher.add_event(event1)
+    #watcher.add_event(event2)
+    #watcher.add_event(event3)
+    #watcher.set_ordered(True)
+
+    #event1 = [{'event' : 'Alarm', 'channel' : '17' }]
+    #event2 = [{'event' : 'Alarm', 'channel' : '18' }]
+    #event3 = [{'event' : 'Alarm', 'channel' : '20' }, {'event' : 'Alarm', 'channel' : '19'}]
+    #watcher.add_event(event1)
+    #watcher.add_event(event2)
+    #watcher.add_event(event3)
+    #watcher.set_ordered(True)
+
+    event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
     watcher.add_event(event1)
-    watcher.add_event(event2)
-    watcher.add_event(event3)
-    watcher.set_ordered(True)
+
+    event_send = {'Action' : 'ping'}
+    watcher.add_send_event(event_send)
 
     reactor.callWhenRunning(watcher.main)
-    reactor.callLater(15, watcher.timeout)
+    reactor.callLater(5, watcher.timeout)
     reactor.run()
         
     watcher.show_events()




More information about the asterisk-commits mailing list