]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3802'
authorThomas Markwalder <tmark@isc.org>
Thu, 11 Jun 2015 10:17:49 +0000 (06:17 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 11 Jun 2015 10:17:49 +0000 (06:17 -0400)
Adds lease-dump to kea-admin.  While merging, additonal changes
were needed:

src/bin/admin/tests/mysql_tests.sh.in
 mysql_wipe() - functio was failing referential integrity checks
 due to new tables added in schema 3.0.  Was deleting all
 tables except "hosts".  This has been fixed.

Added src/bin/admin/scripts/mysql/lease_dump_3.0.sh

1  2 
src/bin/admin/admin-utils.sh
src/bin/admin/kea-admin.in
src/bin/admin/scripts/mysql/Makefile.am
src/bin/admin/scripts/mysql/lease_dump_3.0.sh
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh.in
src/bin/admin/tests/mysql_tests.sh.in

index 58e6c74f4e82ea529ad7f15ea4fe39f73411659c,624691ce8c6c9f1ebb1b3a785cafd48c576d937b..6edc7392ac5ba4a2e6482a11b74d2656f836563f
  #     more convenient to use if the script didn't parse db_user db_password
  #     and db_name.
  #
- # @todo: Catch mysql return code. I tried to use PIPESTATUS[X], but it doesn't
- # seem to work (or at least I don't know how to use it).
+ # It saves mysql command exit status both to the env variable _ADMIN_STATUS
+ # as well as returning it as $? to the caller.
  mysql_execute() {
      if [ $# -gt 1 ]; then
-         QUERY=$1
+         QUERY="$1"
          shift
-         _RESULT=`echo $QUERY | mysql -N -B $@`
+         mysql -N -B  $* -e "${QUERY}"
+         retcode=$?
      else
-         _RESULT=$(mysql -N -B --user=$db_user --password=$db_password -e "${1}" $db_name)
+         mysql -N -B --user=$db_user --password=$db_password -e "${1}" $db_name
+         retcode="$?"
      fi
+     return $retcode
  }
  
 -
  mysql_version() {
      mysql_execute "SELECT CONCAT(version,\".\",minor) FROM schema_version" "$@"
- }
- mysql_version_print() {
-     mysql_version "$@"
-     printf "%s" $_RESULT
+     return $?
  }
  
 +pgsql_execute() {
 +    QUERY=$1
 +    shift
 +    if [ $# -gt 0 ]; then
 +        _RESULT=$(echo $QUERY | psql --set ON_ERROR_STOP=1 -A -t -q $*)
 +        retcode=$?
 +    else
 +        export PGPASSWORD=$db_password
 +        _RESULT=$(echo $QUERY | psql --set ON_ERROR_STOP=1 -A -t -q -U $db_user -d $db_name)
 +        retcode=$?
 +    fi
 +    return $retcode
 +}
 +
 +pgsql_execute_script() {
 +    file=$1
 +    shift
 +    if [ $# -gt 0 ]; then
 +        _RESULT=$(psql --set ON_ERROR_STOP=1 -A -t -q -f $file $*)
 +        retcode=$?
 +    else
 +        export PGPASSWORD=$db_password
 +        _RESULT=$(psql --set ON_ERROR_STOP=1 -A -t -q -U $db_user -d $db_name -f $file)
 +        retcode=$?
 +    fi
 +    return $retcode
 +}
 +
 +
 +pgsql_version() {
 +    pgsql_execute "SELECT version || '.' || minor FROM schema_version" "$@"
 +    return $?
 +}
 +
 +pgsql_version_print() {
 +    pgsql_version "$@"
 +    retcode=$?
 +    printf "%s" $_RESULT
 +    return $?
 +}
index 0c5c9c0046e892e6965d62d0734912796a36a36d,e871b10d25407d5998a160fdd63c4533399fc737..5b964101b72d3cbd2ac5b9518cea7f737a534a85
@@@ -236,36 -236,168 +254,195 @@@ mysql_upgrade() 
  }
  
  pgsql_upgrade() {
 -    log_error "NOT IMPLEMENTED"
 +    # @todo - When PostgreSQL has a schema greater than 1.0, this will need
 +    # to be implemented. See ticket #3600
 +    pgsql_version_print
 +    printf "\n"
 +
 +    # Check if the scripts directory exists at all.
 +    if [ ! -d ${scripts_dir}/pgsql ]; then
 +        log_error "Invalid scripts directory: ${scripts_dir}/pgsql"
 +        exit 1
 +    fi
 +
 +    # Check if there are any files in it
 +    num_files=$(find ${scripts_dir}/pgsql/upgrade*.sh -type f | wc -l)
 +    if [ $num_files -eq 0 ]; then
 +        log_error "No scripts in ${scripts_dir}/pgsql or the directory is not readable or does not have any upgrade* scripts."
 +        exit 1
 +    fi
 +
 +    for script in ${scripts_dir}/pgsql/upgrade*.sh
 +    do
 +        echo "Processing $script file..."
 +        sh ${script} --user=${db_user} --password=${db_password} ${db_name}
 +    done
 +
 +    printf "Lease DB version reported after upgrade: "
 +    pgsql_version_print
 +    printf "\n"
 +    exit 0
  }
  
+ # Utility function which tests if the given file exists and
+ # if so notifies the user and provides them the opportunity
+ # to abort the current command.
+ check_file_overwrite () {
+     local file=$1
+     if [ -e ${file} ]
+     then
+         echo "Output file, $file, exists and will be overwritten."
+         echo "Do you wish to continue? (y/n)"
+         read ans
+         if [ ${ans} != "y" ]
+         then
+             echo "$command aborted by user."
+             exit 1
+         fi
+     fi
+ }
+ ### Functions used for dump
+ # Sets the global variable, dump_qry, to the schema-version specific
+ # SQL text needed to dump the lease data for the current backend
+ # and protocol
+ get_dump_query() {
+     local version=$1
+     dump_qry=""
+     dump_sql_file="$scripts_dir/${backend}/lease_dump_$version.sh"
+     if [ ! -e $dump_sql_file ]
+     then
+         log_error "lease-dump: cannot access dump_sql_file: $dump_sql_file"
+         exit 1;
+     fi
+     # source in the dump file which defines the sql text we'll need
+     . $dump_sql_file
+     if [ $? -ne 0 ]
+     then
+         log_error "lease-dump: error sourcing dump_sql_file: $dump_sql_file"
+         exit 1
+     fi
+     # Construct the SQL text to dump the leases based on protocol type
+     case ${dump_type} in
+         4)
+             dump_qry="$lease4_dump_sql";
+             ;;
+         6)
+             dump_qry="$lease6_dump_sql";
+             ;;
+         *)
+             log_error "you must specify -4 or -6 for lease-dump"
+             usage
+             exit 1
+             ;;
+     esac
+     if [ "$dump_qry" = "" ]
+     then
+         log_error "lease-dump: dump query appears to be undefined"
+         exit 1
+     fi
+ }
+ memfile_dump() {
+     log_error "lease-dump is not supported for memfile"
+     exit 1
+ }
+ mysql_dump() {
+     # get the correct dump query
+     version=`mysql_version`
+     retcode=$?
+     if [ $retcode -ne 0 ]
+     then
+         log_error "lease-dump: mysql_version failed, exit code $retcode"
+         exit 1;
+     fi
+     # Fetch the correct SQL text. Note this function will exit
+     # if it fails.
+     get_dump_query $version
+     # Make sure they specified a file
+     if [ "$dump_file" = "" ]; then
+         log_error "you must specify an output file for lease-dump"
+         usage
+         exit 1
+     fi
+     # If output file exists, notify user, allow them a chance to bail
+     check_file_overwrite $dump_file
+     # Check the temp file too
+     tmp_file="$dump_file.tmp"
+     check_file_overwrite $tmp_file
+     # Run the sql to output tab-delimited lease data to a temp file.
+     # By using a temp file we can check for MySQL errors before using
+     # 'tr' to translate tabs to commas.  We do not use MySQL's output
+     # to file as that requires linux superuser privileges to execute
+     # the select.
+     mysql_execute "${dump_qry}" > $tmp_file
+     retcode=$?
+     if [ $retcode -ne 0 ]; then
+         log_error "lease-dump: mysql_execute failed, exit code $retcode";
+         exit 1
+     fi
+     # Now translate tabs to commas.
+     cat $tmp_file | tr '\t' ',' >$dump_file
+     if [ $? -ne 0 ]; then
+         log_error "lease-dump: reformatting failed";
+         exit 1
+     fi
+     # delete the tmp file on success
+     rm $tmp_file
+     echo lease$dump_type successfully dumped to $dump_file
+     exit 0
+ }
+ ### Functions used for dump
+ pgsql_dump() {
+     # @todo use pgsql_version once implemented. See #3883
+     version='1.0'
+     get_dump_query $version
+     # Make sure they specified a file
+     if [ "$dump_file" = "" ]; then
+         log_error "you must specify an output file for lease-dump"
+         usage
+         exit 1
+     fi
+     # If output file exists, notify user, allow them a chance to bail
+     check_file_overwrite $dump_file
+     # psql does not accept password as a parameter but will look in the environment
+     export PGPASSWORD=$db_password
+     # Call psql and redirect output to the dump file. We don't use psql "to csv"
+     # as it can only be run as db superuser.
+     echo "$dump_qry" | psql --set ON_ERROR_STOP=1 -t -q --user=$db_user --dbname=$db_name -w --no-align --field-separator=',' >$dump_file
+     retcode=$?
+     # Check for errors.
+     if [ $retcode -ne 0 ]; then
+         log_error "lease-dump: psql call failed, exit code: $retcode";
+         exit 1
+     fi
+     echo lease$dump_type successfully dumped to $dump_file
+     exit 0
+ }
  
  ### Script starts here ###
  
index 419474510f36f287da453ec99164a47208cd85e1,cfac0cd4d28198631fd25a5acfd429f621037637..e91622b88f01438c2594a732666fd620e25d0d7d
@@@ -1,6 -1,6 +1,6 @@@
  SUBDIRS = .
  
  sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/mysql
- sqlscripts_DATA = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh upgrade_2.0_to_3.0.sh
 -sqlscripts_DATA = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh lease_dump_1.0.sh lease_dump_2.0.sh
++sqlscripts_DATA = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh upgrade_2.0_to_3.0.sh lease_dump_1.0.sh lease_dump_2.0.sh lease_dump_3.0.sh
  
- EXTRA_DIST = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh upgrade_2.0_to_3.0.sh
 -EXTRA_DIST = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh lease_dump_1.0.sh lease_dump_2.0.sh
++EXTRA_DIST = dhcpdb_create.mysql upgrade_1.0_to_2.0.sh upgrade_2.0_to_3.0.sh lease_dump_1.0.sh lease_dump_2.0.sh lease_dump_3.0.sh
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..80256b273ba11b89478a37e1cffdbca30f6dae85
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,38 @@@
++#!/bin/sh
++# Copyright (C) 2015  Internet Systems Consortium.
++#
++# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM
++# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
++# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
++# INTERNET SYSTEMS CONSORTIUM 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.
++#
++# Specifies the MySQL sql for schema-version 3.0 required to produce 
++# lease output that includes a header row containing column names,
++# followed by the lease data. The text is used in a single call 
++# to the mysql command line tool.
++
++# SQL for DHCPv4 leases
++lease4_dump_sql="\
++SELECT 'address', 'hwaddr', 'client_id', 'valid_lifetime', 'expire',\
++'subnet_id', 'fqdn_fwd', 'fqdn_rev', 'hostname';\
++SELECT INET_NTOA(address), IFNULL(HEX(hwaddr), ''), IFNULL(HEX(client_id), ''),\
++valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname from lease4"
++
++# SQL for DHCPv6 leases
++lease6_dump_sql="\
++SELECT 'address', 'duid', 'valid_lifetime', 'expire',\
++'subnet_id', 'pref_lifetime', 'lease_type', 'iaid', 'prefix_len', 'fqdn_fwd',\
++'fqdn_rev', 'hostname', 'hwaddr', 'hwtype', 'hwaddr_source';\
++SELECT a.address, IFNULL(HEX(a.duid), ''), a.valid_lifetime,\
++a.expire, a.subnet_id, a.pref_lifetime, IFNULL(b.name, ''), a.iaid, a.prefix_len,\
++a.fqdn_fwd, a.fqdn_rev, hostname, IFNULL(HEX(hwaddr), ''), IFNULL(hwtype, ''),\
++IFNULL(hwaddr_source, '') \
++FROM lease6 a left outer join lease6_types b on (a.lease_type = b.lease_type)"
index 9d275ef1b24e24cb27c91050ffc97f18e798c267,0000000000000000000000000000000000000000..cc85d409340f7dd161b6bb1382f85dd811f2ecb4
mode 100755,000000..100755
--- /dev/null
@@@ -1,101 -1,0 +1,100 @@@
- mysql_version "$@"
- VERSION=$_RESULT
 +#!/bin/sh
 +
 +# 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
 +
++VERSION=`mysql_version "$@"`
 +
 +if [ "$VERSION" != "2.0" ]; then
 +    printf "This script upgrades 2.0 to 3.0. Reported version is $VERSION. Skipping upgrade.\n"
 +    exit 0
 +fi
 +
 +mysql "$@" <<EOF
 +CREATE TABLE IF NOT EXISTS hosts (
 +host_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
 +dhcp_identifier VARBINARY(128) NOT NULL ,
 +dhcp_identifier_type TINYINT NOT NULL ,
 +dhcp4_subnet_id INT UNSIGNED NULL ,
 +dhcp6_subnet_id INT UNSIGNED NULL ,
 +ipv4_address INT UNSIGNED NULL ,
 +hostname VARCHAR(255) NULL ,
 +dhcp4_client_classes VARCHAR(255) NULL ,
 +dhcp6_client_classes VARCHAR(255) NULL ,
 +PRIMARY KEY (host_id) ,
 +INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
 +INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC) );
 +
 +CREATE TABLE IF NOT EXISTS ipv6_reservations (
 +reservation_id INT NOT NULL AUTO_INCREMENT ,
 +address VARCHAR(39) NOT NULL ,
 +prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128 ,
 +type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 ,
 +dhcp6_iaid INT UNSIGNED NULL ,
 +host_id INT UNSIGNED NOT NULL ,
 +PRIMARY KEY (reservation_id) ,
 +INDEX fk_ipv6_reservations_host_idx (host_id ASC) ,
 +CONSTRAINT fk_ipv6_reservations_Host
 +FOREIGN KEY (host_id )
 +REFERENCES hosts (host_id )
 +ON DELETE NO ACTION
 +ON UPDATE NO ACTION);
 +
 +CREATE TABLE IF NOT EXISTS dhcp4_options (
 +option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
 +code TINYINT UNSIGNED NOT NULL ,
 +value BLOB NULL ,
 +formatted_value TEXT NULL ,
 +space VARCHAR(128) NULL ,
 +persistent TINYINT(1) NOT NULL DEFAULT 0 ,
 +dhcp_client_class VARCHAR(128) NULL ,
 +dhcp4_subnet_id INT NULL ,
 +host_id INT UNSIGNED NULL ,
 +PRIMARY KEY (option_id) ,
 +UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
 +INDEX fk_options_host1_idx (host_id ASC) ,
 +CONSTRAINT fk_options_host1
 +FOREIGN KEY (host_id )
 +REFERENCES hosts (host_id )
 +ON DELETE NO ACTION
 +ON UPDATE NO ACTION);
 +
 +CREATE TABLE IF NOT EXISTS dhcp6_options (
 +option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
 +code INT UNSIGNED NOT NULL ,
 +value BLOB NULL ,
 +formatted_value TEXT NULL ,
 +space VARCHAR(128) NULL ,
 +persistent TINYINT(1) NOT NULL DEFAULT 0 ,
 +dhcp_client_class VARCHAR(128) NULL ,
 +dhcp6_subnet_id INT NULL ,
 +host_id INT UNSIGNED NULL ,
 +PRIMARY KEY (option_id) ,
 +UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
 +INDEX fk_options_host1_idx (host_id ASC) ,
 +CONSTRAINT fk_options_host10
 +FOREIGN KEY (host_id )
 +REFERENCES hosts (host_id )
 +ON DELETE NO ACTION
 +ON UPDATE NO ACTION);
 +
 +DELIMITER $$
 +CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW
 +-- Edit trigger body code below this line. Do not edit lines above this one
 +BEGIN
 +DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id;
 +END
 +$$
 +DELIMITER ;
 +
 +UPDATE schema_version SET version="3", minor="0";
 +EOF
 +
 +RESULT=$?
 +
 +exit $?
index dec5515231eb9645b120e327a99beea65abc6fff,f4d59b1635f2b20e9876ba1507f247d12f5fef7d..f389722d18b7bb8d3cc38ba232ce83eea7e3721f
@@@ -37,17 -37,17 +37,26 @@@ keaadmin=@abs_top_builddir@/src/bin/adm
  # Wipe all tables from the DB:
  mysql_wipe() {
      printf "Wiping whole database %s\n" $db_name
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
 -    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
--SET @tables = NULL;
--SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
--  FROM information_schema.tables
--  WHERE table_schema = 'keatest';
--
--SET @tables = CONCAT('DROP TABLE ', @tables);
--PREPARE stmt FROM @tables;
--EXECUTE stmt;
--DEALLOCATE PREPARE stmt;
--EOF
++
++    # 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() {
@@@ -129,63 -129,11 +138,63 @@@ EO
      test_finish 0
  }
  
 -mysql_lease_upgrade_test() {
 +mysql_host_reservation_init_test() {
 +    test_start "mysql.host_reservation-init"
  
 -    # @todo: need to test whether non-empty database is updated correctly and the data survives the upgrade
 +    # Let's wipe the whole database
 +    mysql_wipe
  
 -    test_start "mysql.lease-upgrade"
 +    # Ok, now let's initalize the database
-     ${keaadmin} lease-init mysql -u $db_user -p $db_pass -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 @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_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT version, minor FROM schema_version;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "schema_version table is missing or broken. (returned status code %d, expected %d)"
 +
 +    # Second table: hosts
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "hosts table is missing or broken. (returned status code %d, expected %d)"
 +
 +    # Third table: ipv6_reservations
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "ipv6_reservations table is missing or broken. (returned status code %d, expected %d)"
 +
 +    # Fourth table: dhcp4_options
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "dhcp4_options table is missing or broken. (returned status code %d, expected %d)"
 +
 +    # Fifth table: dhcp6_options
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "dhcp6_options table is missing or broken. (returned status code %d, expected %d)"
 +
 +    # Let's wipe the whole database
 +    mysql_wipe
 +
 +    test_finish 0
 +}
 +
 +mysql_upgrade_test() {
 +
 +    test_start "mysql.host_reservation-upgrade"
  
      # Let's wipe the whole database
      mysql_wipe
  
      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 2.0
 +    # Ok, we have a 1.0 database. Let's upgrade it to 3.0
-     ${keaadmin} lease-upgrade mysql -u $db_user -p $db_pass -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 @abs_top_srcdir@/src/bin/admin/scripts
      ERRCODE=$?
  
      assert_eq 0 $ERRCODE "kea-admin lease-upgrade mysql returned non-zero status code %d, expected %d"
  
      # Let's check that the new tables are indeed there.
  
 -    # Third table: lease6
 +    #table: lease6 (upgrade 1.0 -> 2.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
+     mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
      SELECT hwaddr, hwtype, hwaddr_source FROM lease6;
  EOF
      ERRCODE=$?
      assert_eq 0 $ERRCODE "lease6 table not upgraded to 2.0 (returned status code %d, expected %d)"
  
 -    # Fifth table: lease_hwaddr_source
 +    #table: lease_hwaddr_source (upgrade 1.0 -> 2.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
+     mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
      SELECT hwaddr_source, name FROM lease_hwaddr_source;
  EOF
      ERRCODE=$?
      assert_eq 0 $ERRCODE "lease_hwaddr_source table is missing or broken. (returned status code %d, expected %d)"
  
 -    # Verify that it reports version 2.0.
 +    #table: hosts (upgrade 2.0 -> 3.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes FROM hosts;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "hosts table is missing or broken. (returned status code %d, expected %d)"
 +
 +    #table: ipv6_reservations (upgrade 2.0 -> 3.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT reservation_id, address, prefix_len, type, dhcp6_iaid, host_id FROM ipv6_reservations;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "ipv6_reservations table is missing or broken. (returned status code %d, expected %d)"
 +
 +    #table: dhcp4_options (upgrade 2.0 -> 3.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp4_subnet_id, host_id FROM dhcp4_options;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "dhcp4_options table is missing or broken. (returned status code %d, expected %d)"
 +
 +    #table: dhcp6_options (upgrade 2.0 -> 3.0)
-     mysql -u$db_user -p$db_pass $db_name >/dev/null 2>&1 <<EOF
++    mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
 +    SELECT option_id, code, value, formatted_value, space, persistent, dhcp_client_class, dhcp6_subnet_id, host_id FROM dhcp6_options;
 +EOF
 +    ERRCODE=$?
 +    assert_eq 0 $ERRCODE "dhcp6_options table is missing or broken. (returned status code %d, expected %d)"
 +
 +
 +    # Verify that it reports version 3.0.
-     version=$(${keaadmin} lease-version mysql -u $db_user -p $db_pass -n $db_name)
+     version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name)
  
 -    assert_str_eq "2.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 +    assert_str_eq "3.0" ${version} "Expected kea-admin to return %s, returned value was %s"
  
      # Let's wipe the whole database
      mysql_wipe
      test_finish 0
  }
  
+ mysql_lease4_dump_test() {
+     test_start "mysql.lease4_dump_test"
+     test_dir="@abs_top_srcdir@/src/bin/admin/tests"
+     script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
+     output_file="$test_dir/data/lease4_dump_test.output.csv"
+     tmp_file="$test_dir/data/lease4_dump_test.output.csv.tmp"
+     ref_file="$test_dir/data/mysql.lease4_dump_test.reference.csv"
+     # wipe out any residuals from prior failed runs
+     if [ -e $output_file ]
+     then
+         rm $output_file
+     fi
+     if [ -e $tmp_file ]
+     then
+         rm $tmp_file
+     fi
+     # 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 $script_dir
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "could not create database,  status code %d"
+     # Insert the reference record
+     insert_sql="\
+ insert into lease4 values(10,20,30,40,0,50,1,1,\"one.example.com\");\
+ insert into lease4 values(11,NULL,123,40,0,50,1,1,\"\");\
+ insert into lease4 values(12,22,NULL,40,0,50,1,1,\"three.example.com\");"
+     mysql_execute "$insert_sql"
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "insert into lease4 failed, status code %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
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed,  status code %d"
+     # Compare the dump output to reference file, they should be identical
+     cmp -s $output_file  $ref_file
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "dump file does not match reference file"
+     # remove the output file
+     rm $output_file
+     # Let's wipe the whole database
+     mysql_wipe
+     test_finish 0
+ }
+ mysql_lease6_dump_test() {
+     test_start "mysql.lease6_dump_test"
+     test_dir="@abs_top_srcdir@/src/bin/admin/tests"
+     script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
+     output_file="$test_dir/data/lease6_dump_test.output.csv"
+     tmp_file="$test_dir/data/lease6_dump_test.output.csv.tmp"
+     ref_file="$test_dir/data/mysql.lease6_dump_test.reference.csv"
+     # wipe out any residuals from prior failed runs
+     if [ -e $output_file ]
+     then
+         rm $output_file
+     fi
+     if [ -e $tmp_file ]
+     then
+         rm $tmp_file
+     fi
+     # 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 $script_dir
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "could not create database,  status code %d"
+     # Insert the reference record
+     insert_sql="\
+ insert into lease6 values(10,20,30,0,40,50,1,60,70,1,1,\"one.example.com\",80,90,100);\
+ insert into lease6 values(11,NULL,30,0,40,50,1,60,70,1,1,\"\",80,90,100);\
+ insert into lease6 values(12,21,30,0,40,50,1,60,70,1,1,\"three.example.com\",80,90,100);"
+     mysql_execute "$insert_sql"
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "insert into lease6 failed, status code %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
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d"
+     # Compare the dump output to reference file, they should be identical
+     cmp -s $output_file  $ref_file
+     ERRCODE=$?
+     assert_eq 0 $ERRCODE "dump file does not match reference file"
+     # remove the output file
+     rm $output_file
+     # Let's wipe the whole database
+     mysql_wipe
+     test_finish 0
+ }
  mysql_lease_init_test
 +mysql_host_reservation_init_test
  mysql_lease_version_test
 -mysql_lease_upgrade_test
 +mysql_upgrade_test
+ mysql_lease4_dump_test
+ mysql_lease6_dump_test