diff options
author | Thomas Markwalder <tmark@isc.org> | 2019-03-13 15:36:49 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2019-03-13 15:44:17 +0100 |
commit | d88c013de4fc13404965d79e216ff3fadb325d98 (patch) | |
tree | 4061422d3b5b0616b3d34a3cf464616771c2a4d8 /src/share/database/scripts | |
parent | [master] Added ChangeLog entry for --enable-generate-messages (diff) | |
download | kea-d88c013de4fc13404965d79e216ff3fadb325d98.tar.xz kea-d88c013de4fc13404965d79e216ff3fadb325d98.zip |
[#531,!279] PgSQL unit testing now supports data wipe
src/share/database/scripts/pgsql
wipe_data.sh.in - new file
doc/devel/unit-tests.dox
Removed MySQL/CQL only comment
several files:
Added commentary and removed superflous calls to destroyPgSQLSchema
src/lib/pgsql/testutils/pgsql_schema.*
destroyPgSQLSchema()
createPgSQLSchema() - modified to support data wiping
wipePgSQLData() - new function
src/lib/pgsql/tests
pgsql_schema.cc
pgsql_schema.h - deleted these. They appear to have
been added by mistake.
Diffstat (limited to 'src/share/database/scripts')
-rw-r--r-- | src/share/database/scripts/pgsql/.gitignore | 1 | ||||
-rw-r--r-- | src/share/database/scripts/pgsql/Makefile.am | 2 | ||||
-rw-r--r-- | src/share/database/scripts/pgsql/wipe_data.sh.in | 60 |
3 files changed, 63 insertions, 0 deletions
diff --git a/src/share/database/scripts/pgsql/.gitignore b/src/share/database/scripts/pgsql/.gitignore index 60c0c334a2..16c6a378b9 100644 --- a/src/share/database/scripts/pgsql/.gitignore +++ b/src/share/database/scripts/pgsql/.gitignore @@ -5,3 +5,4 @@ /upgrade_3.2_to_3.3.sh /upgrade_3.3_to_4.0.sh /upgrade_4.0_to_5.0.sh +/wipe_data.sh diff --git a/src/share/database/scripts/pgsql/Makefile.am b/src/share/database/scripts/pgsql/Makefile.am index bc604c13d9..a940aa1d14 100644 --- a/src/share/database/scripts/pgsql/Makefile.am +++ b/src/share/database/scripts/pgsql/Makefile.am @@ -10,6 +10,7 @@ sqlscripts_DATA += upgrade_3.1_to_3.2.sh sqlscripts_DATA += upgrade_3.2_to_3.3.sh sqlscripts_DATA += upgrade_3.3_to_4.0.sh sqlscripts_DATA += upgrade_4.0_to_5.0.sh +sqlscripts_DATA += wipe_data.sh DISTCLEANFILES = upgrade_1.0_to_2.0.sh DISTCLEANFILES += upgrade_2.0_to_3.0.sh @@ -18,5 +19,6 @@ DISTCLEANFILES += upgrade_3.1_to_3.2.sh DISTCLEANFILES += upgrade_3.2_to_3.3.sh DISTCLEANFILES += upgrade_3.3_to_4.0.sh DISTCLEANFILES += upgrade_4.0_to_5.0.sh +DISTCLEANFILES += wipe_data.sh EXTRA_DIST = ${sqlscripts_DATA} diff --git a/src/share/database/scripts/pgsql/wipe_data.sh.in b/src/share/database/scripts/pgsql/wipe_data.sh.in new file mode 100644 index 0000000000..4df8de6b05 --- /dev/null +++ b/src/share/database/scripts/pgsql/wipe_data.sh.in @@ -0,0 +1,60 @@ +# Copyright (C) 2019 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/. + +#!/bin/sh + +# This script is primarily used for MySQL unit tests, which need to +# ensure an empty, but schema correct database for each test. It +# deletes ALL transient data from an existing Kea MySQL schema, +# including leases, reservations, etc... Use at your own peril. +# Reference tables will be left in-tact. + +# Include utilities. Use installed version if available and +# use build version if it isn't. +if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then + . @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh +else + . @abs_top_builddir@/src/bin/admin/admin-utils.sh +fi + +# First argument is must be the expected schema version <major>.<minor> +exp_version="$1" +shift; + +# Remaining arguments are used as pgsql command line arguments + +# If the existing schema doesn't match, the fail +VERSION=`pgsql_version "$@"` +if [ "$VERSION" = "" ]; then + printf "Cannot wipe data, schema version could not be detected.\n" + exit 1 +fi + +if [ "$VERSION" != "$exp_version" ]; then + printf "Cannot wipe data, wrong schema version. Expected $exp_version, found version $VERSION.\n" + exit 1 +fi + +# Delete transient data from tables. We're using delete instead +# of truncate because it is much faster since our unit tests +# create very little data. +psql "$@" >/dev/null <<EOF +START TRANSACTION; +DELETE FROM hosts CASCADE; +DELETE FROM dhcp4_options; +DELETE FROM ipv6_reservations; +DELETE FROM dhcp6_options; +DELETE FROM lease4; +DELETE FROM lease4_stat; +DELETE FROM lease6; +DELETE FROM lease6_stat; +DELETE FROM logs; +COMMIT; +EOF + +RESULT=$? + +exit $RESULT |