setupRealtime.sh 4.9 KB

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