Browse Source

- add functions to check for accessible postgres and unixodbc database
to prevent errors if some DB is not installed, change test to use this
- move postgres query command to variable, cleanup 22, 23 and 32
- small comment fix in 37
- add new test for server module loading on unixodbc


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4884 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 years ago
parent
commit
39dbabdf73
6 changed files with 96 additions and 10 deletions
  1. 4 3
      test/unit/22.sh
  2. 4 3
      test/unit/23.sh
  3. 4 3
      test/unit/32.sh
  4. 1 1
      test/unit/37.sh
  5. 48 0
      test/unit/38.sh
  6. 35 0
      test/unit/include/database

+ 4 - 3
test/unit/22.sh

@@ -21,8 +21,9 @@
 
 source include/common
 source include/require
+source include/database
 
-if ! (check_netcat && check_kamailio && check_module "db_postgres"); then
+if ! (check_netcat && check_kamailio && check_module "db_postgres" && check_postgres); then
 	exit 0
 fi ;
 
@@ -46,7 +47,7 @@ if [ "$ret" -eq 0 ] ; then
 	ret=$?
 fi ;
 
-TMP=`PGPASSWORD='openserro' psql -A -t -n -q -h localhost -U openserro openser -c "select COUNT(*) from location where username='1000';" | tail -n 1`
+TMP=`${PSQL} "select COUNT(*) from location where username='1000';"`
 if [ "$TMP" -eq 0 ] ; then
 	ret=1
 fi ;
@@ -64,7 +65,7 @@ if [ "$ret" -eq 0 ] ; then
 	fi ;
 fi ;
 
-ret=`PGPASSWORD='openserro' psql -A -t -n -q -h localhost -U openserro openser -c "select COUNT(*) from location where username='1000';" | tail -n 1`
+ret=`$PSQL "select COUNT(*) from location where username='1000';" | tail -n 1`
 
 killall -9 $BIN
 

+ 4 - 3
test/unit/23.sh

@@ -21,8 +21,9 @@
 
 source include/common
 source include/require
+source include/database
 
-if ! (check_kamailio && check_module "carrierroute" && check_module "db_postgres"); then
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_postgres" && check_postgres); then
 	exit 0
 fi ;
 
@@ -36,7 +37,7 @@ echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
 echo "modparam(\"carrierroute\", \"db_url\", \"postgres://openserro:openserro@localhost/openser\")" >> $CFG
 
 # setup database
-PGPASSWORD='openserrw' psql -A -t -n -q -h localhost -U openser openser -c "insert into route_tree (id, carrier) values ('1', 'carrier1');
+$PSQL "insert into route_tree (id, carrier) values ('1', 'carrier1');
 insert into route_tree (id, carrier) values ('2', 'default');
 insert into route_tree (id, carrier) values ('3', 'premium');
 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('1','1','49','0','0.5','0','host1.local.domain');
@@ -90,7 +91,7 @@ fi ;
 killall -9 $BIN
 
 # cleanup database
-PGPASSWORD='openserrw' psql -A -t -n -q -h localhost -U openser openser -c "delete from route_tree where id = 1;
+$PSQL "delete from route_tree where id = 1;
 delete from route_tree where id = 2;
 delete from route_tree where id = 3;
 delete from carrierroute where carrier=1;

+ 4 - 3
test/unit/32.sh

@@ -21,8 +21,9 @@
 
 source include/common
 source include/require
+source include/database
 
-if ! (check_sipp && check_kamailio && check_module "db_postgres"); then
+if ! (check_sipp && check_kamailio && check_module "db_postgres" && check_postgres); then
 	exit 0
 fi ;
 
@@ -39,7 +40,7 @@ DOMAIN="local"
 COUNTER=0
 while [  $COUNTER -lt 139 ]; do
 	COUNTER=$(($COUNTER+1))
-	PGPASSWORD='openserrw' psql -A -t -n -q -h localhost -U openser openser -c "insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER', '$DOMAIN', 'foobar-$COUNTER@$DOMAIN', '___test___');"
+	$PSQL "insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER', '$DOMAIN', 'foobar-$COUNTER@$DOMAIN', '___test___');"
 done
 
 ../$BIN -w . -f $CFG > /dev/null
@@ -48,7 +49,7 @@ ret=$?
 sleep 1
 killall -9 $BIN
 
-PGPASSWORD='openserrw' psql -A -t -n -q -h localhost -U openser openser -c "delete from location where user_agent = '___test___'"
+$PSQL "delete from location where user_agent = '___test___'"
 
 mv $CFG.bak $CFG
 

+ 1 - 1
test/unit/37.sh

@@ -25,7 +25,7 @@ source include/database
 
 CFG=13.cfg
 # number of routes, multiplied with 10
-# if you want to increase this above 8500, uncomment the fifo command below,
+# if you want to increase this above 8500, comment the fifo command below,
 # otherwise this will fails with memory allocation errors (with 1MB PKG mem)
 NR=850
 

+ 48 - 0
test/unit/38.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+# load all modules without external dependencies with unixodbc
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+# Needs a default kamailio database setup for unixodbc
+
+if ! (check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
+	exit 0
+fi ;
+
+CFG=2.cfg
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_unixodbc/db_unixodbc.so\"" >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"unixodbc://openserro:openserro@localhost/openser\")" >> $CFG
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+killall -9 $BIN
+
+mv $CFG.bak $CFG
+rm -f dispatcher.list
+
+exit $ret

+ 35 - 0
test/unit/include/database

@@ -18,6 +18,11 @@
 
 MYSQL="mysql openser --show-warnings --batch --user=openser --password=openserrw -e"
 
+export PGPASSWORD="openserrw"
+PSQL="psql -A -t -n -q -h localhost -U openser openser -c"
+
+UODBC="isql -b -v openser openser openserrw"
+
 function check_mysql() {
 	$MYSQL "select * from location;" > /dev/null
 	if ! [ "$?" -eq 0 ] ; then
@@ -32,3 +37,33 @@ function check_mysql() {
 	$MYSQL "delete from location where user_agent ='___test___';" > /dev/null
 	return 0
 }
+
+function check_postgres() {
+	$PSQL "select * from location;" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	$PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	$PSQL "delete from location where user_agent ='___test___';" > /dev/null
+	return 0
+}
+
+function check_unixodbc() {
+	echo "select * from location;" | $UODBC  > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $UODBC > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	echo "delete from location where user_agent ='___test___';" | $UODBC > /dev/null
+	return 0
+}