mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[4237] Fixes #4238, adds lease dump order by, bumps MySQL schema to 4.1
Bumps MySQL schema version from 4.0 to 4.1. Fixes the issue spelled out in 4238 by adding an entry for hardware address source of zero. This change was added here to limit the number of schema version bumps. Changes the MySQL lease dump functions to order by the lease address. This ensures the dumps always ordered in a predictable manner. src/bin/admin/scripts/mysql/upgrade_4.0_to_4.1.sh.in New file to upgrade from 4.0 to 4.1 configure.ac Added entry for mysql/upgrade_4.0_to_4.1.sh src/bin/admin/scripts/mysql/Makefile.am Added entry form upgrade_4.0_to_4.1.sh src/bin/admin/scripts/mysql/dhcpdb_create.mysql Added insert of HWADDR_SOURCE_UNKNOWN into lease_hwaddr_source Added order by clauses to lease4DumpData and lease6DumpData Updated schema version from 4.0 to 4.1 src/bin/admin/tests/mysql_tests.sh.in mysql_upgrade_test() Added test for 4.0 to 4.1 upgrade Changed final version check to 4.1
This commit is contained in:
@@ -1417,6 +1417,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
|
||||
src/bin/admin/scripts/mysql/upgrade_1.0_to_2.0.sh
|
||||
src/bin/admin/scripts/mysql/upgrade_2.0_to_3.0.sh
|
||||
src/bin/admin/scripts/mysql/upgrade_3.0_to_4.0.sh
|
||||
src/bin/admin/scripts/mysql/upgrade_4.0_to_4.1.sh
|
||||
src/bin/admin/scripts/pgsql/Makefile
|
||||
src/bin/admin/scripts/pgsql/upgrade_1.0_to_2.0.sh
|
||||
src/hooks/Makefile
|
||||
|
@@ -5,5 +5,6 @@ sqlscripts_DATA = dhcpdb_create.mysql
|
||||
sqlscripts_DATA += upgrade_1.0_to_2.0.sh
|
||||
sqlscripts_DATA += upgrade_2.0_to_3.0.sh
|
||||
sqlscripts_DATA += upgrade_3.0_to_4.0.sh
|
||||
sqlscripts_DATA += upgrade_4.0_to_4.1.sh
|
||||
|
||||
EXTRA_DIST = ${sqlscripts_DATA}
|
||||
|
@@ -342,9 +342,10 @@ SELECT
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
s.name
|
||||
from
|
||||
FROm
|
||||
lease4 l
|
||||
LEFT OUTER JOIN lease_state s on (l.state = s.state);
|
||||
LEFT OUTER JOIN lease_state s on (l.state = s.state)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
@@ -382,15 +383,27 @@ SELECT
|
||||
FROM lease6 l
|
||||
left outer join lease6_types t on (l.lease_type = t.lease_type)
|
||||
left outer join lease_state s on (l.state = s.state)
|
||||
left outer join lease_hwaddr_source h on (l.hwaddr_source = h.hwaddr_source);
|
||||
left outer join lease_hwaddr_source h on (l.hwaddr_source = h.hwaddr_source)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '4', minor = '0';
|
||||
|
||||
# This line concludes database upgrade to version 4.0.
|
||||
|
||||
# In the event hardware address cannot be determined, we need to satisfy
|
||||
# foreign key constraint between lease6 and lease_hardware_source
|
||||
INSERT INTO lease_hwaddr_source VALUES (0, "HWADDR_SOURCE_UNKNOWN");
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '4', minor = '1';
|
||||
|
||||
# This line concludes database upgrade to version 4.1.
|
||||
|
||||
# Notes:
|
||||
#
|
||||
# Indexes
|
||||
|
90
src/bin/admin/scripts/mysql/upgrade_4.0_to_4.1.sh.in
Executable file
90
src/bin/admin/scripts/mysql/upgrade_4.0_to_4.1.sh.in
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/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" != "4.0" ]; then
|
||||
printf "This script upgrades 4.0 to 4.1. Reported version is $VERSION. Skipping upgrade.\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mysql "$@" <<EOF
|
||||
|
||||
# In the event hardware address cannot be determined, we need to satisfy
|
||||
# foreign key constraint between lease6 and lease_hardware_source
|
||||
INSERT INTO lease_hwaddr_source VALUES (0, "HWADDR_SOURCE_UNKNOWN");
|
||||
|
||||
#
|
||||
# Add order by lease address to lease4DumpData
|
||||
#
|
||||
DROP PROCEDURE IF EXISTS lease4DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease4DumpData()
|
||||
BEGIN
|
||||
SELECT
|
||||
INET_NTOA(l.address),
|
||||
IFNULL(HEX(l.hwaddr), ''),
|
||||
IFNULL(HEX(l.client_id), ''),
|
||||
l.valid_lifetime,
|
||||
l.expire,
|
||||
l.subnet_id,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
s.name
|
||||
FROM
|
||||
lease4 l
|
||||
LEFT OUTER JOIN lease_state s on (l.state = s.state)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
#
|
||||
# Add order by lease address to lease6DumpData
|
||||
#
|
||||
DROP PROCEDURE IF EXISTS lease6DumpData;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE lease6DumpData()
|
||||
BEGIN
|
||||
SELECT
|
||||
l.address,
|
||||
IFNULL(HEX(l.duid), ''),
|
||||
l.valid_lifetime,
|
||||
l.expire,
|
||||
l.subnet_id,
|
||||
l.pref_lifetime,
|
||||
IFNULL(t.name, ''),
|
||||
l.iaid,
|
||||
l.prefix_len,
|
||||
l.fqdn_fwd,
|
||||
l.fqdn_rev,
|
||||
l.hostname,
|
||||
IFNULL(HEX(l.hwaddr), ''),
|
||||
IFNULL(l.hwtype, ''),
|
||||
IFNULL(h.name, ''),
|
||||
IFNULL(s.name, '')
|
||||
FROM lease6 l
|
||||
left outer join lease6_types t on (l.lease_type = t.lease_type)
|
||||
left outer join lease_state s on (l.state = s.state)
|
||||
left outer join lease_hwaddr_source h on (l.hwaddr_source = h.hwaddr_source)
|
||||
ORDER BY l.address;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '4', minor = '1';
|
||||
# This line concludes database upgrade to version 4.1.
|
||||
|
||||
EOF
|
||||
|
||||
RESULT=$?
|
||||
|
||||
exit $?
|
@@ -207,7 +207,7 @@ mysql_upgrade_test() {
|
||||
|
||||
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 4.0
|
||||
# Ok, we have a 1.0 database. Let's upgrade it to 4.1
|
||||
${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts
|
||||
ERRCODE=$?
|
||||
|
||||
@@ -257,7 +257,6 @@ 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.
|
||||
#table: lease_state table added (upgrade 3.0 -> 4.0)
|
||||
mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
|
||||
SELECT state,name from lease_state;
|
||||
@@ -286,10 +285,34 @@ EOF
|
||||
ERRCODE=$?
|
||||
assert_eq 0 $ERRCODE "lease dump stored procedures are missing or broken. (returned status code %d, expected %d)"
|
||||
|
||||
# Verify that it reports version 4.0.
|
||||
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name)
|
||||
#lease_hardware_source should have row for source = 0 (upgrade 4.0 -> 4.1)
|
||||
qry="select count(hwaddr_source) from lease_hwaddr_source where hwaddr_source = 0 and name='HWADDR_SOURCE_UNKNOWN';"
|
||||
count=`mysql_execute "${qry}"`
|
||||
ERRCODE=$?
|
||||
assert_eq 0 $ERRCODE "select from lease_hwaddr_source failed. (returned status code %d, expected %d)"
|
||||
assert_eq 1 "$count" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UKNOWN. (record count %d, expected %d)"
|
||||
|
||||
# table: stored procedures for lease data dumps were modified (upgrade 4.0 -> 4.1)
|
||||
# verify lease4DumpData has order by lease address
|
||||
qry="show create procedure lease4DumpData"
|
||||
text=`mysql_execute "${qry}"`
|
||||
ERRCODE=$?
|
||||
assert_eq 0 $ERRCODE "procedure text fetch for lease4DumpData failed. (returned status code %d, expected %d)"
|
||||
count=`echo $text | grep -ic "order by l\.address"`
|
||||
assert_eq 1 $count "lease4DumpData doesn't have order by clause. (returned count %d, expected %d)"
|
||||
|
||||
# verify lease6DumpData has order by lease address
|
||||
qry="show create procedure lease6DumpData"
|
||||
text=`mysql_execute "${qry}"`
|
||||
ERRCODE=$?
|
||||
assert_eq 0 $ERRCODE "procedure text fetch for lease6DumpData failed. (returned status code %d, expected %d)"
|
||||
count=`echo $text | grep -ic "order by l\.address"`
|
||||
assert_eq 1 $count "lease6DumpData doesn't have order by clause. (returned count %d, expected %d)"
|
||||
|
||||
# Verify upgraded schemd reports version 4.1.
|
||||
version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d @abs_top_srcdir@/src/bin/admin/scripts)
|
||||
assert_str_eq "4.1" ${version} "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
assert_str_eq "4.0" ${version} "Expected kea-admin to return %s, returned value was %s"
|
||||
|
||||
# Let's wipe the whole database
|
||||
mysql_wipe
|
||||
|
Reference in New Issue
Block a user