#!/bin/sh # Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # 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 # ipv6_reservations table must be deleted first, as it has contraints that # are dependent on hosts. Therefore hosts table cannot be deleted before # ipv6_reservations. mysql_execute "DROP TABLE IF EXISTS ipv6_reservations;" # 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 < 4.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 4.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 4.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < 4.0) mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <