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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 29 15:57:49 CDT 2010


Author: jpeeler
Date: Thu Apr 29 15:57:45 2010
New Revision: 267

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=267
Log:
convert all debug output to use logger with appropriate levels

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

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=267&r1=266&r2=267
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/client.py Thu Apr 29 15:57:45 2010
@@ -16,7 +16,7 @@
 class EventWatcher():
 
     def start_asterisk(self):
-        self.log.debug("Starting Asterisk")
+        self.log.info("Starting Asterisk")
         self.asterisk.start()
         self.asterisk.cli_exec("core set verbose 10")
         self.asterisk.cli_exec("core set debug 3")
@@ -49,7 +49,7 @@
         if STANDALONE:
             return
 
-        print "Creating Asterisk instance ..."
+        self.log.info("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")
@@ -82,9 +82,12 @@
         self.ordered = ordered
 
     def show_events(self):
-        print "Showing events"
+        if self.log.getEffectiveLevel() < logging.DEBUG:
+            return
+
+        self.log.debug("Showing events")
         for n in self.eventList:
-            print "Event: %s" % n
+            self.log.debug("Event: %s" % n)
 
     def get_events(self):
         return self.eventList
@@ -104,7 +107,7 @@
         return True
 
     def timeout(self):
-        print "DEBUG: timed out"
+        self.log.debug("Timed out")
         self.passed = False
         self.reactorLock.acquire()
         if not self.reactor_stopped:
@@ -120,11 +123,10 @@
             reactor.stop()
             self.reactor_stopped = True
         self.reactorLock.release()
-        self.log.critical("DEBUG: DONE, end_test")
+        self.log.info("DONE - end_test")
         self.stop_asterisk()
 
     def dict_in_dict(self, d_set, d_subset):
-        #log.critical("JPEELER: Checking dictionaries")
         return len(d_subset) == len(set(d_subset.items()) & set(d_set.items()))
 
     def start(self):
@@ -136,10 +138,10 @@
         if self.sendEventList:
             for amessage in self.sendEventList:
                 id = ami.sendMessage(amessage, self.onSentResponse)
-                self.log.debug("!!!!!!!!!!!!!!!! SENDING %s with id %s" % (amessage, id))
+                self.log.debug("SENDING %s with id %s" % (amessage, id))
 
     def onAMIFailure(self, ami):
-        self.log.critical("Stop asterisk")
+        self.log.critical("Stopping asterisk, login failure")
         self.passed = False
         self.stop_asterisk()
 
@@ -153,12 +155,12 @@
         ami.status().addCallback(self.onStatus, ami=ami)
 
         if len(self.eventList) or len(self.sendEventList) != 0:
-            self.log.critical("Don't load events outside of a test method!")
+            self.log.warn("Don't load events outside of a test method!")
 
         self.loadNextTest(ami, True)
 
         if len(self.eventList) == 0:
-            self.log.critical("No events to monitor!")
+            self.log.error("No events to monitor!")
 
         ami.registerEvent(None, self.onAnyEvent)
 
@@ -168,60 +170,59 @@
     def onSentResponse(self, result):
         # don't care about connection terminated event
         if result.__str__() != "Connection was closed cleanly: FastAGI connection terminated.":
-            print "result ---------------------------->", result
+            self.log.debug("Result from sent event: %s", result)
             self.onAnyEvent(self.ami, result)
         else:
-            print "DEBUG: aborted because connection close event"
+            self.log.debug("Ignoring connection close event")
 
     def connectionLost(reason):
-        self.log.critical("UNPLANNED? connection lost")
+        self.log.critical("Connection lost: %s", reason)
 
     def onAnyEvent(self, ami, event):
 
-        self.log.critical("DEBUG: RUNNING onAnyEvent")
+        self.log.debug("Running onAnyEvent")
 
         if not self.ordered:
             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))
+                    self.log.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.log.debug("New event %s" % next_event)
                         self.count = self.count - 1
                         if self.count == 0:
                             self.loadNextTest(ami)
-                    #else:
-                        #self.log.critical("??????????? NO MATCH ")
         else:
             index = abs(self.count - len(self.eventList))
             for next_event in self.eventList[index]:
                 if self.dict_in_dict(event, next_event):
                     next_event.update({"match": time.time()})
-                    self.log.critical("new event %s" % next_event)
+                    self.log.debug("New event %s" % next_event)
                     self.count = self.count - 1
                     if self.count == 0:
                         self.loadNextTest(ami)
                     continue
  
     def next_test(self, count, toexec):
-        print "NEXT TEST YAYA ", count
+        self.log.info("Next test count %s", count)
     
         if not hasattr(self.testobj, toexec):
-             print "DEBUG: no more tests"
+             self.log.debug("No more tests")
              return -1
 
-        print "DEBUG: next test exists"
+        self.log.debug("Next test (%s) exists", toexec)
         if self.callID:
             self.callID.cancel()
         method = getattr(self.testobj, toexec)
+        self.log.debug("Begin executing %s", toexec)
         method(self)
+        self.log.debug("Finish executing %s", toexec)
         if len(self.eventList) > 0:
-            print "DEBUG: Rescheduling timeout"
+            self.log.debug("Rescheduling timeout")
             self.callID = reactor.callLater(self.timeout_sec, self.timeout)
             return 0
     
-        print "DEBUG: returning, no events..."
+        self.log.warn("Returning, no events added by test method!")
         return -1 # exception or something
 
     def loadNextTest(self, ami, firstrun=None):
@@ -231,18 +232,18 @@
 
             passed = self.check_events()
             if not passed:
-                print "TEST FAILED"
+                self.log.debug("TEST FAILED")
                 self.passed = False
                 self.end_test()
                 return
 
-            print "DEBUG: TEST GOOD"
+            self.log.debug("Test passed")
             self.show_events()
             self.clear_vars()
 
         toexec = "test" + str(self.testcount)
         res = self.next_test(self.testcount, toexec)
-        print "DEBUG: res %s from exec %s" % (res, toexec)
+        self.log.debug("res %s from exec %s" % (res, toexec))
         if res == -1:
             self.ami = None
             self.end_test()

Modified: asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test?view=diff&rev=267&r1=266&r2=267
==============================================================================
--- asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test (original)
+++ asterisk/team/jpeeler/event_watcher/tests/ami-monitor/run-test Thu Apr 29 15:57:45 2010
@@ -11,22 +11,16 @@
 class Test():
 
     def test0(self, watcher):
-        print "WOOT! - test0"
-        #time.sleep(3)
         event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
         watcher.add_event(event1)
         event_send = {'Action' : 'ping'}
         watcher.add_send_event(event_send)
-        print "ENDWOOT"
     
-    def test1(self, watcher):
-        print "WOOT2! - test1"
-        #time.sleep(10)
-        event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
-        watcher.add_event(event1)
-        event_send = {'Action' : 'ping'}
-        watcher.add_send_event(event_send)
-        print "ENDWOOT2"
+    #def test1(self, watcher):
+    #    event1 = [{'response' : 'Success', 'ping' : 'Pong'}]
+    #    watcher.add_event(event1)
+    #    event_send = {'Action' : 'ping'}
+    #    watcher.add_send_event(event_send)
 
     #def test2(self, watcher):
         #scenario 2 with optional event matching
@@ -60,9 +54,9 @@
     reactor.run()
         
     if watcher.passed:
-        print "DEBUG: all good!"
+        watcher.log.info("All tests were good!")
         return 0
-    print "DEBUG: FAIL"
+    watcher.log.error("Test failure")
     return 1
       
 if __name__ == "__main__":




More information about the asterisk-commits mailing list