Commit 0b4ec962 authored by Thomas Markwalder's avatar Thomas Markwalder

[4239] Moved schema scripts to src/share/database/scripts

    Moved schema scripts into a new common location:

        src/share/database/scripts

    to make them accessible to both kea-admin and dhcpsrv testing
parent 5b978dab
......@@ -1404,19 +1404,11 @@ AC_CONFIG_FILES([compatcheck/Makefile
src/bin/perfdhcp/tests/testdata/Makefile
src/bin/admin/Makefile
src/bin/admin/kea-admin
src/bin/admin/scripts/Makefile
src/bin/admin/tests/Makefile
src/bin/admin/tests/data/Makefile
src/bin/admin/tests/memfile_tests.sh
src/bin/admin/tests/mysql_tests.sh
src/bin/admin/tests/pgsql_tests.sh
src/bin/admin/scripts/mysql/Makefile
src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh
src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh
src/bin/admin/scripts/mysql/upgrade_4.0_to_4.1.sh
src/bin/admin/scripts/pgsql/Makefile
src/bin/admin/scripts/pgsql/upgrade_1.0_to_2.0.sh
src/hooks/Makefile
src/hooks/dhcp/Makefile
src/hooks/dhcp/user_chk/Makefile
......@@ -1483,6 +1475,16 @@ AC_CONFIG_FILES([compatcheck/Makefile
src/lib/util/unittests/Makefile
src/lib/eval/Makefile
src/lib/eval/tests/Makefile
src/share/Makefile
src/share/database/Makefile
src/share/database/scripts/Makefile
src/share/database/scripts/mysql/Makefile
src/share/database/scripts/mysql/upgrade_1.0_to_2.0.sh
src/share/database/scripts/mysql/upgrade_2.0_to_3.0.sh
src/share/database/scripts/mysql/upgrade_3.0_to_4.0.sh
src/share/database/scripts/mysql/upgrade_4.0_to_4.1.sh
src/share/database/scripts/pgsql/Makefile
src/share/database/scripts/pgsql/upgrade_1.0_to_2.0.sh
tools/Makefile
tools/path_replacer.sh
])
......
SUBDIRS = lib bin hooks
SUBDIRS = share lib bin hooks
EXTRA_DIST = \
cppcheck-suppress.lst \
......
SUBDIRS = . scripts tests
SUBDIRS = . tests
# Install kea-admin in sbin.
sbin_SCRIPTS = kea-admin
......
......@@ -9,15 +9,11 @@
# 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@
# Include admin utilities
. @abs_top_srcdir@/src/bin/admin/admin-utils.sh
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
# Set path to the production schema scripts
db_scripts_dir=@abs_top_srcdir@/src/share/database/scripts
db_user="keatest"
db_password="keatest"
......@@ -30,8 +26,7 @@ keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin
mysql_wipe() {
printf "Wiping whole database %s\n" $db_name
drop_script="@abs_top_srcdir@/src/bin/admin/scripts/mysql/dhcpdb_drop.mysql"
mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < $drop_script
mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 < $db_scripts_dir/mysql/dhcpdb_drop.mysql
ERRCODE=$?
assert_eq 0 $ERRCODE "mysql-wipe: drop table sql failed, exit code %d, expected %d"
......@@ -44,7 +39,7 @@ mysql_lease_init_test() {
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
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-init mysql returned non-zero status code %d, expected %d"
......@@ -123,7 +118,7 @@ mysql_host_reservation_init_test() {
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
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-init mysql returned non-zero status code %d, expected %d"
......@@ -188,12 +183,12 @@ mysql_upgrade_test() {
mysql -u$db_user -p$db_password $db_name < @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql
# Sanity check - verify that it reports version 1.0.
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts)
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
# Ok, we have a 1.0 database. Let's upgrade it to 4.1
${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts
${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-upgrade mysql returned non-zero status code %d, expected %d"
......@@ -295,7 +290,7 @@ EOF
assert_eq 1 $count "lease6DumpData doesn't have order by clause. (returned count %d, expected %d)"
# Verify upgraded schemd reports version 4.1.
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts)
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
assert_str_eq "4.1" ${version} "Expected kea-admin to return %s, returned value was %s"
......@@ -332,7 +327,7 @@ mysql_lease4_dump_test() {
mysql_wipe
# Ok, now let's initalize the database
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $script_dir
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
......@@ -347,7 +342,7 @@ insert into lease4 values(12,22,NULL,40,\"2015-03-03 11:01:07\",50,1,1,\"three.e
assert_eq 0 $ERRCODE "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
${keaadmin} lease-dump mysql -4 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
${keaadmin} lease-dump mysql -4 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
......@@ -392,7 +387,7 @@ mysql_lease6_dump_test() {
mysql_wipe
# Ok, now let's initalize the database
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $script_dir
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
......@@ -407,7 +402,7 @@ insert into lease6 values(12,21,30,\"2015-06-06 11:01:07\",40,50,1,60,70,1,1,\"t
assert_eq 0 $ERRCODE "insert into lease6 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
${keaadmin} lease-dump mysql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
${keaadmin} lease-dump mysql -6 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d"
......
......@@ -9,15 +9,11 @@
# 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@
# Include admin utilities
. @abs_top_srcdir@/src/bin/admin/admin-utils.sh
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
# Set path to the production schema scripts
db_scripts_dir=@abs_top_srcdir@/src/share/database/scripts
db_user="keatest"
db_password="keatest"
......@@ -26,16 +22,12 @@ db_name="keatest"
# Set location of the kea-admin.
keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin
# Set location of scripts directory
scripts_dir=@abs_top_srcdir@/src/bin/admin/scripts
# Wipe all tables from the DB:
pgsql_wipe() {
printf "Wiping whole database %s\n" $db_name
export PGPASSWORD=$db_password
drop_script="@abs_top_srcdir@/src/bin/admin/scripts/pgsql/dhcpdb_drop.pgsql"
cat $drop_script | psql --set ON_ERROR_STOP=1 -A -t -q -U keatest -d keatest >/dev/null 2>&1
cat $db_scripts_dir/pgsql/dhcpdb_drop.pgsql | psql --set ON_ERROR_STOP=1 -A -t -q -U keatest -d keatest >/dev/null 2>&1
assert_eq 0 $? "pgsql_wipe drop failed, expected exit code: %d, actual: %d"
}
......@@ -46,7 +38,7 @@ pgsql_lease_init_test() {
pgsql_wipe
# Create the database
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "kea-admin lease-init pgsql failed, expected exit code: %d, actual: %d"
# Verify that all the expected tables exist
......@@ -75,7 +67,7 @@ pgsql_lease_init_test() {
# check
echo ""
echo "DB created successfully, make sure we aren't allowed to try it again:"
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 2 $? "kea-admin failed to deny lease-init, expected exit code: %d, actual: %d"
# Let's wipe the whole database
......@@ -91,7 +83,7 @@ pgsql_lease_version_test() {
pgsql_wipe
# Create the database
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "cannot initialize the database, expected exit code: %d, actual: %d"
# Verfiy that kea-admin lease-version returns the correct version
......@@ -114,7 +106,7 @@ pgsql_upgrade_test() {
pgsql_execute_script @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql
assert_eq 0 $? "cannot initialize the database, expected exit code: %d, actual: %d"
${keaadmin} lease-upgrade pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
${keaadmin} lease-upgrade pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "lease-upgrade failed, expected exit code: %d, actual: %d"
#table: state column added to lease4 (upgrade 1.0 -> 2.0)
......@@ -200,7 +192,7 @@ pgsql_lease4_dump_test() {
pgsql_wipe
# Ok, now let's initalize the database
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $script_dir
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
......@@ -219,7 +211,7 @@ insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.exam
assert_eq 0 $ERRCODE "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
${keaadmin} lease-dump pgsql -4 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
${keaadmin} lease-dump pgsql -4 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, status code %d"
......@@ -295,7 +287,7 @@ pgsql_lease6_dump_test() {
pgsql_wipe
# Ok, now let's initalize the database
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $script_dir
${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
ERRCODE=$?
assert_eq 0 $ERRCODE "could not create database, status code %d"
......@@ -314,7 +306,7 @@ insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','th
assert_eq 0 $ERRCODE "insert into lease6 failed, status code %d"
# Dump lease6 to output_file
${keaadmin} lease-dump pgsql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
${keaadmin} lease-dump pgsql -6 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
ERRCODE=$?
assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d"
......
SUBDIRS = .
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += -DTEST_ADMIN_SCRIPTS_DIR=\"$(abs_top_builddir)/src/bin/admin/scripts\"
AM_CPPFLAGS += -DDATABASE_SCRIPTS_DIR=\"$(abs_top_srcdir)/src/share/database/scripts\"
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(KEA_CXXFLAGS)
......
......@@ -30,11 +30,11 @@ validMySQLConnectionString() {
}
void destroyMySQLSchema(bool show_err) {
runMySQLScript(TEST_ADMIN_SCRIPTS_DIR, "mysql/dhcpdb_drop.mysql", show_err);
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_drop.mysql", show_err);
}
void createMySQLSchema(bool show_err) {
runMySQLScript(TEST_ADMIN_SCRIPTS_DIR, "mysql/dhcpdb_create.mysql",
runMySQLScript(DATABASE_SCRIPTS_DIR, "mysql/dhcpdb_create.mysql",
show_err);
}
......
......@@ -31,12 +31,12 @@ validPgSQLConnectionString() {
}
void destroyPgSQLSchema(bool show_err) {
runPgSQLScript(TEST_ADMIN_SCRIPTS_DIR, "pgsql/dhcpdb_drop.pgsql",
runPgSQLScript(DATABASE_SCRIPTS_DIR, "pgsql/dhcpdb_drop.pgsql",
show_err);
}
void createPgSQLSchema(bool show_err) {
runPgSQLScript(TEST_ADMIN_SCRIPTS_DIR, "pgsql/dhcpdb_create.pgsql",
runPgSQLScript(DATABASE_SCRIPTS_DIR, "pgsql/dhcpdb_create.pgsql",
show_err);
}
......
SUBDIRS = database
......@@ -2,6 +2,7 @@ SUBDIRS = .
sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/mysql
sqlscripts_DATA = dhcpdb_create.mysql
sqlscripts_DATA += dhcpdb_drop.mysql
sqlscripts_DATA += upgrade_1.0_to_2.0.sh
sqlscripts_DATA += upgrade_2.0_to_3.0.sh
sqlscripts_DATA += upgrade_3.0_to_4.0.sh
......
......@@ -2,6 +2,7 @@ SUBDIRS = .
sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/pgsql
sqlscripts_DATA = dhcpdb_create.pgsql
sqlscripts_DATA += dhcpdb_drop.pgsql
sqlscripts_DATA += upgrade_1.0_to_2.0.sh
EXTRA_DIST = ${sqlscripts_DATA}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment