2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-05 08:25:16 +00:00
Files
kea/src/share/database/scripts/mysql/wipe_data.sh.in
Thomas Markwalder 6af5e78ec8 [#526,!269] - MySQL unit tests now wipe data, instead of schema
src/share/database/scripts/mysql/wipe_data.sh.in -
    New shell script which intelligently deletes data from
    the schema IF the schema version matches the expected version

src/lib/mysql/testutils/mysql_schema.*
    destroyMySQLSchema() - modfied to default to calling
    wipeData(), and only destroying the schema if that fails
    or by force flag = true;

    createMySQLSchema() - modified to default to calling
    wipeData(), and only recreating the schema if that
    fails or by force flag = true;

    wipeData() - new method which runs the
    MySQL wipe_data.sh shell script, passing in the expected
    schema version.

src/share/database/scripts/mysql/dhcpdb_create.mysql
    createAuditRevisionDHCP4()
    createAuditEntryDHCP4()
    createAuditRevisionDHCP6()
    createAuditEntryDHCP6() - added session variable,
    @disable_audit, to allow procedures to be "turned
    off" during data wiping.

src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_mgr_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/tests/cfg_db_access_unittest.cc
src/lib/dhcpsrv/tests/host_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
    Removed calls to destroy schema from test constructors
2019-03-08 12:09:14 -05:00

91 lines
2.9 KiB
Bash

# 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 mysql command line arguments
# If the existing schema doesn't match, the fail
VERSION=`mysql_version "$@"`
if [ "$VERSION" != "$exp_version" ]; then
printf "Reported version is $VERSION is wrong, expected $exp_version.\n"
exit 1
fi
# Delete transient data from tables. Per MySQL documentation TRUNCATE
# destroys and there recreates tables. As schema updates are typically
# very slow, we're use deletes here. We turn off foreign key checks to
# worrying about table order. We also set the session variable
# disable_audit to turn off Back audit procedures, to avoid attempting
# to create entries for deleted records.
mysql "$@" <<EOF
START TRANSACTION;
SET SESSION FOREIGN_KEY_CHECKS = 0;
SET @disable_audit = 1;
DELETE FROM dhcp4_global_parameter;
DELETE FROM dhcp4_global_parameter_server;
DELETE FROM dhcp4_option_def;
DELETE FROM dhcp4_option_def_server;
DELETE FROM dhcp4_options;
DELETE FROM dhcp4_options_server;
DELETE FROM dhcp4_pool;
# preserve special server "all"
DELETE FROM dhcp4_server WHERE tag != "all";
DELETE FROM dhcp4_shared_network;
DELETE FROM dhcp4_shared_network_server;
DELETE FROM dhcp4_subnet;
DELETE FROM dhcp4_subnet_server;
DELETE FROM dhcp4_audit_revision;
DELETE FROM dhcp4_audit;
DELETE FROM dhcp6_global_parameter;
DELETE FROM dhcp6_global_parameter_server;
DELETE FROM dhcp6_option_def;
DELETE FROM dhcp6_option_def_server;
DELETE FROM dhcp6_options;
DELETE FROM dhcp6_options_server;
DELETE FROM dhcp6_pd_pool;
DELETE FROM dhcp6_pool;
# preserve special server "all"
DELETE FROM dhcp6_server WHERE tag != "all";
DELETE FROM dhcp6_shared_network;
DELETE FROM dhcp6_shared_network_server;
DELETE FROM dhcp6_subnet;
DELETE FROM dhcp6_subnet_server;
DELETE FROM dhcp6_audit;
DELETE FROM dhcp6_audit_revision;
DELETE FROM hosts;
DELETE FROM ipv6_reservations;
DELETE FROM lease4;
DELETE FROM lease4_stat;
DELETE FROM lease6;
DELETE FROM lease6_stat;
DELETE FROM logs;
COMMIT;
EOF
RESULT=$?
exit $RESULT