|
@@ -0,0 +1,126 @@
|
|
|
+#!/bin/sh
|
|
|
+
|
|
|
+# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+#
|
|
|
+# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
+# AND FITNESS. IN NO EVENT SHALL ISC 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.
|
|
|
+
|
|
|
+# 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_builddir@/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
|
|
|
+
|
|
|
+# 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
|
|
|
+
|
|
|
+ # Make a set of drop commands, one for each table owned by keatest
|
|
|
+ pgsql_execute "SELECT 'drop table if exists '||t.tablename || ' cascade;' as dcmd FROM pg_catalog.pg_tables t WHERE t.tableowner = 'keatest';"
|
|
|
+ assert_eq 0 $? "pgsql_wipe select failed, exit code: $?"
|
|
|
+
|
|
|
+ # Now execute the set of drop commands from the result set returned
|
|
|
+ pgsql_execute "$_RESULT"
|
|
|
+ assert_eq 0 $? "pgsql_wipe drop failed, exit code: $?"
|
|
|
+}
|
|
|
+
|
|
|
+pgsql_lease_init_test() {
|
|
|
+ test_start "pgsql.lease-init"
|
|
|
+
|
|
|
+ # Let's wipe the whole database
|
|
|
+ pgsql_wipe
|
|
|
+
|
|
|
+ # Create the database
|
|
|
+ ${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
|
|
|
+ assert_eq 0 $? "kea-admin lease-init pgsql failed, exit code: $?"
|
|
|
+
|
|
|
+ # Verify that all the expected tables exist
|
|
|
+
|
|
|
+ # Check schema_version table
|
|
|
+ pgsql_execute "SELECT version, minor FROM schema_version;"
|
|
|
+ assert_eq 0 $? "schema_vesion table check failed, exit code: $?"
|
|
|
+
|
|
|
+ # Check lease4 table
|
|
|
+ pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname FROM lease4;"
|
|
|
+ assert_eq 0 $? "lease4 table check failed, exit code: $?"
|
|
|
+
|
|
|
+ # Check lease6 table
|
|
|
+ pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname FROM lease6;"
|
|
|
+ assert_eq 0 $? "lease6 table check failed, exit code: $?"
|
|
|
+
|
|
|
+ # Check lease6_types table
|
|
|
+ pgsql_execute "SELECT lease_type, name FROM lease6_types;"
|
|
|
+ assert_eq 0 $? "lease6_types table check failed, exit code: $?"
|
|
|
+
|
|
|
+ # Trying to create it again should fail. This verifies the db present
|
|
|
+ # 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
|
|
|
+ assert_eq 2 $? "kea-admin failed to deny lease-init, exit code: $?"
|
|
|
+
|
|
|
+ # Let's wipe the whole database
|
|
|
+ pgsql_wipe
|
|
|
+
|
|
|
+ test_finish 0
|
|
|
+}
|
|
|
+
|
|
|
+pgsql_lease_version_test() {
|
|
|
+ test_start "pgsql.lease-version"
|
|
|
+
|
|
|
+ # Wipe the whole database
|
|
|
+ pgsql_wipe
|
|
|
+
|
|
|
+ # Create the database
|
|
|
+ ${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
|
|
|
+ assert_eq 0 $? "cannot initialize the database, exit code: $?"
|
|
|
+
|
|
|
+ # Verfiy that kea-admin lease-version returns the correct version
|
|
|
+ version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name)
|
|
|
+ assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
|
|
|
+
|
|
|
+ # Let's wipe the whole database
|
|
|
+ pgsql_wipe
|
|
|
+
|
|
|
+ test_finish 0
|
|
|
+}
|
|
|
+
|
|
|
+pgsql_upgrade_test() {
|
|
|
+ test_start "pgsql.upgrade-test"
|
|
|
+
|
|
|
+ ${keaadmin} lease-upgrade pgsql -u $db_user -p $db_password -n $db_name -d $scripts_dir
|
|
|
+ assert_eq 1 $? "lease-upgrade should have failed, exit code: $?"
|
|
|
+
|
|
|
+ test_finish 0
|
|
|
+}
|
|
|
+
|
|
|
+pgsql_lease_init_test
|
|
|
+pgsql_lease_version_test
|
|
|
+pgsql_upgrade_test
|