| 1 | #!/usr/bin/env bash |
| 2 | CIDIR=$(dirname $(readlink -fn $0)) |
| 3 | INITIALIZE_DB=0 |
| 4 | source $CIDIR/ci.functions |
| 5 | ASTTOP=$(readlink -fn $CIDIR/../../) |
| 6 | |
| 7 | set -e |
| 8 | |
| 9 | POSTGRES_PID=`pidof postgres || : ` |
| 10 | |
| 11 | if [ -z "$POSTGRES_PID" ] ; then |
| 12 | if [ -x /usr/local/bin/postgresql-start ] ; then |
| 13 | /usr/local/bin/postgresql-start |
| 14 | fi |
| 15 | fi |
| 16 | |
| 17 | POSTGRES_PID=`pidof postgres || : ` |
| 18 | if [ -z "$POSTGRES_PID" ] ; then |
| 19 | echo "Postgres isn't running. It must be started manually before this test can continue." |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | if [ $INITIALIZE_DB -gt 0 ] ; then |
| 24 | echo "(re)Initializing Database" |
| 25 | |
| 26 | sudo -u postgres dropdb -e asterisk_test >/dev/null 2>&1 || : |
| 27 | sudo -u postgres dropuser -e asterisk_test >/dev/null 2>&1 || : |
| 28 | sudo -u postgres createuser --username=postgres -RDIElS asterisk_test |
| 29 | sudo -u postgres createdb --username=postgres -E UTF-8 -O asterisk_test asterisk_test |
| 30 | |
| 31 | echo "Configuring ODBC" |
| 32 | |
| 33 | sudo odbcinst -u -d -n "PostgreSQL-Asterisk-Test" |
| 34 | |
| 35 | sudo odbcinst -i -d -n "PostgreSQL-Asterisk-Test" -f /dev/stdin <<-EOF |
| 36 | [PostgreSQL-Asterisk-Test] |
| 37 | Description=PostgreSQL ODBC driver (Unicode version) |
| 38 | Driver=psqlodbcw.so |
| 39 | Setup=libodbcpsqlS.so |
| 40 | Debug=0 |
| 41 | CommLog=1 |
| 42 | UsageCount=1 |
| 43 | EOF |
| 44 | |
| 45 | sudo odbcinst -u -s -l -n asterisk-connector-test |
| 46 | sudo odbcinst -i -s -l -n asterisk-connector-test -f /dev/stdin <<-EOF |
| 47 | [asterisk-connector-test] |
| 48 | Description = PostgreSQL connection to 'asterisk' database |
| 49 | Driver = PostgreSQL-Asterisk-Test |
| 50 | Database = asterisk_test |
| 51 | Servername = 127.0.0.1 |
| 52 | UserName = asterisk_test |
| 53 | Port = 5432 |
| 54 | Protocol = 9.1 |
| 55 | ReadOnly = No |
| 56 | RowVersioning = No |
| 57 | ShowSystemTables = No |
| 58 | ShowOldColumn = No |
| 59 | FakeOldIndex = No |
| 60 | ConnSettings = |
| 61 | EOF |
| 62 | fi |
| 63 | |
| 64 | cat >/tmp/config.ini <<-EOF |
| 65 | [alembic] |
| 66 | script_location = config |
| 67 | sqlalchemy.url = postgresql://asterisk_test@localhost/asterisk_test |
| 68 | |
| 69 | [loggers] |
| 70 | keys = root,sqlalchemy,alembic |
| 71 | |
| 72 | [handlers] |
| 73 | keys = console |
| 74 | |
| 75 | [formatters] |
| 76 | keys = generic |
| 77 | |
| 78 | [logger_root] |
| 79 | level = WARN |
| 80 | handlers = console |
| 81 | qualname = |
| 82 | |
| 83 | [logger_sqlalchemy] |
| 84 | level = WARN |
| 85 | handlers = |
| 86 | qualname = sqlalchemy.engine |
| 87 | |
| 88 | [logger_alembic] |
| 89 | level = INFO |
| 90 | handlers = |
| 91 | qualname = alembic |
| 92 | |
| 93 | [handler_console] |
| 94 | class = StreamHandler |
| 95 | args = (sys.stderr,) |
| 96 | level = NOTSET |
| 97 | formatter = generic |
| 98 | |
| 99 | [formatter_generic] |
| 100 | format = %(levelname)-5.5s [%(name)s] %(message)s |
| 101 | datefmt = %H:%M:%S |
| 102 | EOF |
| 103 | |
| 104 | pushd $ASTTOP/contrib/ast-db-manage |
| 105 | |
| 106 | psql --username=asterisk_test --host=localhost --db=asterisk_test --command='DROP OWNED BY asterisk_test CASCADE' |
| 107 | alembic -c /tmp/config.ini upgrade head |
| 108 | rm -rf /tmp/config.ini || : |
| 109 | |
| 110 | popd |
| 111 | |
| 112 | cp test-config.yaml test-config.orig.yaml |
| 113 | |
| 114 | cat >test-config.yaml <<-EOF |
| 115 | global-settings: |
| 116 | test-configuration: config-realtime |
| 117 | |
| 118 | condition-definitions: |
| 119 | - |
| 120 | name: 'threads' |
| 121 | pre: |
| 122 | typename: 'thread_test_condition.ThreadPreTestCondition' |
| 123 | post: |
| 124 | typename: 'thread_test_condition.ThreadPostTestCondition' |
| 125 | related-type: 'thread_test_condition.ThreadPreTestCondition' |
| 126 | - |
| 127 | name: 'sip-dialogs' |
| 128 | pre: |
| 129 | typename: 'sip_dialog_test_condition.SipDialogPreTestCondition' |
| 130 | post: |
| 131 | typename: 'sip_dialog_test_condition.SipDialogPostTestCondition' |
| 132 | - |
| 133 | name: 'locks' |
| 134 | pre: |
| 135 | typename: 'lock_test_condition.LockTestCondition' |
| 136 | post: |
| 137 | typename: 'lock_test_condition.LockTestCondition' |
| 138 | - |
| 139 | name: 'file-descriptors' |
| 140 | pre: |
| 141 | typename: 'fd_test_condition.FdPreTestCondition' |
| 142 | post: |
| 143 | typename: 'fd_test_condition.FdPostTestCondition' |
| 144 | related-type: 'fd_test_condition.FdPreTestCondition' |
| 145 | - |
| 146 | name: 'channels' |
| 147 | pre: |
| 148 | typename: 'channel_test_condition.ChannelTestCondition' |
| 149 | post: |
| 150 | typename: 'channel_test_condition.ChannelTestCondition' |
| 151 | - |
| 152 | name: 'sip-channels' |
| 153 | pre: |
| 154 | typename: 'sip_channel_test_condition.SipChannelTestCondition' |
| 155 | post: |
| 156 | typename: 'sip_channel_test_condition.SipChannelTestCondition' |
| 157 | - |
| 158 | name: 'memory' |
| 159 | pre: |
| 160 | typename: 'memory_test_condition.MemoryPreTestCondition' |
| 161 | post: |
| 162 | typename: 'memory_test_condition.MemoryPostTestCondition' |
| 163 | related-type: 'memory_test_condition.MemoryPreTestCondition' |
| 164 | |
| 165 | config-realtime: |
| 166 | test-modules: |
| 167 | modules: |
| 168 | - |
| 169 | typename: realtime_converter.RealtimeConverter |
| 170 | config-section: realtime-config |
| 171 | |
| 172 | realtime-config: |
| 173 | username: "asterisk_test" |
| 174 | password: "asterisk_test" |
| 175 | host: "localhost" |
| 176 | db: "asterisk_test" |
| 177 | dsn: "asterisk-connector-test" |
| 178 | EOF |
| 179 |