diff --git a/configure.ac b/configure.ac index 9ef5eaa370..8beb2aeb28 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 889ce522bb..4f4d42f8da 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -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 + diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index f9b839e20d..08d6b0deb0 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -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 diff --git a/src/lib/mysql/mysql_constants.h b/src/lib/mysql/mysql_constants.h index 0f2cc1c8fc..4ea90a74db 100644 --- a/src/lib/mysql/mysql_constants.h +++ b/src/lib/mysql/mysql_constants.h @@ -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; //@} diff --git a/src/lib/pgsql/pgsql_connection.h b/src/lib/pgsql/pgsql_connection.h index 4e8c21a5b1..f5d1f134ab 100644 --- a/src/lib/pgsql/pgsql_connection.h +++ b/src/lib/pgsql/pgsql_connection.h @@ -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 diff --git a/src/share/database/scripts/mysql/.gitignore b/src/share/database/scripts/mysql/.gitignore index 195dfc3841..7f4b2dbf04 100644 --- a/src/share/database/scripts/mysql/.gitignore +++ b/src/share/database/scripts/mysql/.gitignore @@ -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 diff --git a/src/share/database/scripts/mysql/Makefile.am b/src/share/database/scripts/mysql/Makefile.am index 8849bf18fe..ee95d34b37 100644 --- a/src/share/database/scripts/mysql/Makefile.am +++ b/src/share/database/scripts/mysql/Makefile.am @@ -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} diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index d05ccaede0..0e78580510 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -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 diff --git a/src/share/database/scripts/mysql/upgrade_019_to_020.sh.in b/src/share/database/scripts/mysql/upgrade_019_to_020.sh.in new file mode 100644 index 0000000000..8d15c44a60 --- /dev/null +++ b/src/share/database/scripts/mysql/upgrade_019_to_020.sh.in @@ -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 "$@" </dev/null <