[svn-commits] pabelanger: testsuite/asterisk/trunk r851 - in /asterisk/trunk: ./ lib/python...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Nov 17 14:49:36 CST 2010
Author: pabelanger
Date: Wed Nov 17 14:49:30 2010
New Revision: 851
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=851
Log:
A new library for testsuite utilites.
Also includes better handling of finding the 'asterisk'
binary. This should help with CentOS builds using sudo.
Review: https://reviewboard.asterisk.org/r/1015/
Added:
asterisk/trunk/lib/python/asterisk/utils.py (with props)
Modified:
asterisk/trunk/lib/python/asterisk/__init__.py
asterisk/trunk/lib/python/asterisk/asterisk.py
asterisk/trunk/runtests.py
Modified: asterisk/trunk/lib/python/asterisk/__init__.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/__init__.py?view=diff&rev=851&r1=850&r2=851
==============================================================================
--- asterisk/trunk/lib/python/asterisk/__init__.py (original)
+++ asterisk/trunk/lib/python/asterisk/__init__.py Wed Nov 17 14:49:30 2010
@@ -1,1 +1,1 @@
-__all__ = [ "asterisk", "config", "version", "cdr" ]
+__all__ = [ "asterisk", "config", "version", "cdr", "utils" ]
Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=851&r1=850&r2=851
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Wed Nov 17 14:49:30 2010
@@ -17,9 +17,9 @@
import time
import shutil
import subprocess
+import utils
from config import ConfigFile
-
from version import AsteriskVersion
@@ -60,6 +60,8 @@
self.ast_version = AsteriskVersion()
self.astetcdir = "/etc/asterisk"
+ self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
+
# Find the system installed asterisk.conf
ast_confs = [
"/etc/asterisk/asterisk.conf",
@@ -107,11 +109,16 @@
asterisk.start()
"""
cmd = [
- "asterisk",
+ self.ast_binary,
"-f", "-g", "-q", "-m", "-n",
"-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf")
]
- self.process = subprocess.Popen(cmd)
+ try:
+ self.process = subprocess.Popen(cmd)
+ except OSError:
+ print "Failed to execute command: %s" % str(cmd)
+ return False
+
# Be _really_ sure that Asterisk has started up before returning.
time.sleep(5.0)
self.cli_exec("core waitfullybooted")
@@ -295,7 +302,7 @@
asterisk.cli_exec("core set verbose 10")
"""
cmd = [
- "asterisk",
+ self.ast_binary,
"-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf"),
"-rx", "%s" % cli_cmd
]
Added: asterisk/trunk/lib/python/asterisk/utils.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/utils.py?view=auto&rev=851
==============================================================================
--- asterisk/trunk/lib/python/asterisk/utils.py (added)
+++ asterisk/trunk/lib/python/asterisk/utils.py Wed Nov 17 14:49:30 2010
@@ -1,0 +1,32 @@
+#! /usr/bin/env python
+""" Asterisk testsuite utils
+
+This module provides access to Asterisk testsuite utility
+functions from within python code.
+
+Copyright (C) 2010, Digium, Inc.
+Paul Belanger <pabelanger at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+import os
+
+
+def which(program):
+ '''
+ http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
+ '''
+ def is_exe(fpath):
+ return os.path.exists(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
Propchange: asterisk/trunk/lib/python/asterisk/utils.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/lib/python/asterisk/utils.py
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/lib/python/asterisk/utils.py
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=851&r1=850&r2=851
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Wed Nov 17 14:49:30 2010
@@ -20,6 +20,7 @@
from asterisk.version import AsteriskVersion
from asterisk.asterisk import Asterisk
+from asterisk import utils
TESTS_CONFIG = "tests/tests.yaml"
@@ -41,7 +42,7 @@
self.met = False
if "app" in dep:
self.name = dep["app"]
- self.met = self.__which(self.name) is not None
+ self.met = utils.which(self.name) is not None
elif "python" in dep:
self.name = dep["python"]
try:
@@ -62,25 +63,6 @@
else:
print "Unknown dependency type specified."
- def __which(self, program):
- '''
- http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
- '''
- def is_exe(fpath):
- return os.path.exists(fpath) and os.access(fpath, os.X_OK)
-
- fpath, fname = os.path.split(program)
- if fpath:
- if is_exe(program):
- return program
- else:
- for path in os.environ["PATH"].split(os.pathsep):
- exe_file = os.path.join(path, program)
- if is_exe(exe_file):
- return exe_file
-
- return None
-
def depend_ipv6(self):
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
@@ -95,7 +77,7 @@
we run pjsua --help and parse the output to determine if --ipv6
is a valid option
'''
- if self.__which('pjsua') is None:
+ if utils.which('pjsua') is None:
return False
help_output = subprocess.Popen(['pjsua', '--help'],
More information about the svn-commits
mailing list