2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#2276] Upgrade global param values in DB

Convert ddns-use-conflict-resolution to
ddns-conflict-resolution-mode in DB

configure.ac
    Added new upgrade files

src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
    new upgrade tests

src/lib/mysql/mysql_constants.h
src/lib/pgsql/pgsql_connection.h
    update schema version

src/share/database/scripts/mysql/.gitignore
src/share/database/scripts/mysql/Makefile.am
src/share/database/scripts/mysql/upgrade_019_to_020.sh.in
    new upgrade script

src/share/database/scripts/mysql/dhcpdb_create.mysql
    added conversion logic to stay in sync with upgrade script

src/share/database/scripts/pgsql/Makefile.am
src/share/database/scripts/pgsql/.gitignore
src/share/database/scripts/pgsql/upgrade_018_to_019.sh.in
    new upgrade script

src/share/database/scripts/pgsql/dhcpdb_create.pgsql
    added conversion logic to stay in sync with upgrade script
This commit is contained in:
Thomas Markwalder
2023-07-06 10:24:26 -04:00
parent 1a54201a1c
commit e87c11fe28
13 changed files with 368 additions and 5 deletions

View File

@@ -1704,6 +1704,8 @@ AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_017_to_018.sh],
[chmod +x src/share/database/scripts/mysql/upgrade_017_to_018.sh])
AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_018_to_019.sh],
[chmod +x src/share/database/scripts/mysql/upgrade_018_to_019.sh])
AC_CONFIG_FILES([src/share/database/scripts/mysql/upgrade_019_to_020.sh],
[chmod +x src/share/database/scripts/mysql/upgrade_019_to_020.sh])
AC_CONFIG_FILES([src/share/database/scripts/mysql/wipe_data.sh],
[chmod +x src/share/database/scripts/mysql/wipe_data.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/Makefile])
@@ -1753,6 +1755,8 @@ AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_016_to_017.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_016_to_017.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_017_to_018.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_017_to_018.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/upgrade_018_to_019.sh],
[chmod +x src/share/database/scripts/pgsql/upgrade_018_to_019.sh])
AC_CONFIG_FILES([src/share/database/scripts/pgsql/wipe_data.sh],
[chmod +x src/share/database/scripts/pgsql/wipe_data.sh])
AC_CONFIG_FILES([src/share/yang/Makefile])

View File

@@ -814,6 +814,14 @@ mysql_upgrade_18_to_19_test() {
run_statement "ipv6_reservations_insert" "$qry" "3001::99"
}
mysql_upgrade_19_to_20_test() {
# The function, mysql_ddns_conflict_resolution_mode_update_test, is called explicitly
# and tests conversion of ddns-use-conflict-resolution to ddns-conflict-resolution-mode.
# For now this function only verifies version number.
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "20.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
}
mysql_upgrade_test() {
test_start "mysql.upgrade"
@@ -835,7 +843,7 @@ mysql_upgrade_test() {
# Verify that the upgraded schema reports the latest version.
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "19.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "20.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's check that the new tables are indeed there.
@@ -1498,6 +1506,9 @@ SET @disable_audit = 0"
# Check upgrade from 18.0 to 19.0.
mysql_upgrade_18_to_19_test
# Check upgrade from 19.0 to 20.0.
mysql_upgrade_19_to_20_test
# Let's wipe the whole database
mysql_wipe
@@ -2865,6 +2876,69 @@ insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that CB global parameter entries for 'ddns-use-conflict-resolution'
# will get translated to 'ddns-conflict-resolution-mode'.
mysql_ddns_conflict_resolution_mode_update_test() {
test_start "mysql.ddns_conflict_resolution_mode_update_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database.
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
# Now upgrade to schema 19.0.
mysql_upgrade_schema_to_version 19.0
# Now insert global parameter instances of ddns-use-conflict-resolution.
sql=\
"set @disable_audit = 1; \
insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'false', current_time(),2);
insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'true', current_time(),2);
insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'false', current_time(),2);
insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'true', current_time(),2);"
run_statement "insert ddns_conflict_resolution_mode" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 4_global parameter count before update" "$qry" 2
qry="select count(*) from dhcp6_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 6_global parameter count before update" "$qry" 2
# Upgrade to schema 20.0
mysql_upgrade_schema_to_version 20.0
# Verify we converted parameters correctly.
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 4_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 4_no-check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 6_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 6_no-check-with-dhcid after update" "$qry" 1
# Let's wipe the whole database
mysql_wipe
test_finish 0
}
# Run tests.
mysql_db_init_test
mysql_host_reservation_init_test
@@ -2890,3 +2964,5 @@ mysql_client_class_test dhcp6
mysql_shrink_server_tag_test
mysql_update_empty_duid_test
mysql_update_v6_addresses_to_binary
mysql_ddns_conflict_resolution_mode_update_test

View File

@@ -143,7 +143,7 @@ pgsql_db_version_test() {
run_command \
"${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
version="${OUTPUT}"
assert_str_eq "18.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
assert_str_eq "19.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
# Let's wipe the whole database
pgsql_wipe
@@ -868,6 +868,14 @@ pgsql_upgrade_17_to_18_test() {
run_statement "ipv6_reservations_insert" "$qry" "3001::99"
}
pgsql_upgrade_18_to_19_test() {
# The function, pgsql_ddns_conflict_resolution_mode_update_test, is called explicitly
# and tests conversion of ddns-use-conflict-resolution to ddns-conflict-resolution-mode.
# For now this function only verifies version number.
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "19.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
}
pgsql_upgrade_test() {
test_start "pgsql.upgrade"
@@ -886,7 +894,7 @@ pgsql_upgrade_test() {
# Verify upgraded schema reports the latest version.
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
assert_str_eq "18.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
assert_str_eq "19.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
# Check 1.0 to 2.0 upgrade
pgsql_upgrade_1_0_to_2_0_test
@@ -936,6 +944,9 @@ pgsql_upgrade_test() {
# Check 17 to 18 upgrade
pgsql_upgrade_17_to_18_test
# Check 18 to 19 upgrade
pgsql_upgrade_18_to_19_test
# Let's wipe the whole database
pgsql_wipe
@@ -2047,6 +2058,73 @@ insert into ipv6_reservations (address, prefix_len, type, dhcp6_iaid, host_id) \
test_finish 0
}
# Verifies that you can upgrade from an earlier version and
# that reservation_mode values in subnet and shared network tables are
# converted to new reservations flags.
pgsql_ddns_conflict_resolution_mode_update_test() {
test_start "pgsql_ddns_conflict_resolution_mode_update_test"
# Let's wipe the whole database
pgsql_wipe
# We need to create an older database with lease data so we can
# verify the upgrade mechanisms which prepopulate the lease stat
# tables.
#
# Initialize database to schema 1.0.
pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
# Now upgrade to schema 18.0
pgsql_upgrade_schema_to_version 18.0
# Now we need insert some subnets and shared networks.
sql=\
"select set_config('kea.disable_audit', 'true', false);\
insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'false', current_timestamp, 2);
insert into dhcp4_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'true', current_timestamp, 2);
insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'false', current_timestamp,2);
insert into dhcp6_global_parameter (name,value, modification_ts,parameter_type)\
values ('ddns-use-conflict-resolution', 'true', current_timestamp, 2);"
run_statement "insert ddns_conflict_resolution_mode" "$sql"
# Verify the inserted record counts.
qry="select count(*) from dhcp4_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 4_global parameter count before update" "$qry" 2
qry="select count(*) from dhcp6_global_parameter where name='ddns-use-conflict-resolution';"
run_statement "#get 6_global parameter count before update" "$qry" 2
# Upgrade to schema 19.0
pgsql_upgrade_schema_to_version 19.0
# Verify we converted parameters correctly.
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 4_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp4_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 4_no-check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='check-with-dhcid'"
run_statement "#get 6_check-with-dhcid after update" "$qry" 1
qry="select count(*) from dhcp6_global_parameter where name='ddns-conflict-resolution-mode' and\
value='no-check-with-dhcid'"
run_statement "#get 6_no-check-with-dhcid after update" "$qry" 1
# Let's wipe the whole database
pgsql_wipe
test_finish 0
}
# Run tests.
pgsql_db_init_test
pgsql_db_version_test
@@ -2066,3 +2144,4 @@ pgsql_lease_stat_recount_test
pgsql_unused_subnet_id_test
pgsql_update_empty_duid_test
pgsql_update_v6_addresses_to_binary
pgsql_ddns_conflict_resolution_mode_update_test

View File

@@ -52,7 +52,7 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
/// @name Current database schema version values.
//@{
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 19;
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 20;
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
//@}

View File

@@ -18,7 +18,7 @@ namespace isc {
namespace db {
/// @brief Define the PostgreSQL backend version.
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 18;
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 19;
const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
// Maximum number of parameters that can be used a statement

View File

@@ -27,4 +27,5 @@
/upgrade_016_to_017.sh
/upgrade_017_to_018.sh
/upgrade_018_to_019.sh
/upgrade_019_to_020.sh
/wipe_data.sh

View File

@@ -38,6 +38,7 @@ mysql_SCRIPTS += upgrade_015_to_016.sh
mysql_SCRIPTS += upgrade_016_to_017.sh
mysql_SCRIPTS += upgrade_017_to_018.sh
mysql_SCRIPTS += upgrade_018_to_019.sh
mysql_SCRIPTS += upgrade_019_to_020.sh
mysql_SCRIPTS += wipe_data.sh
DISTCLEANFILES = ${mysql_SCRIPTS}

View File

@@ -5812,6 +5812,32 @@ UPDATE schema_version
-- This line concludes the schema upgrade to version 19.0.
-- This line starts the schema upgrade to version 20.0.
-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
SET @disable_audit = 1;
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
-- Update the schema version number.
UPDATE schema_version
SET version = '20', minor = '0';
-- This line concludes the schema upgrade to version 20.0.
# Notes:
#
# Indexes

View File

@@ -0,0 +1,81 @@
#!/bin/sh
# Copyright (C) 2023 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# shellcheck disable=SC1091
# SC1091: Not following: ... was not specified as input (see shellcheck -x).
# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu
# shellcheck disable=SC2034
# SC2034: ... appears unused. Verify use (or export if used externally).
prefix="@prefix@"
# Include utilities. Use installed version if available and
# use build version if it isn't.
if test -f "@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
# Check version.
version=$(mysql_version "${@}")
if test "${version}" != "19.0"; then
printf 'This script upgrades 19.0 to 20.0. '
printf 'Reported version is %s. Skipping upgrade.\n' "${version}"
exit 0
fi
# Get the schema name from database argument. We need this to
# query information_schema for the right database.
for arg in "${@}"
do
if ! printf '%s' "${arg}" | grep -Eq -- '^--'
then
schema="$arg"
break
fi
done
# Make sure we have the schema.
if [ -z "$schema" ]
then
printf "Could not find database schema name in cmd line args: %s\n" "${*}"
exit 255
fi
mysql "$@" <<EOF
-- This line starts the schema upgrade to version 20.0.
-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
SET @disable_audit = 1;
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
-- Update the schema version number.
UPDATE schema_version
SET version = '20', minor = '0';
-- This line concludes the schema upgrade to version 20.0.
EOF

View File

@@ -21,4 +21,5 @@
/upgrade_015_to_016.sh
/upgrade_016_to_017.sh
/upgrade_017_to_018.sh
/upgrade_018_to_019.sh
/wipe_data.sh

View File

@@ -32,6 +32,7 @@ pgsql_SCRIPTS += upgrade_014_to_015.sh
pgsql_SCRIPTS += upgrade_015_to_016.sh
pgsql_SCRIPTS += upgrade_016_to_017.sh
pgsql_SCRIPTS += upgrade_017_to_018.sh
pgsql_SCRIPTS += upgrade_018_to_019.sh
pgsql_SCRIPTS += wipe_data.sh
DISTCLEANFILES = ${pgsql_SCRIPTS}

View File

@@ -6264,6 +6264,32 @@ UPDATE schema_version
-- This line concludes the schema upgrade to version 18.0.
-- This line starts the schema upgrade to version 19.0.
-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
SELECT set_config('kea.disable_audit', 'true', false);
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
-- Update the schema version number.
UPDATE schema_version
SET version = '19', minor = '0';
-- This line concludes the schema upgrade to version 19.0.
-- Commit the script transaction.
COMMIT;

View File

@@ -0,0 +1,67 @@
#!/bin/sh
# Copyright (C) 2023 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# shellcheck disable=SC1091
# SC1091: Not following: ... was not specified as input (see shellcheck -x).
# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu
# shellcheck disable=SC2034
# SC2034: ... appears unused. Verify use (or export if used externally).
prefix="@prefix@"
# Include utilities. Use installed version if available and
# use build version if it isn't.
if test -f "@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=$(pgsql_version "$@")
if [ "$VERSION" != "18.0" ]; then
printf 'This script upgrades 18.0 to 19.0. '
printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
exit 0
fi
psql "$@" >/dev/null <<EOF
-- This line starts the schema upgrade to version 19.0.
-- Convert ddns-use-conflict-resolution to ddns-conflict-resolution-mode
SELECT set_config('kea.disable_audit', 'true', false);
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp4_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'true';
UPDATE dhcp6_global_parameter
SET name = 'ddns-conflict-resolution-mode', value = 'no-check-with-dhcid', parameter_type = 4
WHERE name = 'ddns-use-conflict-resolution' and value = 'false';
-- Update the schema version number.
UPDATE schema_version
SET version = '19', minor = '0';
-- This line concludes the schema upgrade to version 19.0.
-- Commit the script transaction.
COMMIT;
EOF