CI: Add options to initialize and cleanup database to runTestsuite.sh
authorGeorge Joseph <gjoseph@digium.com>
Tue, 24 Jul 2018 18:29:19 +0000 (12:29 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 25 Jul 2018 15:10:20 +0000 (09:10 -0600)
Change-Id: I352333233bab5377723bf37d490ba84fc55bc853

tests/CI/periodic-dailyTestGroups.json
tests/CI/runTestsuite.sh
tests/CI/setupRealtime.sh
tests/CI/teardownRealtime.sh

index 01f51d1..9136032 100644 (file)
@@ -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"
        }
 ]
index a8908d4..0778a2b 100755 (executable)
@@ -9,7 +9,7 @@ pushd $TESTSUITE_DIR
 ./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 @@ echo "Running tests ${TESTSUITE_COMMAND}"
 ./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
index f599d33..49ffb8b 100755 (executable)
@@ -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 @@ cat >test-config.yaml <<-EOF
                        config-section: realtime-config
                
            realtime-config:
-               username: "asterisk"
+               username: "asterisk_test"
+               password: "asterisk_test"
                host: "localhost"
-               db: "asterisk"
-               dsn: "asterisk-connector"
-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
+               db: "asterisk_test"
+               dsn: "asterisk-connector-test"
 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
index 1114699..8687706 100755 (executable)
@@ -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