From: Tomek Mrugalski Date: Fri, 5 Dec 2014 22:33:53 +0000 (+0100) Subject: [3599] Changes after review X-Git-Tag: kea-eng-20141219~9^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35357a30fa385aedbedc6418e445769ca5b2285c;p=thirdparty%2Fkea.git [3599] Changes after review - mysql/upgrade_1.0_to_2.0.sh renamed to .in - header added to admin-utils.sh, revoked exec bit - kea-admin clarified (db => lease db) - kea-admin manpage corrected - lease6_hwaddr_source renamed to lease_hwaddr_source - mysql_tests are now working without installation --- diff --git a/configure.ac b/configure.ac index b9959c338c..5248ed4a5c 100644 --- a/configure.ac +++ b/configure.ac @@ -1400,6 +1400,7 @@ AC_CONFIG_FILES([compatcheck/Makefile 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 diff --git a/src/bin/admin/admin-utils.sh b/src/bin/admin/admin-utils.sh old mode 100755 new mode 100644 index 6cd740bcc5..f1b621da11 --- a/src/bin/admin/admin-utils.sh +++ b/src/bin/admin/admin-utils.sh @@ -1,4 +1,18 @@ -#!/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, diff --git a/src/bin/admin/kea-admin.in b/src/bin/admin/kea-admin.in index 39281a2fa2..79025b4e18 100644 --- a/src/bin/admin/kea-admin.in +++ b/src/bin/admin/kea-admin.in @@ -17,8 +17,9 @@ # 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 @@ -51,10 +52,10 @@ usage() { 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" @@ -148,7 +149,7 @@ mysql_init() { 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 @@ -188,7 +189,7 @@ memfile_upgrade() { # 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" @@ -199,7 +200,7 @@ mysql_upgrade() { 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 @@ -211,7 +212,7 @@ mysql_upgrade() { 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" } @@ -230,7 +231,7 @@ if [ -z ${command} ]; then 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 @@ -305,7 +306,7 @@ done case ${command} in # Initialize the database - init) + lease-init) case ${backend} in memfile) memfile_init @@ -318,7 +319,7 @@ case ${command} in ;; esac ;; - version) + lease-version) case ${backend} in memfile) memfile_version @@ -332,7 +333,7 @@ case ${command} in ;; esac ;; - upgrade) + lease-upgrade) case ${backend} in memfile) memfile_upgrade diff --git a/src/bin/admin/kea-admin.xml b/src/bin/admin/kea-admin.xml index 84730b88f2..e08c190954 100644 --- a/src/bin/admin/kea-admin.xml +++ b/src/bin/admin/kea-admin.xml @@ -30,7 +30,7 @@ kea-admin - Shell script for managing Kea database + Shell script for managing Kea databases @@ -42,7 +42,7 @@ - keactrl + kea-admin command backend @@ -73,25 +73,28 @@ - init + lease-init - Initializes a new database. Useful during first Kea installation. + 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. - version + lease-version - Reports database version. This is not necessarily equal to Kea version as - each backend has its own versionining scheme. + Reports lease database version. This is not necessarily + equal to Kea version as each backend has its own versioning + scheme. - upgrade + lease-upgrade - Conducts database upgrade. This is useful when migrating between old and new - Kea versions. + Conducts lease database upgrade. This is useful when + migrating between old and new Kea versions. diff --git a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql index 231a0b1a53..4ab7dab096 100644 --- a/src/bin/admin/scripts/mysql/dhcpdb_create.mysql +++ b/src/bin/admin/scripts/mysql/dhcpdb_create.mysql @@ -99,7 +99,7 @@ INSERT INTO lease6_types VALUES (1, "IA_TA"); # Temporary v6 addresses 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". @@ -125,7 +125,7 @@ ALTER TABLE lease6 # 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 @@ -133,31 +133,31 @@ ALTER TABLE lease6 # 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"; diff --git a/src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh b/src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh deleted file mode 100644 index ffd82b7d8d..0000000000 --- a/src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/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 "$@" </dev/null </dev/null <