@@ -3609,6 +3609,131 @@ mysql_remove_control_socket_parameters_test() {
3609
3609
test_finish 0
3610
3610
}
3611
3611
3612
+ # Verifies that client_class to client_classes migrates
3613
+ # single text entries to JSON list correctly
3614
+ mysql_migrate_client_class_test () {
3615
+ test_start " mysql.migrate_client_class_test"
3616
+
3617
+ # Let's wipe the whole database
3618
+ mysql_wipe
3619
+
3620
+ # We need to create an older database with lease data so we can
3621
+ # verify the upgrade mechanisms which prepopulate the lease stat
3622
+ # tables.
3623
+ #
3624
+ # Initialize database to schema 1.0.
3625
+ mysql -u" ${db_user} " -p" ${db_password} " " ${db_name} " < " @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
3626
+
3627
+ # Now upgrade to schema 4.0, this has lease_state in it
3628
+ mysql_upgrade_schema_to_version 26.0
3629
+
3630
+ # Now we need insert some leases to "migrate" for both v4 and v6
3631
+ qry=\
3632
+ " set @disable_audit 1;\
3633
+ insert into dhcp4_shared_network (name, client_classes) values ('aaa', 'abc');\
3634
+ insert into dhcp4_shared_network (name, client_classes) values ('bbb', '');\
3635
+ insert into dhcp4_shared_network (name) values ('ccc');\
3636
+ set @disable_audit 0;\
3637
+ run_statement " insert v4 networks" " $qry "
3638
+
3639
+ # Let's upgrade it to the latest version.
3640
+ run_command \
3641
+ " ${kea_admin} " db-upgrade mysql -u " ${db_user} " -p " ${db_password} " -n " ${db_name} " -d " ${db_scripts_dir} "
3642
+
3643
+ qry=" select client_classes from dhcp4_shared_network where name = ' aaa' and client_classes = ' [ \"abc\" ]' ;
3644
+ run_statement " #4.1" " $qry " 1
3645
+
3646
+ mysql_wipe
3647
+
3648
+ test_finish 0
3649
+ }
3650
+
3651
+ # Verifies that client_class to client_classes migrates
3652
+ # single text entries to JSON list correctly
3653
+ mysql_migrate_client_class_test () {
3654
+ test_start " mysql.migrate_client_class_test"
3655
+
3656
+ # Let's wipe the whole database
3657
+ mysql_wipe
3658
+
3659
+ # We need to create an older database with lease data so we can
3660
+ # verify the upgrade mechanisms which prepopulate the lease stat
3661
+ # tables.
3662
+ #
3663
+ # Initialize database to schema 1.0.
3664
+ mysql -u" ${db_user} " -p" ${db_password} " " ${db_name} " < " @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
3665
+
3666
+ # Now upgrade to schema 4.0, this has lease_state in it
3667
+ mysql_upgrade_schema_to_version 26.0
3668
+
3669
+ # Now we need insert some leases to "migrate" for both v4 and v6
3670
+ qry=" \
3671
+ set @disable_audit = 1;\
3672
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net1', 'abc', current_timestamp);\
3673
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net2', '', current_timestamp);\
3674
+ insert into dhcp4_shared_network (name, modification_ts) values ('net3', current_timestamp);\
3675
+ insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
3676
+ values (1, '192.0.0.0/24', current_timestamp, 'subber');\
3677
+ insert into dhcp4_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
3678
+ values (1, INET_ATON('192.0.0.0'), INET_ATON('192.0.0.1'), current_timestamp, 'poolio');\
3679
+ insert into dhcp6_shared_network (name, client_class, modification_ts) values ('net6', 'xyz', current_timestamp);\
3680
+ insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
3681
+ values (6, '2001:db8:1::/64', current_timestamp, 'subber6');\
3682
+ insert into dhcp6_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
3683
+ values (6, ('2001:db8:1::1'), ('2001:db8:1::2'), current_timestamp, 'poolio6');\
3684
+ insert into dhcp6_pd_pool (subnet_id, prefix, prefix_length, delegated_prefix_length, \
3685
+ excluded_prefix_length, modification_ts, client_class) \
3686
+ values (6, ('3001::'), 64, 72, 0, current_timestamp, 'pd_poolio');\
3687
+ set @disable_audit = 0;\
3688
+ "
3689
+ run_statement " insert v4 networks" " $qry "
3690
+
3691
+ # Let's upgrade it to the latest version.
3692
+ run_command \
3693
+ " ${kea_admin} " db-upgrade mysql -u " ${db_user} " -p " ${db_password} " -n " ${db_name} " -d " ${db_scripts_dir} "
3694
+
3695
+ # Verify dhcp4_shared_network values
3696
+ qry=" select count(name) from dhcp4_shared_network where name = 'net1' and client_classes = '[ \" abc\" ]';"
3697
+ run_statement " #1" " $qry " 1
3698
+
3699
+ qry=" select count(name) from dhcp4_shared_network where name = 'net2' and client_classes IS NULL;"
3700
+ run_statement " #2" " $qry " 1
3701
+
3702
+ qry=" select count(name) from dhcp4_shared_network where name = 'net3' and client_classes IS NULL;"
3703
+ run_statement " #3" " $qry " 1
3704
+
3705
+ # We don't bother verifying all null and '' handling again, only that the conversion function is
3706
+ # called for remaining tables.
3707
+
3708
+ # Verify dhcp4_subnet.
3709
+ qry=" select count(subnet_id) from dhcp4_subnet where subnet_id = 1 and client_classes = '[ \" subber\" ]';"
3710
+ run_statement " #4" " $qry " 1
3711
+
3712
+ # Verify dhcp4_pool.
3713
+ qry=" select count(subnet_id) from dhcp4_pool where subnet_id = 1 and client_classes = '[ \" poolio\" ]';"
3714
+ run_statement " #5" " $qry " 1
3715
+
3716
+ # Verify dhcp6_shared_network.
3717
+ qry=" select count(name) from dhcp6_shared_network where name = 'net6' and client_classes = '[ \" xyz\" ]';"
3718
+ run_statement " #6" " $qry " 1
3719
+
3720
+ # Verify dhcp6_subnet.
3721
+ qry=" select count(subnet_id) from dhcp6_subnet where subnet_id = 6 and client_classes = '[ \" subber6\" ]';"
3722
+ run_statement " #7" " $qry " 1
3723
+
3724
+ # Verify dhcp6_pool.
3725
+ qry=" select count(subnet_id) from dhcp6_pool where subnet_id = 6 and client_classes = '[ \" poolio6\" ]';"
3726
+ run_statement " #8" " $qry " 1
3727
+
3728
+ # Verify dhcp6_pd_pool.
3729
+ qry=" select count(subnet_id) from dhcp6_pd_pool where subnet_id = 6 and client_classes = '[ \" pd_poolio\" ]';"
3730
+ run_statement " #9" " $qry " 1
3731
+
3732
+ mysql_wipe
3733
+
3734
+ test_finish 0
3735
+ }
3736
+
3612
3737
# Run tests.
3613
3738
mysql_db_init_test
3614
3739
mysql_host_reservation_init_test
@@ -3643,3 +3768,4 @@ mysql_reservation_mode_global_parameters_test
3643
3768
mysql_reservation_mode_out_of_pool_parameters_test
3644
3769
mysql_migrate_opt_record_type
3645
3770
mysql_remove_control_socket_parameters_test
3771
+ mysql_migrate_client_class_test
0 commit comments