Skip to content

Commit 0ea184b

Browse files
committed
testuite: Python3 support
ASTERISK-26826 Change-Id: Id22c8f7a89e2d00fca760970af63f3954c049bf3
1 parent 1c9359c commit 0ea184b

File tree

284 files changed

+11966
-5009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+11966
-5009
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ crash-mail-config.yaml
99
/fastagi
1010
/run-local.conf
1111
/.valgrindrc
12+
/.venv
1213
__pycache__/

addons/Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ distclean: _clean
2323
rm -rf starpy/install.record
2424

2525
install:
26-
(cd starpy; python setup.py install --prefix=~/.local --record install.record)
26+
(cd starpy; python3 setup.py install --prefix=~/.local --record install.record)
2727

2828
uninstall:
2929
rm -rf $$(cat starpy/install.record)
3030

3131
update:
3232
@if [ -d starpy ]; then \
3333
cd starpy; \
34-
if [ `git config --get remote.origin.url` = git://github.com/asterisk-org/starpy.git ]; then \
35-
git remote set-url origin git://github.com/asterisk/starpy.git git://github.com/asterisk-org/starpy.git; \
34+
if [ `git config --get remote.origin.url` = https://github.com/asterisk-org/starpy.git ]; then \
35+
git remote set-url origin https://github.com/asterisk/starpy.git https://github.com/asterisk-org/starpy.git; \
3636
fi; \
37+
git checkout 1.1; \
3738
git pull; \
3839
else \
39-
git clone git://github.com/asterisk/starpy.git; \
40+
git clone https://github.com/asterisk/starpy.git; \
41+
git checkout 1.1; \
4042
fi

contrib/scripts/cel-to-yaml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main(argv=None):
4848
result.append(blob)
4949
raw_yaml = yaml.dump(result)
5050
raw_yaml = raw_yaml.replace(',', '\n').replace('}', '').replace('{', '')
51-
print raw_yaml
51+
print(raw_yaml)
5252

5353
return 0
5454

contrib/scripts/install_prereq

+5-50
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@ usage() {
1515
# Basic build system:
1616
PACKAGES_DEBIAN="subversion git build-essential automake"
1717
# Python tools
18-
PACKAGES_DEBIAN="$PACKAGES_DEBIAN python python-pip python-setuptools python-dev cython"
18+
PACKAGES_DEBIAN="$PACKAGES_DEBIAN python3 python3-pip python3-setuptools python3-dev"
1919
# Testsuite: basic requirements:
20-
PACKAGES_DEBIAN="$PACKAGES_DEBIAN python-yaml python-twisted-core python-lxml liblua5.1-0-dev lua5.1 gdb"
20+
PACKAGES_DEBIAN="$PACKAGES_DEBIAN liblua5.1-0-dev lua5.1 gdb"
2121
# Sipp requirements
2222
PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpcap-dev libssl-dev libsctp-dev libncurses5-dev"
23-
# pjsua requirements
24-
#PACKAGES_DEBIAN="$PACKAGES_DEBIAN python-dev"
2523

2624
# Basic build system:
2725
PACKAGES_RH="subversion git gcc gcc-c++ patch"
2826
# Python tools
29-
PACKAGES_RH="$PACKAGES_RH python python-pip python-setuptools python-devel Cython"
27+
PACKAGES_RH="$PACKAGES_RH python3 python3-pip python3-setuptools python3-devel"
3028
# Testsuite: basic requirements:
31-
PACKAGES_RH="$PACKAGES_RH PyYAML python-twisted-core python-lxml lua-devel gdb"
29+
PACKAGES_RH="$PACKAGES_RH lua-devel gdb"
3230
# Sipp requirements
3331
PACKAGES_RH="$PACKAGES_RH libpcap-devel openssl-devel lksctp-tools-devel"
34-
# pjsua requirements
35-
#PACKAGES_RH="$PACKAGES_RH python-devel"
3632

3733
LIBDIR=/usr/lib$(getconf LONG_BIT | fgrep 64)
3834
[ ! -d $LIBDIR ] && LIBDIR=/usr/lib
@@ -145,38 +141,13 @@ else
145141
exit 1
146142
fi
147143

148-
install_starpy() {
149-
$testcmd cd addons
150-
$testcmd make update
151-
$testcmd cd starpy
152-
$testcmd sudo python setup.py install
153-
$testcmd cd ../..
154-
}
155-
156144
install_asttest() {
157145
$testcmd cd asttest
158146
$testcmd make
159147
$testcmd sudo make install
160148
$testcmd cd ..
161149
}
162150

163-
# Build and install yappcap
164-
install_yappcap() {
165-
SAVE_DIR=`pwd`
166-
$testcmd cd /tmp
167-
168-
PROJECT_DIR=yappcap
169-
170-
$testcmd sudo rm -rf $PROJECT_DIR
171-
$testcmd git clone https://github.com/otherwiseguy/yappcap $PROJECT_DIR
172-
$testcmd cd $PROJECT_DIR
173-
174-
$testcmd make
175-
$testcmd sudo make install
176-
177-
$testcmd cd $SAVE_DIR
178-
}
179-
180151
# Build and install sipp
181152
install_sipp() {
182153
SAVE_DIR=`pwd`
@@ -223,7 +194,6 @@ install_pjsua() {
223194

224195
# The testsuite only cares about pjsua from what we have built.
225196
$testcmd sudo cp -v pjsip-apps/bin/pjsua-`uname -m`-*-linux-gnu $MY_BIN/pjsua
226-
$testcmd sudo make -C pjsip-apps/src/python install
227197

228198
$testcmd cd $SAVE_DIR
229199
}
@@ -232,24 +202,9 @@ install_testsuite_dependencies()
232202
{
233203
$install_packages
234204

235-
if [ "x`find $LIBDIR/python* $LIBLOCALDIR/python* -name 'starpy*'`" = "x" ] ; then
236-
install_starpy
237-
fi
238-
239-
if [ "x`find $LIBDIR/python* $LIBLOCALDIR/python* -name yappcap.so`" = "x" ] ; then
240-
install_yappcap
241-
fi
242-
243205
which asttest > /dev/null || install_asttest
244206
which sipp > /dev/null || install_sipp
245207
which pjsua > /dev/null || install_pjsua
246-
247-
$testcmd sudo pip install construct
248-
$testcmd sudo pip install requests
249-
250-
# The following is needed for ARI tests and may not install
251-
# on older distributions.
252-
$testcmd sudo pip install autobahn
253208
}
254209

255210
if in_test_mode; then
@@ -266,7 +221,7 @@ if ! in_test_mode; then
266221
echo "## $1 completed successfully"
267222
echo "#############################################"
268223
echo ""
269-
echo "Testsuite requires 2.6.5 <= python version < 3"
224+
echo "Testsuite requires python version >= 3.6.8"
270225
echo "Your installed python is"
271226
python --version
272227
fi

contrib/scripts/rlmi_demo.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,46 @@
2323
list_elem = rlmi.CreateFromDocument(xml)
2424

2525
# The outermost XML element in an RLMI document is the 'list' element.
26-
print 'list'
26+
print('list')
2727
# pyxb performs type-checking and type conversion of elements that it comes
2828
# across in XML documents. In this case, the list element's version attribute is
2929
# an integer, and the fullState attribute is a boolean. This is why the str()
3030
# function is necessary in order to convert to string for the concatenation.
31-
print '\t' + str(list_elem.version)
32-
print '\t' + str(list_elem.fullState)
33-
print '\t' + list_elem.uri
31+
print('\t' + str(list_elem.version))
32+
print('\t' + str(list_elem.fullState))
33+
print('\t' + list_elem.uri)
3434
# A list element may have zero or more name elements in it. This is a
3535
# user-visible name for the list. The main reason why more than one name may
3636
# exist for a list would be because it is expressed in multiple languages.
3737
# Asterisk RLMI lists will have only a single name.
3838
for name in list_elem.name:
39-
print '\tname'
39+
print('\tname')
4040
# Parsed XML documents have their attributes accessed as members on an
4141
# object.
42-
print '\t\t' + name.lang
42+
print('\t\t' + name.lang)
4343
# The content of XML elements is accessed through the value() member.
44-
print '\t\t' + name.value()
44+
print('\t\t' + name.value())
4545
# A list element may have zero or more resource elements in it. The resources
4646
# represent the resources that make up the list (duh).
4747
for resource in list_elem.resource:
48-
print '\tresource'
49-
print '\t\t' + resource.uri
48+
print('\tresource')
49+
print('\t\t' + resource.uri)
5050
# Resources may have names associated with them, just like the list does.
5151
# Asterisk will use the name of the list from the configuration file here.
5252
for name in resource.name:
53-
print '\t\tname'
54-
print '\t\t\t' + name.value()
53+
print('\t\tname')()
54+
print('\t\t\t' + name.value())
5555
# Resources may have zero or more instance elements on them. The reason that
5656
# more than one instance element may exist for a resource is that a resource
5757
# may correspond to a single subscription that forks, resulting in multiple
5858
# instances of the resource being represented. In Asterisk's case, there
5959
# will be a single instance per resource.
6060
for instance in resource.instance:
61-
print '\t\tinstance'
62-
print '\t\t\t' + instance.id
63-
print '\t\t\t' + instance.state
61+
print('\t\tinstance')
62+
print('\t\t\t' + instance.id)
63+
print('\t\t\t' + instance.state)
6464
# If an instance has a cid, it indicates that there is a body element
6565
# in the multipart body that corresponds to the instance. The cid
6666
# corresponds to the Content-ID header in that body part.
6767
if instance.cid:
68-
print '\t\t\t' + instance.cid
68+
print('\t\t\t' + instance.cid)

extras.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://github.com/asterisk/starpy/archive/refs/heads/1.1.zip
2+
https://github.com/asterisk/yappcap/archive/refs/heads/python3.zip

lib/python/asterisk/astconfigparser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def keys(self, self_only=False):
119119
for key in d.keys():
120120
if key not in res:
121121
res.append(key)
122-
return res
122+
return list(res.keys())
123123

124124
def add_defaults(self, defaults):
125125
"""

lib/python/asterisk/astdicts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ def __init__(self, *args, **kwds):
271271

272272
def __setitem__(self, key, val, i=None):
273273
if key not in self:
274-
# print "__setitem__ key = ", key, " val = ", val
274+
# print("__setitem__ key = ", key, " val = ", val)
275275
OrderedDict.__setitem__(
276276
self, key, val if isinstance(val, list) else [val])
277277
return
278-
# print "inserting key = ", key, " val = ", val
278+
# print("inserting key = ", key, " val = ", val)
279279
vals = self[key]
280280
if i is None:
281281
i = len(vals)

lib/python/asterisk/asterisk.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def connectionMade(self):
243243

244244
def errReceived(self, data):
245245
"""Override of ProcessProtocol.errReceived"""
246-
LOGGER.warn("Asterisk %s received error: %s" % (self._host, data))
246+
LOGGER.warn("Asterisk %s received error: %s" % (self._host, data.decode('utf-8', 'ignore')))
247247

248248
def processEnded(self, reason):
249249
"""Override of ProcessProtocol.processEnded"""
@@ -464,8 +464,12 @@ def __start_asterisk_callback(cmd):
464464
self.process = reactor.spawnProcess(self.protocol,
465465
cmd[0],
466466
cmd, env=os.environ)
467-
# Begin the wait fully booted cycle
468-
reactor.callLater(1, __execute_wait_fully_booted)
467+
# This was a one second delay, now two. This is to allow
468+
# asterisk sufficient time to actually start and create the ctl
469+
# file. If we try to send the fully booted command before this
470+
# happens we wait and try again, but this results in an unhandled
471+
# error in twisted after the command succeeds.
472+
reactor.callLater(2, __execute_wait_fully_booted)
469473

470474
def __execute_wait_fully_booted():
471475
"""Send the CLI command waitfullybooted"""
@@ -496,8 +500,9 @@ def __wait_fully_booted_error(cli_command):
496500
LOGGER.error(msg)
497501
self._start_deferred.errback(Exception(msg))
498502
else:
499-
msg = "Asterisk core waitfullybooted failed, attempting again"
500-
LOGGER.debug(msg)
503+
LOGGER.debug("Asterisk core waitfullybooted failed " +
504+
"with output '%s', attempting again..." %
505+
cli_command.value.err.decode('utf-8'))
501506
reactor.callLater(1, __execute_wait_fully_booted)
502507
return cli_command
503508

0 commit comments

Comments
 (0)