src/bin/admin/tests/memfile_tests.sh
src/bin/admin/tests/mysql_tests.sh
src/bin/admin/scripts/mysql/Makefile
+ src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh
src/bin/admin/scripts/pgsql/Makefile
src/hooks/Makefile
src/hooks/dhcp/Makefile
-#!/bin/sh
+# Copyright (C) 2014 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.
+
+# This is an utility script that is being included by other scripts.
# There are two ways of calling this method.
# mysql_execute SQL_QUERY - This call is simpler, but requires db_user,
# This is kea-admin script that conducts administrative tasks on the Kea
# installation. Currently supported operations are:
#
-# - database version check
-# - database version upgrade
+# - lease database init
+# - lease database version check
+# - lease database version upgrade
# Get the location of the kea-admin scripts
printf "\n"
printf "COMMAND: Currently supported operations are:\n"
printf "\n"
- printf " - init: Initalizes new database. Useful for first time installation.\n"
- printf " - version: Checks version of the existing database scheme. Useful\n"
- printf " - for checking DB version when preparing for an upgrade.\n"
- printf " - upgrade: Upgrades your database scheme\n"
+ printf " - lease-init: Initalizes new lease database. Useful for first time installation.\n"
+ printf " - lease-version: Checks version of the existing lease database scheme. Useful\n"
+ printf " - for checking lease DB version when preparing for an upgrade.\n"
+ printf " - lease-upgrade: Upgrades your lease database scheme\n"
printf "\n"
printf "BACKEND - one of the supported backends: memfile|mysql|pgsql\n"
printf "\n"
printf "mysql returned status code $ERRCODE\n"
if [ "$ERRCODE" -eq 0 ]; then
- printf "Version reported after initialization: "
+ printf "Lease DB version reported after initialization: "
mysql_version_print
printf "\n"
fi
# This function prints version before and after upgrade.
mysql_upgrade() {
- printf "Version reported before upgrade: "
+ printf "Lease DB version reported before upgrade: "
mysql_version_print
printf "\n"
fi
# Check if there are any files in it
- num_files=`ls -1 ${scripts_dir}/mysql/upgrade*.sh | wc -l &> /dev/null`
+ num_files=$(find ${scripts_dir}/mysql/upgrade*.sh -type f | wc -l)
if [ $num_files -eq 0 ]; then
log_error "No scripts in ${scripts_dir}/mysql or the directory is not readable or does not have any upgrade* scripts."
exit 1
sh ${script} --user=${db_user} --password=${db_password} ${db_name}
done
- printf "Version reported after upgrade: "
+ printf "Lease DB version reported after upgrade: "
mysql_version_print
printf "\n"
}
usage
exit 1
fi
-is_in_list "${command}" "init version upgrade"
+is_in_list "${command}" "lease-init lease-version lease-upgrade"
if [ ${_inlist} -eq 0 ]; then
log_error "invalid command: ${command}"
exit 1
case ${command} in
# Initialize the database
- init)
+ lease-init)
case ${backend} in
memfile)
memfile_init
;;
esac
;;
- version)
+ lease-version)
case ${backend} in
memfile)
memfile_version
;;
esac
;;
- upgrade)
+ lease-upgrade)
case ${backend} in
memfile)
memfile_upgrade
<refnamediv>
<refname>kea-admin</refname>
- <refpurpose>Shell script for managing Kea database</refpurpose>
+ <refpurpose>Shell script for managing Kea databases</refpurpose>
</refnamediv>
<docinfo>
<refsynopsisdiv>
<cmdsynopsis>
- <command>keactrl</command>
+ <command>kea-admin</command>
<arg>command</arg>
<arg>backend</arg>
<arg><option>-u <replaceable class="parameter">database username</replaceable></option></arg>
<variablelist>
<varlistentry>
- <term>init</term>
+ <term>lease-init</term>
<listitem>
- <para>Initializes a new database. Useful during first Kea installation.</para>
+ <para>Initializes a new lease database. Useful during first Kea
+ installation. The database is initialized to the latest version
+ supported by the version of the software.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term>version</term>
+ <term>lease-version</term>
<listitem>
- <para>Reports database version. This is not necessarily equal to Kea version as
- each backend has its own versionining scheme.</para>
+ <para>Reports lease database version. This is not necessarily
+ equal to Kea version as each backend has its own versioning
+ scheme.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term>upgrade</term>
+ <term>lease-upgrade</term>
<listitem>
- <para>Conducts database upgrade. This is useful when migrating between old and new
- Kea versions.</para>
+ <para>Conducts lease database upgrade. This is useful when
+ migrating between old and new Kea versions.</para>
</listitem>
</varlistentry>
</variablelist>
INSERT INTO lease6_types VALUES (2, "IA_PD"); # Prefix delegations
COMMIT;
-# Finally, the version of the schema. We start at 0.1 during development.
+# Finally, the version of the schema. We start at 1.0 during development.
# This table is only modified during schema upgrades. For historical reasons
# (related to the names of the columns in the BIND 10 DNS database file), the
# first column is called "version" and not "major".
# Infiniband) use up to 20.
ADD COLUMN hwtype smallint unsigned, # hardware type (16 bits)
ADD COLUMN hwaddr_source int unsigned; # Hardware source. See description
- # of lease6_hwaddr_source below.
+ # of lease_hwaddr_source below.
# Kea keeps track of the hardware/MAC address source, i.e. how the address
# was obtained. Depending on the technique and your network topology, it may
# users of the database - if they want to view the lease table and use the
# type names, they can join this table with the lease6 table. For details,
# see constants defined in src/lib/dhcp/dhcp/pkt.h for detailed explanation.
-CREATE TABLE lease6_hwaddr_source (
+CREATE TABLE lease_hwaddr_source (
hwaddr_source INT PRIMARY KEY NOT NULL,
name VARCHAR(40)
);
# Hardware address obtained from raw sockets
-INSERT INTO lease6_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
+INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
# Hardware address converted from IPv6 link-local address with EUI-64
-INSERT INTO lease6_hwaddr_source VALUES (2, "HWADDR_SOURCE_IPV6_LINK_LOCAL");
+INSERT INTO lease_hwaddr_source VALUES (2, "HWADDR_SOURCE_IPV6_LINK_LOCAL");
# Hardware address extracted from client-id (duid)
-INSERT INTO lease6_hwaddr_source VALUES (4, "HWADDR_SOURCE_DUID");
+INSERT INTO lease_hwaddr_source VALUES (4, "HWADDR_SOURCE_DUID");
# Hardware address extracted from client address relay option (RFC6939)
-INSERT INTO lease6_hwaddr_source VALUES (8, "HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION");
+INSERT INTO lease_hwaddr_source VALUES (8, "HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION");
# Hardware address extracted from remote-id option (RFC4649)
-INSERT INTO lease6_hwaddr_source VALUES (16, "HWADDR_SOURCE_REMOTE_ID");
+INSERT INTO lease_hwaddr_source VALUES (16, "HWADDR_SOURCE_REMOTE_ID");
# Hardware address extracted from subscriber-id option (RFC4580)
-INSERT INTO lease6_hwaddr_source VALUES (32, "HWADDR_SOURCE_SUBSCRIBER_ID");
+INSERT INTO lease_hwaddr_source VALUES (32, "HWADDR_SOURCE_SUBSCRIBER_ID");
# Hardware address extracted from docsis options
-INSERT INTO lease6_hwaddr_source VALUES (64, "HWADDR_SOURCE_DOCSIS");
+INSERT INTO lease_hwaddr_source VALUES (64, "HWADDR_SOURCE_DOCSIS");
UPDATE schema_version SET version="2", minor="0";
+++ /dev/null
-#!/bin/sh
-
-# Import common library.
-. /home/thomson/devel/kea/src/bin/admin/admin-utils.sh
-
-mysql_version "$@"
-VERSION=$_RESULT
-
-if [ "$VERSION" != "1.0" ]; then
- printf "This script upgrades 1.0 to 2.0. Reported version is $VERSION. Skipping upgrade.\n"
- exit 0
-fi
-
-mysql "$@" <<EOF
-ALTER TABLE lease6
- ADD COLUMN hwaddr varbinary(20),
- ADD COLUMN hwtype smallint unsigned,
- ADD COLUMN hwaddr_source int unsigned;
-
-CREATE TABLE lease6_hwaddr_source (
- hwaddr_source INT PRIMARY KEY NOT NULL,
- name VARCHAR(40)
-);
-
--- See src/lib/dhcp/dhcp/pkt.h for detailed explanation
-INSERT INTO lease6_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
-INSERT INTO lease6_hwaddr_source VALUES (2, "HWADDR_SOURCE_IPV6_LINK_LOCAL");
-INSERT INTO lease6_hwaddr_source VALUES (4, "HWADDR_SOURCE_DUID");
-INSERT INTO lease6_hwaddr_source VALUES (8, "HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION");
-INSERT INTO lease6_hwaddr_source VALUES (16, "HWADDR_SOURCE_REMOTE_ID");
-INSERT INTO lease6_hwaddr_source VALUES (32, "HWADDR_SOURCE_SUBSCRIBER_ID");
-INSERT INTO lease6_hwaddr_source VALUES (64, "HWADDR_SOURCE_DOCSIS");
-
-UPDATE schema_version SET version="2", minor="0";
-EOF
-
-RESULT=$?
-
-exit $?
--- /dev/null
+#!/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
+
+mysql_version "$@"
+VERSION=$_RESULT
+
+if [ "$VERSION" != "1.0" ]; then
+ printf "This script upgrades 1.0 to 2.0. Reported version is $VERSION. Skipping upgrade.\n"
+ exit 0
+fi
+
+mysql "$@" <<EOF
+ALTER TABLE lease6
+ ADD COLUMN hwaddr varbinary(20),
+ ADD COLUMN hwtype smallint unsigned,
+ ADD COLUMN hwaddr_source int unsigned;
+
+CREATE TABLE lease_hwaddr_source (
+ hwaddr_source INT PRIMARY KEY NOT NULL,
+ name VARCHAR(40)
+);
+
+-- See src/lib/dhcp/dhcp/pkt.h for detailed explanation
+INSERT INTO lease_hwaddr_source VALUES (1, "HWADDR_SOURCE_RAW");
+INSERT INTO lease_hwaddr_source VALUES (2, "HWADDR_SOURCE_IPV6_LINK_LOCAL");
+INSERT INTO lease_hwaddr_source VALUES (4, "HWADDR_SOURCE_DUID");
+INSERT INTO lease_hwaddr_source VALUES (8, "HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION");
+INSERT INTO lease_hwaddr_source VALUES (16, "HWADDR_SOURCE_REMOTE_ID");
+INSERT INTO lease_hwaddr_source VALUES (32, "HWADDR_SOURCE_SUBSCRIBER_ID");
+INSERT INTO lease_hwaddr_source VALUES (64, "HWADDR_SOURCE_DOCSIS");
+
+UPDATE schema_version SET version="2", minor="0";
+EOF
+
+RESULT=$?
+
+exit $?
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-# This is the BIND 10 DHCP schema specification for MySQL.
+# This is the Kea schema 1.0 specification for MySQL.
+# Note: this is outdated version on purpose and it used to test upgrade
+# process. Do not update this file to 2.0 or any later.
#
# The schema is reasonably portable (with the exception of the engine
# specification, which is MySQL-specific). Minor changes might be needed for
EOF
}
-mysql_init_test() {
- test_start "mysql.init"
+mysql_lease_init_test() {
+ test_start "mysql.lease-init"
# Let's wipe the whole database
mysql_wipe
# Ok, now let's initalize the database
- ${keaadmin} init mysql -u $db_user -p $db_pass -n $db_name
+ ${keaadmin} lease-init mysql -u $db_user -p $db_pass -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts
ERRCODE=$?
- assert_eq 0 $ERRCODE "kea-admin init mysql returned non-zero status code %d, expected %d"
+ 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.
ERRCODE=$?
assert_eq 0 $ERRCODE "lease6_types table is missing or broken. (returned status code %d, expected %d)"
- # Fifth table: lease6_hwaddr_source
+ # Fifth table: lease_hwaddr_source
mysql -u$db_user -p$db_pass $db_name &>/dev/null <<EOF
- SELECT hwaddr_source, name FROM lease6_hwaddr_source;
+ SELECT hwaddr_source, name FROM lease_hwaddr_source;
EOF
ERRCODE=$?
- assert_eq 0 $ERRCODE "lease6_hwaddr_source table is missing or broken. (returned status code %d, expected %d)"
+ assert_eq 0 $ERRCODE "lease_hwaddr_source table is missing or broken. (returned status code %d, expected %d)"
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
-mysql_version_test() {
- test_start "mysql.version"
+mysql_lease_version_test() {
+ test_start "mysql.lease-version"
# Let's wipe the whole database
mysql_wipe
INSERT INTO schema_version VALUES (1, 7);
EOF
- version=$(${keaadmin} version mysql -u $db_user -p $db_pass -n $db_name)
+ version=$(${keaadmin} lease-version mysql -u $db_user -p $db_pass -n $db_name)
assert_str_eq "1.7" ${version} "Expected kea-admin to return %s, returned value was %s"
test_finish 0
}
-mysql_upgrade_test() {
- test_start "mysql.upgrade"
+mysql_lease_upgrade_test() {
+ test_start "mysql.lease-upgrade"
# Let's wipe the whole database
mysql_wipe
mysql -u$db_user -p$db_pass $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} version mysql -u $db_user -p $db_pass -n $db_name)
+ version=$(${keaadmin} lease-version mysql -u $db_user -p $db_pass -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts)
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
- ${keaadmin} upgrade mysql -u $db_user -p $db_pass -n $db_name
+ ${keaadmin} lease-upgrade mysql -u $db_user -p $db_pass -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts
ERRCODE=$?
- assert_eq 0 $ERRCODE "kea-admin upgrade mysql returned non-zero status code %d, expected %d"
+ 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.
ERRCODE=$?
assert_eq 0 $ERRCODE "lease6 table not upgraded to 2.0 (returned status code %d, expected %d)"
- # Fifth table: lease6_hwaddr_source
+ # Fifth table: lease_hwaddr_source
mysql -u$db_user -p$db_pass $db_name &>/dev/null <<EOF
- SELECT hwaddr_source, name FROM lease6_hwaddr_source;
+ SELECT hwaddr_source, name FROM lease_hwaddr_source;
EOF
ERRCODE=$?
- assert_eq 0 $ERRCODE "lease6_hwaddr_source table is missing or broken. (returned status code %d, expected %d)"
+ 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.
- version=$(${keaadmin} version mysql -u $db_user -p $db_pass -n $db_name)
+ version=$(${keaadmin} lease-version mysql -u $db_user -p $db_pass -n $db_name)
assert_str_eq "2.0" ${version} "Expected kea-admin to return %s, returned value was %s"
test_finish 0
}
-mysql_init_test
-mysql_version_test
-mysql_upgrade_test
+mysql_lease_init_test
+mysql_lease_version_test
+mysql_lease_upgrade_test