summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2024-12-03 21:21:17 +0100
committerThomas Markwalder <tmark@isc.org>2024-12-06 15:16:04 +0100
commit5e6e9738e06b5a83bb16f253a902a09ba6f521af (patch)
tree22f6920abc3185c0cc65995a48d930a7df73ae5f /src
parent[#1989] Addressed review comment (diff)
downloadkea-5e6e9738e06b5a83bb16f253a902a09ba6f521af.tar.xz
kea-5e6e9738e06b5a83bb16f253a902a09ba6f521af.zip
[#3677] MySQL now migrates client_classes data
src/bin/admin/tests/mysql_tests.sh.in mysql_migrate_client_class_test() - new test src/share/database/scripts/mysql/dhcpdb_create.mysql src/share/database/scripts/mysql/upgrade_026_to_027.sh.in Added migration of client_classes data
Diffstat (limited to 'src')
-rw-r--r--src/bin/admin/tests/mysql_tests.sh.in126
-rw-r--r--src/share/database/scripts/mysql/dhcpdb_create.mysql34
-rw-r--r--src/share/database/scripts/mysql/upgrade_026_to_027.sh.in34
3 files changed, 194 insertions, 0 deletions
diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in
index 7150c8b2fd..2f55d3a9e8 100644
--- a/src/bin/admin/tests/mysql_tests.sh.in
+++ b/src/bin/admin/tests/mysql_tests.sh.in
@@ -3609,6 +3609,131 @@ mysql_remove_control_socket_parameters_test() {
test_finish 0
}
+# Verifies that client_class to client_classes migrates
+# single text entries to JSON list correctly
+mysql_migrate_client_class_test() {
+ test_start "mysql.migrate_client_class_test"
+
+ # Let's wipe the whole database
+ mysql_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.
+ 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 4.0, this has lease_state in it
+ mysql_upgrade_schema_to_version 26.0
+
+ # Now we need insert some leases to "migrate" for both v4 and v6
+ qry=\
+"set @disable_audit 1;\
+ insert into dhcp4_shared_network (name, client_classes) values ('aaa', 'abc');\
+ insert into dhcp4_shared_network (name, client_classes) values ('bbb', '');\
+ insert into dhcp4_shared_network (name) values ('ccc');\
+ set @disable_audit 0;\
+ run_statement "insert v4 networks" "$qry"
+
+ # Let's upgrade it to the latest version.
+ run_command \
+ "${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+
+ qry="select client_classes from dhcp4_shared_network where name = 'aaa' and client_classes = '[ \"abc\" ]';
+ run_statement "#4.1" "$qry" 1
+
+ mysql_wipe
+
+ test_finish 0
+}
+
+# Verifies that client_class to client_classes migrates
+# single text entries to JSON list correctly
+mysql_migrate_client_class_test() {
+ test_start "mysql.migrate_client_class_test"
+
+ # Let's wipe the whole database
+ mysql_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.
+ 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 4.0, this has lease_state in it
+ mysql_upgrade_schema_to_version 26.0
+
+ # Now we need insert some leases to "migrate" for both v4 and v6
+ qry="\
+ set @disable_audit = 1;\
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net1', 'abc', current_timestamp);\
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net2', '', current_timestamp);\
+ insert into dhcp4_shared_network (name, modification_ts) values ('net3', current_timestamp);\
+ insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
+ values (1, '192.0.0.0/24', current_timestamp, 'subber');\
+ insert into dhcp4_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
+ values (1, INET_ATON('192.0.0.0'), INET_ATON('192.0.0.1'), current_timestamp, 'poolio');\
+ insert into dhcp6_shared_network (name, client_class, modification_ts) values ('net6', 'xyz', current_timestamp);\
+ insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
+ values (6, '2001:db8:1::/64', current_timestamp, 'subber6');\
+ insert into dhcp6_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
+ values (6, ('2001:db8:1::1'), ('2001:db8:1::2'), current_timestamp, 'poolio6');\
+ insert into dhcp6_pd_pool (subnet_id, prefix, prefix_length, delegated_prefix_length, \
+ excluded_prefix_length, modification_ts, client_class) \
+ values (6, ('3001::'), 64, 72, 0, current_timestamp, 'pd_poolio');\
+ set @disable_audit = 0;\
+ "
+ run_statement "insert v4 networks" "$qry"
+
+ # Let's upgrade it to the latest version.
+ run_command \
+ "${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+
+ # Verify dhcp4_shared_network values
+ qry="select count(name) from dhcp4_shared_network where name = 'net1' and client_classes = '[ \"abc\" ]';"
+ run_statement "#1" "$qry" 1
+
+ qry="select count(name) from dhcp4_shared_network where name = 'net2' and client_classes IS NULL;"
+ run_statement "#2" "$qry" 1
+
+ qry="select count(name) from dhcp4_shared_network where name = 'net3' and client_classes IS NULL;"
+ run_statement "#3" "$qry" 1
+
+ # We don't bother verifying all null and '' handling again, only that the conversion function is
+ # called for remaining tables.
+
+ # Verify dhcp4_subnet.
+ qry="select count(subnet_id) from dhcp4_subnet where subnet_id = 1 and client_classes = '[ \"subber\" ]';"
+ run_statement "#4" "$qry" 1
+
+ # Verify dhcp4_pool.
+ qry="select count(subnet_id) from dhcp4_pool where subnet_id = 1 and client_classes = '[ \"poolio\" ]';"
+ run_statement "#5" "$qry" 1
+
+ # Verify dhcp6_shared_network.
+ qry="select count(name) from dhcp6_shared_network where name = 'net6' and client_classes = '[ \"xyz\" ]';"
+ run_statement "#6" "$qry" 1
+
+ # Verify dhcp6_subnet.
+ qry="select count(subnet_id) from dhcp6_subnet where subnet_id = 6 and client_classes = '[ \"subber6\" ]';"
+ run_statement "#7" "$qry" 1
+
+ # Verify dhcp6_pool.
+ qry="select count(subnet_id) from dhcp6_pool where subnet_id = 6 and client_classes = '[ \"poolio6\" ]';"
+ run_statement "#8" "$qry" 1
+
+ # Verify dhcp6_pd_pool.
+ qry="select count(subnet_id) from dhcp6_pd_pool where subnet_id = 6 and client_classes = '[ \"pd_poolio\" ]';"
+ run_statement "#9" "$qry" 1
+
+ mysql_wipe
+
+ test_finish 0
+}
+
# Run tests.
mysql_db_init_test
mysql_host_reservation_init_test
@@ -3643,3 +3768,4 @@ mysql_reservation_mode_global_parameters_test
mysql_reservation_mode_out_of_pool_parameters_test
mysql_migrate_opt_record_type
mysql_remove_control_socket_parameters_test
+mysql_migrate_client_class_test
diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql
index a212dc8cf9..8423b8e328 100644
--- a/src/share/database/scripts/mysql/dhcpdb_create.mysql
+++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql
@@ -6070,27 +6070,61 @@ UPDATE schema_version
-- This line starts the schema upgrade to version 27.0.
+SET @disable_audit = 1;
+
+DROP FUNCTION IF EXISTS textToJSONList;
+DELIMITER $$
+CREATE FUNCTION textToJSONList(orig TEXT)
+RETURNS TEXT
+DETERMINISTIC
+BEGIN
+ IF orig = '' THEN
+ RETURN NULL;
+ END IF;
+
+ RETURN CONCAT('[ "', orig, '" ]');
+END $$
+DELIMITER ;
+
ALTER TABLE dhcp4_shared_network
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_shared_network SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp4_subnet
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_subnet SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp4_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_pool SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_shared_network
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_shared_network SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_subnet
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_subnet SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_pool SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_pd_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_pd_pool SET client_classes = textToJSONList(client_classes);
+
+DROP FUNCTION textToJSONList;
+
+SET @disable_audit = 0;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '27', minor = '0';
diff --git a/src/share/database/scripts/mysql/upgrade_026_to_027.sh.in b/src/share/database/scripts/mysql/upgrade_026_to_027.sh.in
index 552eb179ae..0178a2a149 100644
--- a/src/share/database/scripts/mysql/upgrade_026_to_027.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_026_to_027.sh.in
@@ -56,27 +56,61 @@ mysql "$@" <<EOF
-- This line starts the schema upgrade to version 27.0.
+SET @disable_audit = 1;
+
+DROP FUNCTION IF EXISTS textToJSONList;
+DELIMITER $$
+CREATE FUNCTION textToJSONList(orig TEXT)
+RETURNS TEXT
+DETERMINISTIC
+BEGIN
+ IF orig = '' THEN
+ RETURN NULL;
+ END IF;
+
+ RETURN CONCAT('[ "', orig, '" ]');
+END $$
+DELIMITER ;
+
ALTER TABLE dhcp4_shared_network
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_shared_network SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp4_subnet
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_subnet SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp4_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp4_pool SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_shared_network
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_shared_network SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_subnet
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_subnet SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_pool SET client_classes = textToJSONList(client_classes);
+
ALTER TABLE dhcp6_pd_pool
CHANGE client_class client_classes LONGTEXT DEFAULT NULL;
+UPDATE dhcp6_pd_pool SET client_classes = textToJSONList(client_classes);
+
+DROP FUNCTION textToJSONList;
+
+SET @disable_audit = 0;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '27', minor = '0';