[asterisk-commits] mjordan: branch group/python_logging r1973 - in /asterisk/team/group/python_l...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 26 14:57:13 CDT 2011
Author: mjordan
Date: Fri Aug 26 14:57:09 2011
New Revision: 1973
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1973
Log:
Posted for testing, etc.
Added:
asterisk/team/group/python_logging/ (props changed)
- copied from r1911, asterisk/trunk/
asterisk/team/group/python_logging/asttest/asttest.c
- copied, changed from r1972, asterisk/trunk/asttest/asttest.c
asterisk/team/group/python_logging/configs/
- copied from r1962, asterisk/trunk/configs/
asterisk/team/group/python_logging/lib/python/asterisk/TestCase.py
- copied, changed from r1972, asterisk/trunk/lib/python/asterisk/TestCase.py
asterisk/team/group/python_logging/lib/python/asterisk/asterisk.py
- copied, changed from r1972, asterisk/trunk/lib/python/asterisk/asterisk.py
asterisk/team/group/python_logging/logger.conf (with props)
asterisk/team/group/python_logging/runtests.py
- copied, changed from r1972, asterisk/trunk/runtests.py
asterisk/team/group/python_logging/tests/apps/directory_attendant_exit/run-test
- copied unchanged from r1962, asterisk/trunk/tests/apps/directory_attendant_exit/run-test
asterisk/team/group/python_logging/tests/apps/directory_context_operator_exit/run-test
- copied unchanged from r1962, asterisk/trunk/tests/apps/directory_context_operator_exit/run-test
asterisk/team/group/python_logging/tests/apps/directory_operator_exit/run-test
- copied unchanged from r1962, asterisk/trunk/tests/apps/directory_operator_exit/run-test
asterisk/team/group/python_logging/tests/apps/voicemail/leave_voicemail_nominal/run-test
- copied, changed from r1972, asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test
asterisk/team/group/python_logging/tests/blind-transfer-parkingtimeout/run-test
- copied unchanged from r1972, asterisk/trunk/tests/blind-transfer-parkingtimeout/run-test
asterisk/team/group/python_logging/tests/callparking/run-test
- copied unchanged from r1962, asterisk/trunk/tests/callparking/run-test
asterisk/team/group/python_logging/tests/cdr/cdr_unanswered_yes/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/cdr_unanswered_yes/run-test
asterisk/team/group/python_logging/tests/cdr/cdr_userfield/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/cdr_userfield/run-test
asterisk/team/group/python_logging/tests/cdr/console_dial_sip_answer/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_dial_sip_answer/run-test
asterisk/team/group/python_logging/tests/cdr/console_dial_sip_busy/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_dial_sip_busy/run-test
asterisk/team/group/python_logging/tests/cdr/console_dial_sip_congestion/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_dial_sip_congestion/run-test
asterisk/team/group/python_logging/tests/cdr/console_dial_sip_transfer/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_dial_sip_transfer/run-test
asterisk/team/group/python_logging/tests/cdr/console_fork_after_busy_forward/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_fork_after_busy_forward/run-test
asterisk/team/group/python_logging/tests/cdr/console_fork_before_dial/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/console_fork_before_dial/run-test
asterisk/team/group/python_logging/tests/cdr/nocdr/run-test
- copied unchanged from r1962, asterisk/trunk/tests/cdr/nocdr/run-test
asterisk/team/group/python_logging/tests/channels/SIP/message_auth/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/message_auth/run-test
asterisk/team/group/python_logging/tests/channels/SIP/message_disabled/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/message_disabled/run-test
asterisk/team/group/python_logging/tests/channels/SIP/message_from_call/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/message_from_call/run-test
asterisk/team/group/python_logging/tests/channels/SIP/message_unauth/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/message_unauth/run-test
asterisk/team/group/python_logging/tests/channels/SIP/noload_res_srtp/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/noload_res_srtp/run-test
asterisk/team/group/python_logging/tests/channels/SIP/noload_res_srtp_attempt_srtp/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/noload_res_srtp_attempt_srtp/run-test
asterisk/team/group/python_logging/tests/channels/SIP/options/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/options/run-test
asterisk/team/group/python_logging/tests/channels/SIP/refer_replaces_to_self/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/refer_replaces_to_self/run-test
asterisk/team/group/python_logging/tests/channels/SIP/secure_bridge_media/run-test
- copied unchanged from r1962, asterisk/trunk/tests/channels/SIP/secure_bridge_media/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_attended_transfer/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_attended_transfer/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_attended_transfer_tcp/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_attended_transfer_tcp/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_attended_transfer_v6/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_attended_transfer_v6/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_one_legged_transfer/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_one_legged_transfer/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_one_legged_transfer_v6/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_one_legged_transfer_v6/run-test
asterisk/team/group/python_logging/tests/channels/SIP/sip_register/run-test
- copied unchanged from r1972, asterisk/trunk/tests/channels/SIP/sip_register/run-test
asterisk/team/group/python_logging/tests/chanspy/chanspy_barge/run-test
- copied unchanged from r1972, asterisk/trunk/tests/chanspy/chanspy_barge/run-test
asterisk/team/group/python_logging/tests/chanspy/chanspy_w_mixmonitor/run-test
- copied unchanged from r1972, asterisk/trunk/tests/chanspy/chanspy_w_mixmonitor/run-test
asterisk/team/group/python_logging/tests/directed_pickup/run-test
- copied unchanged from r1972, asterisk/trunk/tests/directed_pickup/run-test
asterisk/team/group/python_logging/tests/fastagi/execute/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/execute/run-test
asterisk/team/group/python_logging/tests/fastagi/get-data/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/get-data/run-test
asterisk/team/group/python_logging/tests/fastagi/hangup/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/hangup/run-test
asterisk/team/group/python_logging/tests/fastagi/record-file/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/record-file/run-test
asterisk/team/group/python_logging/tests/fastagi/say-alpha/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-alpha/run-test
asterisk/team/group/python_logging/tests/fastagi/say-date/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-date/run-test
asterisk/team/group/python_logging/tests/fastagi/say-datetime/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-datetime/run-test
asterisk/team/group/python_logging/tests/fastagi/say-digits/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-digits/run-test
asterisk/team/group/python_logging/tests/fastagi/say-number/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-number/run-test
asterisk/team/group/python_logging/tests/fastagi/say-phonetic/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-phonetic/run-test
asterisk/team/group/python_logging/tests/fastagi/say-time/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/say-time/run-test
asterisk/team/group/python_logging/tests/fastagi/wait-for-digit/run-test
- copied unchanged from r1972, asterisk/trunk/tests/fastagi/wait-for-digit/run-test
asterisk/team/group/python_logging/tests/feature_attended_transfer/run-test
- copied unchanged from r1972, asterisk/trunk/tests/feature_attended_transfer/run-test
asterisk/team/group/python_logging/tests/feature_blonde_transfer/run-test
- copied unchanged from r1972, asterisk/trunk/tests/feature_blonde_transfer/run-test
asterisk/team/group/python_logging/tests/iax2/basic-call/run-test
- copied unchanged from r1972, asterisk/trunk/tests/iax2/basic-call/run-test
asterisk/team/group/python_logging/tests/manager/event-monitor/run-test
- copied unchanged from r1972, asterisk/trunk/tests/manager/event-monitor/run-test
asterisk/team/group/python_logging/tests/mixmonitor/run-test
- copied unchanged from r1972, asterisk/trunk/tests/mixmonitor/run-test
asterisk/team/group/python_logging/tests/mixmonitor_audiohook_inherit/run-test
- copied unchanged from r1972, asterisk/trunk/tests/mixmonitor_audiohook_inherit/run-test
asterisk/team/group/python_logging/tests/one-step-parking/run-test
- copied unchanged from r1972, asterisk/trunk/tests/one-step-parking/run-test
asterisk/team/group/python_logging/tests/pbx/call-files/run-test
- copied unchanged from r1972, asterisk/trunk/tests/pbx/call-files/run-test
asterisk/team/group/python_logging/tests/udptl_v6/run-test
- copied unchanged from r1972, asterisk/trunk/tests/udptl_v6/run-test
Modified:
asterisk/team/group/python_logging/lib/python/asterisk/ami.py
asterisk/team/group/python_logging/lib/python/asterisk/cdr.py
asterisk/team/group/python_logging/lib/python/asterisk/config.py
asterisk/team/group/python_logging/lib/python/asterisk/sipp.py
asterisk/team/group/python_logging/lib/python/asterisk/version.py
asterisk/team/group/python_logging/lib/python/asterisk/voicemail.py
asterisk/team/group/python_logging/lib/python/client.py
asterisk/team/group/python_logging/tests/apps/voicemail/leave_voicemail_nominal/configs/ast2/extensions.conf
asterisk/team/group/python_logging/tests/apps/voicemail/tests.yaml
Propchange: asterisk/team/group/python_logging/
------------------------------------------------------------------------------
reviewboard:url = https://reviewboard.asterisk.org
Propchange: asterisk/team/group/python_logging/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 26 14:57:09 2011
@@ -1,0 +1,2 @@
+asterisk-test-suite-report.xml
+*.pyc
Propchange: asterisk/team/group/python_logging/
------------------------------------------------------------------------------
svn:mergeinfo = /asterisk/trunk:1112
Copied: asterisk/team/group/python_logging/asttest/asttest.c (from r1972, asterisk/trunk/asttest/asttest.c)
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/asttest/asttest.c?view=diff&rev=1973&p1=asterisk/trunk/asttest/asttest.c&r1=1972&p2=asterisk/team/group/python_logging/asttest/asttest.c&r2=1973
==============================================================================
--- asterisk/trunk/asttest/asttest.c (original)
+++ asterisk/team/group/python_logging/asttest/asttest.c Fri Aug 26 14:57:09 2011
@@ -82,7 +82,7 @@
opts->asterisk_path = "asterisk";
/* parse options */
- while ((c = getopt(argc, argv, "l:a:s:v:n:wh")) != -1) {
+ while ((c = getopt(argc, argv, "l:a:s:v:wh")) != -1) {
switch (c) {
case 'l':
opts->log_filename = optarg;
Copied: asterisk/team/group/python_logging/lib/python/asterisk/TestCase.py (from r1972, asterisk/trunk/lib/python/asterisk/TestCase.py)
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/TestCase.py?view=diff&rev=1973&p1=asterisk/trunk/lib/python/asterisk/TestCase.py&r1=1972&p2=asterisk/team/group/python_logging/lib/python/asterisk/TestCase.py&r2=1973
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/TestCase.py Fri Aug 26 14:57:09 2011
@@ -8,14 +8,14 @@
'''
import sys
-import logging
+import logging, logging.config
import os
from twisted.internet import reactor
from starpy import manager, fastagi
from asterisk import Asterisk
-log = logging.getLogger('TestCase')
+logger = logging.getLogger(__name__)
class TestCase(object):
ast = []
@@ -23,10 +23,31 @@
fastagi = []
reactor_timeout = 30
passed = False
+ defaultLogLevel = "WARN"
+ defaultLogFileName = "logger.conf"
def __init__(self):
self.test_name = os.path.dirname(sys.argv[0])
self.base = self.test_name.lstrip("tests/")
+
+ self.testStateController = None
+
+ """ Set up logging """
+ logConfigFile = os.path.join(os.getcwd(), "%s" % (self.defaultLogFileName))
+ if os.path.exists(logConfigFile):
+ logging.config.fileConfig(logConfigFile, None, False)
+ else:
+ print "WARNING: no logging.conf file found; using default configuration"
+ logging.basicConfig(level=self.defaultLogLevel)
+
+ """ File logger specific for this test - note that there should be a console logger by default """
+ logFormat = logging.Formatter("%(levelname)s\t%(asctime)s\t%(name)s::%(funcName)s[%(lineno)d]: %(message)s")
+ filePath = self.test_name + "/test-output.txt"
+ fh = logging.FileHandler(filePath, 'w')
+ fh.setFormatter(logFormat)
+
+ """ Attach the handler to the root logger - this applies it to things like starpy as well """
+ logging.getLogger().addHandler(fh)
reactor.callWhenRunning(self.run)
@@ -38,7 +59,7 @@
"""
for c in range(count):
- print "Creating Asterisk instance %d ..." % (c + 1)
+ logger.info("Creating Asterisk instance %d ..." % (c + 1))
self.ast.append(Asterisk(base=self.base))
# Copy shared config files
self.ast[c].install_configs("%s/configs" %
@@ -60,7 +81,7 @@
for c in range(count):
host = "127.0.0.%d" % (c + 1)
self.ami.append(None)
- print "Creating AMIFactory %d ..." % (c + 1)
+ logger.info( "Creating AMIFactory %d ..." % (c + 1))
self.ami_factory = manager.AMIFactory(username, secret, c)
self.ami_factory.login(host).addCallbacks(self.ami_connect,
self.ami_login_error)
@@ -70,7 +91,7 @@
for c in range(count):
host = "127.0.0.%d" % (c + 1)
self.fastagi.append(None)
- print "Creating FastAGI Factory %d ..." % (c + 1)
+ logger.info( "Creating FastAGI Factory %d ..." % (c + 1))
self.fastagi_factory = fastagi.FastAGIFactory(self.fastagi_connect)
reactor.listenTCP(4573, self.fastagi_factory,
self.reactor_timeout, host)
@@ -80,7 +101,7 @@
"""
for index, item in enumerate(self.ast):
- print "Starting Asterisk instance %d ..." % (index + 1)
+ logger.info( "Starting Asterisk instance %d ..." % (index + 1))
self.ast[index].start()
def stop_asterisk(self):
@@ -88,14 +109,14 @@
"""
for index, item in enumerate(self.ast):
- print "Stopping Asterisk instance %d ..." % (index + 1)
+ logger.info( "Stopping Asterisk instance %d ..." % (index + 1))
self.ast[index].stop()
def stop_reactor(self):
"""
"""
- print "Stopping Reactor ..."
+ logger.info( "Stopping Reactor ...")
if reactor.running:
reactor.stop()
@@ -106,10 +127,10 @@
reactor.callLater(self.reactor_timeout, self.stop_reactor)
def ami_login_error(self, ami):
- print "Error logging into AMI"
+ logger.error( "Error logging into AMI")
self.stop_reactor()
def ami_connect(self, ami):
- print "AMI Connect instance %s ..." % (ami.id + 1)
+ logger.info( "AMI Connect instance %s ..." % (ami.id + 1))
self.ami[ami.id] = ami
Modified: asterisk/team/group/python_logging/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/ami.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/ami.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/ami.py Fri Aug 26 14:57:09 2011
@@ -2,6 +2,9 @@
from starpy import manager
import datetime
import sys
+import logging
+
+logger = logging.getLogger(__name__)
class AMI:
def __init__(self, on_login, on_error, timeout=60, user="mark", secret="mysecret", host="127.0.0.1", port=5038):
@@ -18,20 +21,20 @@
def login(self):
self.__attempts = self.__attempts + 1
- print "AMI Login attempt #%d" % (self.__attempts)
+ logger.debug("AMI Login attempt #%d" % (self.__attempts))
if not self.__start:
self.__start = datetime.datetime.now()
self.ami_factory.login(self.host, self.port).addCallbacks(self.on_login_success, self.on_login_error)
def on_login_success(self, ami):
self.ami = ami
- print "AMI Login succesful"
+ logger.debug("AMI Login succesful")
return self.on_login(ami)
def on_login_error(self, reason):
runtime = (datetime.datetime.now() - self.__start).seconds
if runtime >= self.login_timeout:
- print "AMI login failed after %d second timeout" % (self.login_timeout)
+ logger.error("AMI login failed after %d second timeout" % (self.login_timeout))
return self.on_error()
delay = 2 ** self.__attempts
if delay + runtime >= self.login_timeout:
Copied: asterisk/team/group/python_logging/lib/python/asterisk/asterisk.py (from r1972, asterisk/trunk/lib/python/asterisk/asterisk.py)
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/asterisk.py?view=diff&rev=1973&p1=asterisk/trunk/lib/python/asterisk/asterisk.py&r1=1972&p2=asterisk/team/group/python_logging/lib/python/asterisk/asterisk.py&r2=1973
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/asterisk.py Fri Aug 26 14:57:09 2011
@@ -18,10 +18,12 @@
import shutil
import subprocess
import utils
+import logging
from config import ConfigFile
from version import AsteriskVersion
+logger = logging.getLogger(__name__)
class Asterisk:
"""An instance of Asterisk.
@@ -77,7 +79,7 @@
ast_conf = ConfigFile(c)
break
if ast_conf is None:
- print "No asterisk.conf found on the system!"
+ logger.error("No asterisk.conf found on the system!")
return
if base is not None:
@@ -97,7 +99,7 @@
if c.name == "directories":
dir_cat = c
if dir_cat is None:
- print "Unable to discover dir layout from asterisk.conf"
+ logger.error("Unable to discover dir layout from asterisk.conf")
return
self.__gen_ast_conf(ast_conf, dir_cat, ast_conf_options)
for (var, val) in dir_cat.options:
@@ -121,7 +123,7 @@
try:
self.process = subprocess.Popen(cmd)
except OSError:
- print "Failed to execute command: %s" % str(cmd)
+ logger.error("Failed to execute command: %s" % str(cmd))
return False
# Be _really_ sure that Asterisk has started up before returning.
@@ -232,7 +234,7 @@
asterisk.install_config("tests/my-cool-test/configs/manager.conf")
"""
if not os.path.exists(cfg_path):
- print "Config file '%s' does not exist" % cfg_path
+ logger.error("Config file '%s' does not exist" % cfg_path)
return
tmp = "%s/%s/%s" % (os.path.dirname(cfg_path), self.ast_version.branch, os.path.basename(cfg_path))
@@ -244,9 +246,9 @@
try:
shutil.copyfile(cfg_path, target_path)
except shutil.Error:
- print "'%s' and '%s' are the same file" % (cfg_path, target_path)
+ logger.warn("'%s' and '%s' are the same file" % (cfg_path, target_path))
except IOError:
- print "The destination is not writable '%s'" % target_path
+ logger.warn("The destination is not writable '%s'" % target_path)
def cli_originate(self, argstr, blocking=True):
"""Starts a call from the CLI and links it to an application or
@@ -272,13 +274,13 @@
raise_error = False
if len(args) != 3 and len(args) != 4:
raise_error = True
- print "Wrong number of arguments."
+ logger.error("Wrong number of arguments.")
if args[1] != "extension" and args[1] != "application":
raise_error = True
- print '2nd argument must be "extension" or "application"'
+ logger.error('2nd argument must be "extension" or "application"')
if args[0].find("/") == -1:
raise_error = True
- print 'Channel dial string must be in the form "tech/data".'
+ logger.error('Channel dial string must be in the form "tech/data".')
if raise_error is True:
raise Exception, "Cannot originate call!\n\
Argument string must be in one of these forms:\n\
@@ -306,7 +308,7 @@
"-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf"),
"-rx", "%s" % cli_cmd
]
- print "Executing %s ..." % cmd
+ logger.debug("Executing %s ..." % cmd)
if not blocking:
process = subprocess.Popen(cmd)
@@ -316,13 +318,13 @@
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
except OSError:
- print "Failed to execute command: %s" % str(cmd)
+ logger.warn("Failed to execute command: %s" % str(cmd))
return ""
output = ""
try:
for l in process.stdout.readlines():
- print l,
+ logger.debug(l),
output += l
except IOError:
pass
@@ -343,10 +345,10 @@
try:
f = open(local_ast_conf_path, "w")
except IOError:
- print "Failed to open %s" % local_ast_conf_path
+ logger.error("Failed to open %s" % local_ast_conf_path)
return
except:
- print "Unexpected error: %s" % sys.exc_info()[0]
+ logger.error("Unexpected error: %s" % sys.exc_info()[0])
return
for c in ast_conf.categories:
Modified: asterisk/team/group/python_logging/lib/python/asterisk/cdr.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/cdr.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/cdr.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/cdr.py Fri Aug 26 14:57:09 2011
@@ -14,6 +14,9 @@
import sys
import csv
import re
+import logging
+
+logger = logging.getLogger(__name__)
class AsteriskCSVCDRLine:
"A single Asterisk call detail record"
@@ -46,8 +49,8 @@
for k,v in self.iteritems():
if None not in (v, other.get(k)) and not re.match(
"%s$" % (str(v).lower()), str(other.get(k)).lower()):
- print "CDR MATCH FAILED, Expected: %s:%s Got: %s:%s" % (k, v,
- k, other.get(k))
+ logger.warn("CDR MATCH FAILED, Expected: %s:%s Got: %s:%s" % (k, v,
+ k, other.get(k)))
return False
return True
@@ -86,10 +89,10 @@
try:
cdr = csv.DictReader(open(fn, "r"), AsteriskCSVCDRLine.get_fields(), ",")
except IOError:
- print "Failed to open CDR file '%s'" % (fn)
+ logger.error("Failed to open CDR file '%s'" % (fn))
return
except:
- print "Unexpected error: %s" % (sys.exc_info()[0])
+ logger.error("Unexpected error: %s" % (sys.exc_info()[0]))
return
for r in cdr:
@@ -110,7 +113,7 @@
each record"""
if len(self) != len(other):
- print "CDR MATCH FAILED, different number of records"
+ logger.warn("CDR MATCH FAILED, different number of records")
return False
for i,x in enumerate(self):
if not x.match(other[i]):
@@ -124,7 +127,7 @@
try:
open(self.filename, "w").close()
except:
- print "Unable to empty CDR file %s" % (self.filename)
+ logger.warn("Unable to empty CDR file %s" % (self.filename))
class AsteriskCSVCDRTests(unittest.TestCase):
Modified: asterisk/team/group/python_logging/lib/python/asterisk/config.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/config.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/config.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/config.py Fri Aug 26 14:57:09 2011
@@ -19,7 +19,9 @@
import sys
import re
import unittest
+import logging
+logger = logging.getLogger(__name__)
def is_blank_line(line):
return re.match("\s*(?:;.*)?$", line) is not None
@@ -49,7 +51,7 @@
match = self.varval_re.match(line)
if match is None:
if not is_blank_line(line):
- print "Invalid line: '%s'" % line.strip()
+ logger.warn("Invalid line: '%s'" % line.strip())
return
self.options.append((match.group("name"), match.group("value").strip()))
@@ -80,10 +82,10 @@
config_str = f.read()
f.close()
except IOError:
- print "Failed to open config file '%s'" % fn
+ logger.error("Failed to open config file '%s'" % fn)
return
except:
- print "Unexpected error: %s" % sys.exc_info()[0]
+ logger.error("Unexpected error: %s" % sys.exc_info()[0])
return
config_str = self.strip_mline_comments(config_str)
@@ -103,7 +105,7 @@
)
elif len(self.categories) == 0:
if not is_blank_line(line):
- print "Invalid line: '%s'" % line.strip()
+ logger.warn("Invalid line: '%s'" % line.strip())
else:
self.categories[-1].parse_line(line)
@@ -178,9 +180,9 @@
if len(argv) == 2:
conf = ConfigFile(argv[1])
for c in conf.categories:
- print "[%s]" % c.name
+ logger.debug("[%s]" % c.name)
for (var, val) in c.options:
- print "%s = %s" % (var, val)
+ logger.debug("%s = %s" % (var, val))
else:
return unittest.main()
Modified: asterisk/team/group/python_logging/lib/python/asterisk/sipp.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/sipp.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/sipp.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/sipp.py Fri Aug 26 14:57:09 2011
@@ -13,9 +13,11 @@
import sys
import os
import subprocess
+import logging
from asterisk import Asterisk
+logger = logging.getLogger(__name__)
class SIPpTest:
"""
@@ -90,9 +92,10 @@
for (key, val) in default_args.items():
sipp_args.extend([ key, val ])
- print "Executing SIPp scenario: %s" % scenario['scenario']
- print sipp_args
+ logger.debug("Executing SIPp scenario: %s" % scenario['scenario'])
+ logger.debug(sipp_args)
+ #return subprocess.Popen(sipp_args)
return subprocess.Popen(sipp_args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -115,13 +118,13 @@
self.stderr.append(err)
self.result.append(self.sipp[i].wait())
if self.result[i]:
- print "SIPp scenario #%d FAILED" % i
+ logger.warn("SIPp scenario #%d FAILED" % i)
else:
- print "SIPp scenario #%d PASSED" % i
+ logger.info("SIPp scenario #%d PASSED" % i)
if self.result[i]:
passed = False
#print self.stdout[i]
- print self.stderr[i]
+ logger.warn(self.stderr[i])
self.ast1.stop()
Modified: asterisk/team/group/python_logging/lib/python/asterisk/version.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/version.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/version.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/version.py Fri Aug 26 14:57:09 2011
@@ -14,6 +14,9 @@
import sys
import re
import unittest
+import logging
+
+logger = logging.getLogger(__name__)
class AsteriskVersion:
"""An Asterisk Version.
@@ -146,10 +149,10 @@
v = match.group(1)
f.close()
except IOError:
- print "I/O Error getting Asterisk version from %s" % path
+ logger.error("I/O Error getting Asterisk version from %s" % path)
except:
- print "Unexpected error getting version from %s: %s" % (path,
- sys.exc_info()[0])
+ logger.error("Unexpected error getting version from %s: %s" % (path,
+ sys.exc_info()[0]))
return v
Modified: asterisk/team/group/python_logging/lib/python/asterisk/voicemail.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/asterisk/voicemail.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/asterisk/voicemail.py (original)
+++ asterisk/team/group/python_logging/lib/python/asterisk/voicemail.py Fri Aug 26 14:57:09 2011
@@ -12,12 +12,21 @@
import os
import glob
import shutil
-
+import datetime
+import logging
+
+from datetime import datetime
from asterisk import Asterisk
from config import Category
from config import ConfigFile
+from TestCase import TestCase
+from TestState import TestState
+from TestState import TestStateController
sys.path.append("lib/python")
+
+logger = logging.getLogger(__name__)
+
"""
Class that manages creation of, verification of, and teardown of Asterisk mailboxes on the local filesystem
@@ -71,7 +80,7 @@
def __init__(self, ast):
self.__ast = ast
self.voicemailDirectory = self.__ast.directories['astspooldir'] + '/voicemail'
-
+ logger = logging.getLogger("TestCase.VoiceMailMailboxManagement")
"""
Creates the basic set of folders needed for a mailbox on the file system
@@ -116,7 +125,7 @@
except IOError as e:
if e.errno == errno.EACCESS:
- print "You do not have sufficient permissions to perform the necessary directory manipulations"
+ logger.error( "You do not have sufficient permissions to perform the necessary directory manipulations")
return False
return True
@@ -154,14 +163,15 @@
f.write('rdnis=unknown\n')
f.write('priority=2\n')
f.write('callerchan=SIP/ast1-00000000\n')
- f.write('callerid=\"Anonymous\"<ast1>\n')
+ f.write('callerid=\"Anonymous\"<555-5555>\n')
f.write('origdate=Tue Aug 9 10:05:13 PM UTC 2011\n')
f.write('origtime=1312927513\n')
if (folder == self.urgentFolderName):
f.write('flag=Urgent\n')
else:
f.write('flag=\n')
- f.write('duration=1\n')
+ f.write('category=tt-monkeys\n')
+ f.write('duration=6\n')
f.close()
for format in formats:
@@ -215,6 +225,24 @@
"""
fileName = msgName + ".txt"
retVal = retVal & self.checkVoiceFileExists(context, mailbox, fileName, folder)
+
+ return retVal
+
+ """
+ Check if a voicemail greeting exists on the filesystem
+ context The context of the mailbox
+ mailbox The mailbox
+ msgname The name of the greeting to find
+ lstFormats The formats we expect to be recorded for us
+
+ true if the greeting exists, false otherwise
+ """
+ def checkGreetingExists(self, context, mailbox, msgname, lstFormats):
+ retVal = True
+
+ for format in lstFormats:
+ fileName = msgname + "." + format
+ retVal = retVal & self.checkVoiceFileExists(context, mailbox, fileName, "")
return retVal
@@ -248,6 +276,53 @@
return False
"""
+ An object that holds voicemail user information
+ """
+ class UserObject(object):
+ def __init__(self):
+ self.password = ""
+ self.fullname = ""
+ self.emailaddress = ""
+ self.pageraddress = ""
+
+ """
+ Gets user information from the voicemail configuration file
+
+ context The context of the mailbox
+ mailbox The mailbox
+ sourceFile The file containing the user information to pull from. Defaults
+ to voicemail.conf
+
+ returns A VoiceMailMailboxManagement.UserObject object, populated with the user's values,
+ or an empty object
+ """
+ def getUserObject(self, context, mailbox, sourceFile="voicemail.conf"):
+
+ filePath = self.__ast.baseDirectory + self.__ast.directories['astetcdir'] + "/" + sourceFile
+
+ configFile = ConfigFile(filePath)
+ userObject = VoiceMailMailboxManagement.UserObject()
+ for cat in configFile.categories:
+ if cat.name == context:
+ for kvp in cat.options:
+ if kvp[0] == mailbox:
+ tokens = kvp[1].split(',')
+ i = 0
+ for token in tokens:
+ if i == 0:
+ userObject.password = token
+ elif i == 1:
+ userObject.fullname = token
+ elif i == 2:
+ userObject.emailaddress = token
+ elif i == 3:
+ userObject.pageraddress = token
+ i += 1
+ return userObject
+
+ return userObject
+
+ """
Checks if a file exists under the voicemail file structure
context The context of the mailbox
mailbox The mailbox
@@ -266,7 +341,6 @@
return True
else:
return False
-
def __removeItemsFromFolder__(self, mailboxPath, folder):
folderPath = os.path.join(self.__ast.baseDirectory, "%(mp)s/%(f)s" % {'mp':mailboxPath, 'f':folder})
Modified: asterisk/team/group/python_logging/lib/python/client.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/lib/python/client.py?view=diff&rev=1973&r1=1911&r2=1973
==============================================================================
--- asterisk/team/group/python_logging/lib/python/client.py (original)
+++ asterisk/team/group/python_logging/lib/python/client.py Fri Aug 26 14:57:09 2011
@@ -106,8 +106,7 @@
self.ordered = False
def __init__(self, myargv, myasterisk, mytester, mytimeout = 5):
- self.log = logging.getLogger('TestAMI')
- self.log.setLevel(logging.INFO)
+ self.log = logging.getLogger(__name__)
self.ami = None
self.testcount = 0
self.passed = True
Added: asterisk/team/group/python_logging/logger.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/logger.conf?view=auto&rev=1973
==============================================================================
--- asterisk/team/group/python_logging/logger.conf (added)
+++ asterisk/team/group/python_logging/logger.conf Fri Aug 26 14:57:09 2011
@@ -1,0 +1,31 @@
+#
+# Logger configuration for python tests
+#
+
+[loggers]
+keys=root
+
+[handlers]
+keys=stdout
+
+[formatters]
+keys=default
+
+# Logger definitions. Note that a default file handler will be
+# used for all loggers (as defined in TestCase). See
+# lib/python/asterisk/TestCase.py. If additional handlers are desired,
+# they can be configured below this section.
+[logger_root]
+level=INFO
+handlers=stdout
+
+[handler_stdout]
+class=StreamHandler
+level=WARN
+formatter=default
+args=(sys.stdout,)
+
+# Formatter definitions for handlers defined in this configuration file
+[formatter_default]
+format='%(levelname)s %(asctime)s %(name)s::%(funcName)s[%(lineno)d]: %(message)s'
+class=logging.Formatter
Propchange: asterisk/team/group/python_logging/logger.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/team/group/python_logging/logger.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/team/group/python_logging/logger.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: asterisk/team/group/python_logging/runtests.py (from r1972, asterisk/trunk/runtests.py)
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/python_logging/runtests.py?view=diff&rev=1973&p1=asterisk/trunk/runtests.py&r1=1972&p2=asterisk/team/group/python_logging/runtests.py&r2=1973
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/team/group/python_logging/runtests.py Fri Aug 26 14:57:09 2011
@@ -158,10 +158,11 @@
cmd = [
"%s/run-test" % self.test_name,
]
+
if os.path.exists(cmd[0]) and os.access(cmd[0], os.X_OK):
print "Running %s ..." % cmd
try:
- f = open("%s/test-output.txt" % self.test_name, "w")
+ f = open("%s/test-console-output.txt" % self.test_name, "w")
except IOError:
[... 141 lines stripped ...]
More information about the asterisk-commits
mailing list