Skip to content

Commit 80529b2

Browse files
Updates for running the testsuite using realtime database
* Fix python3 MultiOrderedDict.keys() issue in astconfigparser.py. * Updated realtime_converter.py to be compatible with SQLAlchemy 2. * Added requirements-realtime.txt to install SQLAlchemy, alembic and psycopg2. * Updated setupVenv.sh to install from requirements-realtime.txt if the `--realtime` argument was passed in.
1 parent afc0cbf commit 80529b2

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

lib/python/asterisk/astconfigparser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def keys(self, self_only=False):
106106
keys from this section's defaults and templates are not
107107
included in the returned value
108108
"""
109-
res = MultiOrderedDict.keys(self)
109+
res = list(MultiOrderedDict.keys(self))
110110
if self_only:
111111
return res
112112

@@ -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 list(res.keys())
122+
return res
123123

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

lib/python/asterisk/realtime_converter.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def write_db(self, config_dir, meta, engine, conn, test_object):
151151
"type {0}".format(obj_type))
152152
continue
153153
table = Table(self.sections[sorcery_section][obj_type], meta,
154-
autoload=True, autoload_with=engine)
154+
autoload_with=engine)
155155
vals = {'id': title}
156156
for key in section.keys():
157157
key_name = test_object.ast[0].configuration_replace_string(key)
@@ -190,10 +190,9 @@ def cleanup_db(self, meta, engine, conn):
190190
conn: sqlalchemy Connection to database
191191
"""
192192
for table_name in self.tables:
193-
table = Table(table_name, meta, autoload=True,
194-
autoload_with=engine)
193+
table = Table(table_name, meta, autoload_with=engine)
195194
conn.execute(table.delete())
196-
195+
conn.commit()
197196

198197
class RealtimeConverter(object):
199198
"""Pluggable module used to convert configuration files to database data.
@@ -302,9 +301,14 @@ def write_modules_conf(self):
302301

303302
def write_db(self, test_object):
304303
"""Tell converters to write database information"""
305-
for realtime_file in REALTIME_FILE_REGISTRY:
306-
realtime_file.write_db(self.config_dir, self.meta, self.engine,
307-
self.conn, test_object)
304+
try:
305+
for realtime_file in REALTIME_FILE_REGISTRY:
306+
realtime_file.write_db(self.config_dir, self.meta, self.engine,
307+
self.conn, test_object)
308+
except:
309+
self.conn.rollback()
310+
raise
311+
self.conn.commit()
308312

309313
def cleanup(self, result):
310314
"""Cleanup information after test has completed.

requirements-realtime.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These packages are required if running the testsuite with
2+
# the realtime_converter
3+
SQLAlchemy==2.0.30
4+
alembic==1.13.1
5+
psycopg2==2.9.9

setupVenv.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
REALTIME=false
5+
declare -a VENV_ARGS
6+
7+
for a in "$@" ; do
8+
if [ "$a" == "--realtime" ] ; then
9+
REALTIME=true
10+
else
11+
VENV_ARGS+=( "$a" )
12+
fi
13+
done
14+
415
function do_pip_setup {
516
python3 -m pip install --upgrade pip
617
python3 -m pip install wheel setuptools build
718
python3 -m pip install -r ./requirements.txt
819
python3 -m pip install -r ./extras.txt
9-
md5sum requirements.txt extras.txt > $1/checksums
20+
$REALTIME && python3 -m pip install -r ./requirements-realtime.txt
21+
md5sum requirements.txt extras.txt requirements-realtime.txt > $1/checksums
1022
}
1123

12-
1324
if [[ "$VIRTUAL_ENV" != "" ]]
1425
then
1526
echo "Detected activated virtual environment:" $VIRTUAL_ENV
1627
echo "Skipping creation of new environment, configuring"
1728
do_pip_setup $VIRTUAL_ENV
1829
else
19-
python3 -m venv $@ .venv
30+
python3 -m venv ${VENV_ARGS[@]} .venv
2031
source .venv/bin/activate
2132
echo "Activated virtual environment:" $VIRTUAL_ENV
2233
if [[ "$VIRTUAL_ENV" != "" ]]

0 commit comments

Comments
 (0)