[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])
[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])
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"
# 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.
# 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
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
mysql_shrink_server_tag_test
mysql_update_empty_duid_test
mysql_update_v6_addresses_to_binary
+mysql_ddns_conflict_resolution_mode_update_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
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"
# 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
# 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
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
pgsql_unused_subnet_id_test
pgsql_update_empty_duid_test
pgsql_update_v6_addresses_to_binary
+pgsql_ddns_conflict_resolution_mode_update_test
/// @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;
//@}
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
/upgrade_016_to_017.sh
/upgrade_017_to_018.sh
/upgrade_018_to_019.sh
+/upgrade_019_to_020.sh
/wipe_data.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}
-- 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
--- /dev/null
+#!/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
/upgrade_015_to_016.sh
/upgrade_016_to_017.sh
/upgrade_017_to_018.sh
+/upgrade_018_to_019.sh
/wipe_data.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}
-- 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;
--- /dev/null
+#!/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