[Asterisk-code-review] CI: Add options to initialize and cleanup database to runTes... (asterisk[16.0])
George Joseph
asteriskteam at digium.com
Wed Jul 25 10:12:52 CDT 2018
George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/9684
Change subject: CI: Add options to initialize and cleanup database to runTestsuite.sh
......................................................................
CI: Add options to initialize and cleanup database to runTestsuite.sh
Change-Id: I352333233bab5377723bf37d490ba84fc55bc853
---
M tests/CI/periodic-dailyTestGroups.json
M tests/CI/runTestsuite.sh
M tests/CI/setupRealtime.sh
M tests/CI/teardownRealtime.sh
4 files changed, 119 insertions(+), 57 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/84/9684/1
diff --git a/tests/CI/periodic-dailyTestGroups.json b/tests/CI/periodic-dailyTestGroups.json
index 01f51d1..9136032 100644
--- a/tests/CI/periodic-dailyTestGroups.json
+++ b/tests/CI/periodic-dailyTestGroups.json
@@ -32,7 +32,7 @@
{
"name": "real",
"dir": "tests/CI/output/realtime",
- "runTestsuiteOptions": "--realtime",
+ "runTestsuiteOptions": "--realtime --initialize-db --cleanup-db",
"testcmd": " -t tests/channels/pjsip -G realtime-incompatible"
}
]
diff --git a/tests/CI/runTestsuite.sh b/tests/CI/runTestsuite.sh
index a8908d4..0778a2b 100755
--- a/tests/CI/runTestsuite.sh
+++ b/tests/CI/runTestsuite.sh
@@ -9,7 +9,7 @@
./cleanup-test-remnants.sh
if [ $REALTIME -eq 1 ] ; then
- $CIDIR/setupRealtime.sh
+ $CIDIR/setupRealtime.sh --initialize-db=${INITIALIZE_DB:?0}
fi
export PYTHONPATH=./lib/python/
@@ -17,7 +17,7 @@
./runtests.py --cleanup ${TESTSUITE_COMMAND} | contrib/scripts/pretty_print --no-color --no-timer --term-width=120 --show-errors || :
if [ $REALTIME -eq 1 ] ; then
- $CIDIR/teardownRealtime.sh
+ $CIDIR/teardownRealtime.sh --cleanup-db=${CLEANUP_DB:?0}
fi
if [ -f core* ] ; then
diff --git a/tests/CI/setupRealtime.sh b/tests/CI/setupRealtime.sh
index f599d33..49ffb8b 100755
--- a/tests/CI/setupRealtime.sh
+++ b/tests/CI/setupRealtime.sh
@@ -1,9 +1,114 @@
#!/usr/bin/env bash
CIDIR=$(dirname $(readlink -fn $0))
+INITIALIZE_DB=0
source $CIDIR/ci.functions
+ASTTOP=$(readlink -fn $CIDIR/../../)
set -e
+POSTGRES_PID=`pidof postgres || : `
+
+if [ -z "$POSTGRES_PID" ] ; then
+ if [ -x /usr/local/bin/postgresql-start ] ; then
+ /usr/local/bin/postgresql-start
+ fi
+fi
+
+POSTGRES_PID=`pidof postgres || : `
+if [ -z "$POSTGRES_PID" ] ; then
+ echo "Postgres isn't running. It must be started manually before this test can continue."
+ exit 1
+fi
+
+if [ $INITIALIZE_DB -gt 0 ] ; then
+ echo "(re)Initializing Database"
+
+ sudo -u postgres dropdb -e asterisk_test >/dev/null 2>&1 || :
+ sudo -u postgres dropuser -e asterisk_test >/dev/null 2>&1 || :
+ sudo -u postgres createuser --username=postgres -RDIElS asterisk_test
+ sudo -u postgres createdb --username=postgres -E UTF-8 -O asterisk_test asterisk_test
+
+ echo "Configuring ODBC"
+
+ sudo odbcinst -u -d -n "PostgreSQL-Asterisk-Test"
+
+ sudo odbcinst -i -d -n "PostgreSQL-Asterisk-Test" -f /dev/stdin <<-EOF
+ [PostgreSQL-Asterisk-Test]
+ Description=PostgreSQL ODBC driver (Unicode version)
+ Driver=psqlodbcw.so
+ Setup=libodbcpsqlS.so
+ Debug=0
+ CommLog=1
+ UsageCount=1
+ EOF
+
+ sudo odbcinst -u -s -l -n asterisk-connector-test
+ sudo odbcinst -i -s -l -n asterisk-connector-test -f /dev/stdin <<-EOF
+ [asterisk-connector-test]
+ Description = PostgreSQL connection to 'asterisk' database
+ Driver = PostgreSQL-Asterisk-Test
+ Database = asterisk_test
+ Servername = 127.0.0.1
+ UserName = asterisk_test
+ Port = 5432
+ Protocol = 9.1
+ ReadOnly = No
+ RowVersioning = No
+ ShowSystemTables = No
+ ShowOldColumn = No
+ FakeOldIndex = No
+ ConnSettings =
+ EOF
+fi
+
+cat >/tmp/config.ini <<-EOF
+ [alembic]
+ script_location = config
+ sqlalchemy.url = postgresql://asterisk_test@localhost/asterisk_test
+
+ [loggers]
+ keys = root,sqlalchemy,alembic
+
+ [handlers]
+ keys = console
+
+ [formatters]
+ keys = generic
+
+ [logger_root]
+ level = WARN
+ handlers = console
+ qualname =
+
+ [logger_sqlalchemy]
+ level = WARN
+ handlers =
+ qualname = sqlalchemy.engine
+
+ [logger_alembic]
+ level = INFO
+ handlers =
+ qualname = alembic
+
+ [handler_console]
+ class = StreamHandler
+ args = (sys.stderr,)
+ level = NOTSET
+ formatter = generic
+
+ [formatter_generic]
+ format = %(levelname)-5.5s [%(name)s] %(message)s
+ datefmt = %H:%M:%S
+EOF
+
+pushd $ASTTOP/contrib/ast-db-manage
+
+psql --username=asterisk_test --host=localhost --db=asterisk_test --command='DROP OWNED BY asterisk_test CASCADE'
+alembic -c /tmp/config.ini upgrade head
+rm -rf /tmp/config.ini || :
+
+popd
+
cp test-config.yaml test-config.orig.yaml
cat >test-config.yaml <<-EOF
@@ -65,59 +170,10 @@
config-section: realtime-config
realtime-config:
- username: "asterisk"
+ username: "asterisk_test"
+ password: "asterisk_test"
host: "localhost"
- db: "asterisk"
- dsn: "asterisk-connector"
+ db: "asterisk_test"
+ dsn: "asterisk-connector-test"
EOF
-ASTTOP=$(readlink -fn $CIDIR/../../)
-
-cat >/tmp/config.ini <<-EOF
- [alembic]
- script_location = config
- sqlalchemy.url = postgresql://asterisk@localhost/asterisk
-
- [loggers]
- keys = root,sqlalchemy,alembic
-
- [handlers]
- keys = console
-
- [formatters]
- keys = generic
-
- [logger_root]
- level = WARN
- handlers = console
- qualname =
-
- [logger_sqlalchemy]
- level = WARN
- handlers =
- qualname = sqlalchemy.engine
-
- [logger_alembic]
- level = INFO
- handlers =
- qualname = alembic
-
- [handler_console]
- class = StreamHandler
- args = (sys.stderr,)
- level = NOTSET
- formatter = generic
-
- [formatter_generic]
- format = %(levelname)-5.5s [%(name)s] %(message)s
- datefmt = %H:%M:%S
-EOF
-
-pushd $ASTTOP/contrib/ast-db-manage
-if [ -x /usr/local/bin/postgresql-start ] ; then
- /usr/local/bin/postgresql-start
-fi
-psql --username=asterisk --host=localhost --db=asterisk --command='DROP OWNED BY asterisk CASCADE'
-alembic -c /tmp/config.ini upgrade head
-rm -rf /tmp/config.ini || :
-popd
diff --git a/tests/CI/teardownRealtime.sh b/tests/CI/teardownRealtime.sh
index 1114699..8687706 100755
--- a/tests/CI/teardownRealtime.sh
+++ b/tests/CI/teardownRealtime.sh
@@ -1,6 +1,12 @@
#!/usr/bin/env bash
CIDIR=$(dirname $(readlink -fn $0))
+CLEANUP_DB=0
source $CIDIR/ci.functions
cp test-config.orig.yaml test-config.yaml
-psql --username=asterisk --host=localhost --db=asterisk --command='DROP OWNED BY asterisk CASCADE'
+if [ $CLEANUP_DB -gt 0 ] ; then
+ sudo -u postgres dropdb -e asterisk_test >/dev/null 2>&1 || :
+ sudo -u postgres dropuser -e asterisk_test >/dev/null 2>&1 || :
+ sudo odbcinst -u -d -n "PostgreSQL-Asterisk-Test"
+ sudo odbcinst -u -s -l -n "asterisk-connector-test"
+fi
--
To view, visit https://gerrit.asterisk.org/9684
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16.0
Gerrit-MessageType: newchange
Gerrit-Change-Id: I352333233bab5377723bf37d490ba84fc55bc853
Gerrit-Change-Number: 9684
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180725/1f1f8841/attachment.html>
More information about the asterisk-code-review
mailing list