#!/bin/sh # Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC") # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # Include common test library. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh # If the code is installed, include admin-utils.sh from the destination # directory. If not, include it from the sources. prefix=@prefix@ if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh else . @abs_top_srcdir@/src/bin/admin/admin-utils.sh fi db_user="keatest" db_password="keatest" db_name="keatest" # Set location of the kea-admin. keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin # Wipe all tables from the DB: mysql_wipe() { printf "Wiping whole database %s\n" $db_name # First we build the list of drop table commands # We don't bother with "cascade" because as of MySQL # 5.1 it is only there to ease porting, it doesn't # actually do anything. qry="\ SELECT CONCAT('DROP TABLE ', table_schema, '.', table_name, ';') \ FROM information_schema.tables \ WHERE table_schema = 'keatest';" drop_sql=`mysql_execute "${qry}"` ERRCODE=$? assert_eq 0 $ERRCODE "mysql-wipe: table query failed, exit code %d, expected %d" # We need to turn off referrential integrity checks so tables # are dropped regardless of whether they are used in foreign keys. # (This is what cascade would normally do) mysql_execute "SET SESSION FOREIGN_KEY_CHECKS = 0;$drop_sql" ERRCODE=$? assert_eq 0 $ERRCODE "mysql-wipe: drop table sql failed, exit code %d, expected %d" } mysql_lease_init_test() { test_start "mysql.lease-init" # Let's wipe the whole database mysql_wipe # Ok, now let's initalize the database ${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts ERRCODE=$? assert_eq 0 $ERRCODE "kea-admin lease-init mysql returned non-zero status code %d, expected %d" # Ok, now let's check if the tables are indeed there. # First table: schema_version. Should have 2 columns: version and minor. mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 < 2.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 2.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 3.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 3.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 3.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 3.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <