@@ -2872,6 +2872,94 @@ pgsql_remove_control_socket_parameters_test() {
2872
2872
test_finish 0
2873
2873
}
2874
2874
2875
+ # Verifies that client_class to client_classes migrates
2876
+ # single text entries to JSON list correctly
2877
+ pgsql_migrate_client_class_test () {
2878
+
2879
+ test_start " pgsql.pgsql_migrate_client_class_test"
2880
+
2881
+ # Let's wipe the whole database
2882
+ pgsql_wipe
2883
+
2884
+ # We need to create an older database with lease data so we can
2885
+ # verify the upgrade mechanisms which prepopulate the lease stat
2886
+ # tables.
2887
+ #
2888
+ # Initialize database to schema 1.0.
2889
+ pgsql_execute_script " @abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
2890
+ assert_eq 0 " ${EXIT_CODE} " " cannot initialize 1.0 database, expected exit code: %d, actual: %d"
2891
+
2892
+ # Now upgrade to schema 26.0
2893
+ pgsql_upgrade_schema_to_version 26.0
2894
+
2895
+ # Now we need insert some leases to "migrate" for both v4 and v6
2896
+ qry=" \
2897
+ select set_config('kea.disable_audit', 'true', false);\
2898
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net1', 'abc', current_timestamp);\
2899
+ insert into dhcp4_shared_network (name, client_class, modification_ts) values ('net2', '', current_timestamp);\
2900
+ insert into dhcp4_shared_network (name, modification_ts) values ('net3', current_timestamp);\
2901
+ insert into dhcp4_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
2902
+ values (1, '192.0.0.0/24', current_timestamp, 'subber');\
2903
+ insert into dhcp4_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
2904
+ values (1, '192.0.0.0', '192.0.0.1', current_timestamp, 'poolio');\
2905
+ insert into dhcp6_shared_network (name, client_class, modification_ts) values ('net6', 'xyz', current_timestamp);\
2906
+ insert into dhcp6_subnet (subnet_id, subnet_prefix, modification_ts, client_class)\
2907
+ values (6, '2001:db8:1::/64', current_timestamp, 'subber6');\
2908
+ insert into dhcp6_pool (subnet_id, start_address, end_address, modification_ts, client_class)\
2909
+ values (6, '2001:db8:1::1', '2001:db8:1::2', current_timestamp, 'poolio6');\
2910
+ insert into dhcp6_pd_pool (subnet_id, prefix, prefix_length, delegated_prefix_length, \
2911
+ excluded_prefix_length, modification_ts, client_class) \
2912
+ values (6, ('3001::'), 64, 72, 0, current_timestamp, 'pd_poolio');\
2913
+ select set_config('kea.disable_audit', 'false', false);\
2914
+ "
2915
+ run_statement " insert test data" " $qry "
2916
+
2917
+ # Let's upgrade it to the latest version.
2918
+ pgsql_upgrade_schema_to_version 27.0
2919
+
2920
+ # Verify dhcp4_shared_network values
2921
+ qry=" select count(name) from dhcp4_shared_network where name = 'net1' and client_classes = '[ \" abc\" ]';"
2922
+ run_statement " #1" " $qry " 1
2923
+
2924
+ qry=" select count(name) from dhcp4_shared_network where name = 'net2' and client_classes IS NULL;"
2925
+ run_statement " #2" " $qry " 1
2926
+
2927
+ qry=" select count(name) from dhcp4_shared_network where name = 'net3' and client_classes IS NULL;"
2928
+ run_statement " #3" " $qry " 1
2929
+
2930
+ # We don't bother verifying all null and '' handling again, only that the conversion function is
2931
+ # called for remaining tables.
2932
+
2933
+ # Verify dhcp4_subnet.
2934
+ qry=" select count(subnet_id) from dhcp4_subnet where subnet_id = 1 and client_classes = '[ \" subber\" ]';"
2935
+ run_statement " #4" " $qry " 1
2936
+
2937
+ # Verify dhcp4_pool.
2938
+ qry=" select count(subnet_id) from dhcp4_pool where subnet_id = 1 and client_classes = '[ \" poolio\" ]';"
2939
+ run_statement " #5" " $qry " 1
2940
+
2941
+ # Verify dhcp6_shared_network.
2942
+ qry=" select count(name) from dhcp6_shared_network where name = 'net6' and client_classes = '[ \" xyz\" ]';"
2943
+ run_statement " #6" " $qry " 1
2944
+
2945
+ # Verify dhcp6_subnet.
2946
+ qry=" select count(subnet_id) from dhcp6_subnet where subnet_id = 6 and client_classes = '[ \" subber6\" ]';"
2947
+ run_statement " #7" " $qry " 1
2948
+
2949
+ # Verify dhcp6_pool.
2950
+ qry=" select count(subnet_id) from dhcp6_pool where subnet_id = 6 and client_classes = '[ \" poolio6\" ]';"
2951
+ run_statement " #8" " $qry " 1
2952
+
2953
+ # Verify dhcp6_pd_pool.
2954
+ qry=" select count(subnet_id) from dhcp6_pd_pool where subnet_id = 6 and client_classes = '[ \" pd_poolio\" ]';"
2955
+ run_statement " #9" " $qry " 1
2956
+
2957
+ pgsql_wipe
2958
+
2959
+ test_finish 0
2960
+ }
2961
+
2962
+
2875
2963
# Run tests.
2876
2964
pgsql_db_init_test
2877
2965
pgsql_db_version_test
@@ -2900,3 +2988,4 @@ pgsql_reservation_mode_global_parameters_test
2900
2988
pgsql_reservation_mode_out_of_pool_parameters_test
2901
2989
pgsql_migrate_opt_record_type
2902
2990
pgsql_remove_control_socket_parameters_test
2991
+ pgsql_migrate_client_class_test
0 commit comments