]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3770] Fix dhcp6_options.modfication_ts
authorThomas Markwalder <tmark@isc.org>
Thu, 17 Jul 2025 12:03:17 +0000 (08:03 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 17 Jul 2025 12:03:17 +0000 (08:03 -0400)
Fix dhcp6_options modification_ts column omitted in
original upgrade script and add checks of dhcp6_options changes

/src/bin/admin/tests/mysql_tests.sh.in
    mysql_upgrade_30_to_31_test()
    mysql_migrate_dhcpX_options_client_classes()
    - add dhcp6_options check

/src/bin/admin/tests/pgsql_tests.sh.in
    pgsql_upgrade_29_to_30_test()
    pgsql_migrate_dhcpX_options_client_classes()
    - add dhcp6_options check

/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
    Include conditional add of dhcp6_columns.modification_ts

src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in
    Add dhcp6_columns.modification_ts

/src/share/database/scripts/pgsql/upgrade_029_to_030.sh.in
    Include conditional add of dhcp6_columns.modification_ts

src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in
src/share/database/scripts/pgsql/upgrade_029_to_030.sh.in

index ad4f19deb50c29489f6f01ca2dc2c6de30c88ea6..da770a75b1c9ebbd0dc7e6fa46a0230cbb62a7b2 100755 (executable)
@@ -1158,7 +1158,7 @@ mysql_upgrade_29_to_30_test() {
 }
 
 mysql_upgrade_30_to_31_test() {
-    # Check dhcp4.client_classes now needs a value
+    # Check dhcp4_options.client_classes now needs a value
     qry="SET @disable_audit = 1;\
         INSERT INTO dhcp4_options (scope_id, code, space, formatted_value, modification_ts) \
         VALUES (0, '223', 'dhcp4', 'foo' , current_timestamp );";
@@ -1167,6 +1167,16 @@ mysql_upgrade_30_to_31_test() {
     run_command \
         mysql_execute "${qry}"
     assert_eq 1 "${EXIT_CODE}" "${qry}: expected %d, returned %d"
+
+    # Check dhcp6_options.client_classes now needs a value
+    qry="SET @disable_audit = 1;\
+        INSERT INTO dhcp6_options (scope_id, code, space, formatted_value, modification_ts) \
+        VALUES (0, '223', 'dhcp6', 'foo' , current_timestamp );";
+
+    # Should fail with "ERROR 1364 (HY000): Field 'client_classes' doesn't have a default value"
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 1 "${EXIT_CODE}" "${qry}: expected %d, returned %d"
 }
 
 mysql_upgrade_test() {
@@ -3982,8 +3992,8 @@ mysql_migrate_client_class_test() {
     test_finish 0
 }
 
-# Verifies migration of dhcp4_options.client_classes column to not null.
-mysql_migrate_dhcp4_options_client_classes() {
+# Verifies migration of dhcpX_options.client_classes column to not null.
+mysql_migrate_dhcpX_options_client_classes() {
     test_start "mysql.mysql_migrate_dhcp4_options_client_classes"
 
     # Let's wipe the whole database
@@ -4008,23 +4018,37 @@ mysql_migrate_dhcp4_options_client_classes() {
         values (0, 222, 'dhcp4', 'foo' , current_timestamp); \
     insert into dhcp4_options \
         (scope_id, code, space, formatted_value, client_classes, modification_ts) \
-        values (0, 223, 'dhcp4', 'bar' , '[ \"cc-one\" ]', current_timestamp);"
+        values (0, 223, 'dhcp4', 'bar' , '[ \"cc-one\" ]', current_timestamp);
+    insert into dhcp6_options \
+        (scope_id, code, space, formatted_value, modification_ts) \
+        values (0, 222, 'dhcp6', 'foo' , current_timestamp); \
+    insert into dhcp6_options \
+        (scope_id, code, space, formatted_value, client_classes, modification_ts) \
+        values (0, 223, 'dhcp6', 'bar' , '[ \"cc-one\" ]', current_timestamp);"
 
     run_statement "insert option" "$sql"
 
     # Verify the inserted record counts.
     qry="select count(*) from dhcp4_options;"
     run_statement "#get 4_option_count before update" "$qry" 2
+    qry="select count(*) from dhcp6_options;"
+    run_statement "#get 6_option_count before update" "$qry" 2
 
     # Upgrade to schema 31.0
     mysql_upgrade_schema_to_version 31.0
 
     # Verify the migrated records.
     qry="select code from dhcp4_options where client_classes = '[  ]';"
-    run_statement "#get 4_option_222 after update" "$qry" 222 
+    run_statement "#get 4_option_222 after update" "$qry" 222
 
     qry="select code from dhcp4_options where client_classes = '[ \"cc-one\" ]';"
-    run_statement "#get 4_option_223 after update" "$qry" 223 
+    run_statement "#get 4_option_223 after update" "$qry" 223
+
+    qry="select code from dhcp6_options where client_classes = '[  ]';"
+    run_statement "#get 6_option_222 after update" "$qry" 222
+
+    qry="select code from dhcp6_options where client_classes = '[ \"cc-one\" ]';"
+    run_statement "#get 6_option_223 after update" "$qry" 223
 
     # Let's wipe the whole database
     mysql_wipe
@@ -4067,4 +4091,4 @@ mysql_reservation_mode_out_of_pool_parameters_test
 mysql_migrate_opt_record_type
 mysql_remove_control_socket_parameters_test
 mysql_migrate_client_class_test
-mysql_migrate_dhcp4_options_client_classes
+mysql_migrate_dhcpX_options_client_classes
index 48eab6210f0f4700eb3d619fd0778b830f21f20a..e20b6ad02554d92ec945998bfd5c34d5276cfcbb 100755 (executable)
@@ -1130,7 +1130,7 @@ pgsql_upgrade_28_to_29_test() {
 }
 
 pgsql_upgrade_29_to_30_test() {
-    # Check dhcp4.client_classes now needs a value
+    # Check dhcp4_options.client_classes now needs a value
     qry="SELECT set_config('kea.disable_audit', 'true', false);\
         INSERT INTO dhcp4_options (scope_id, code, space, formatted_value, modification_ts) \
         VALUES (0, '223', 'dhcp4', 'foo' , current_timestamp );";
@@ -1140,6 +1140,17 @@ pgsql_upgrade_29_to_30_test() {
     run_command \
         pgsql_execute "${qry}"
     assert_eq 3 "${EXIT_CODE}" "${qry}: expected %d, returned %d"
+
+    # Check dhcp6_options.client_classes now needs a value
+    qry="SELECT set_config('kea.disable_audit', 'true', false);\
+        INSERT INTO dhcp6_options (scope_id, code, space, formatted_value, modification_ts) \
+        VALUES (0, '223', 'dhcp6', 'foo' , current_timestamp );";
+
+    # Should fail with "# ERROR:  null value in column "client_classes" of relation "dhcp6_options"
+    # violates not-null constraint"
+    run_command \
+        pgsql_execute "${qry}"
+    assert_eq 3 "${EXIT_CODE}" "${qry}: expected %d, returned %d"
 }
 
 pgsql_upgrade_test() {
@@ -3123,9 +3134,9 @@ pgsql_migrate_client_class_test() {
     test_finish 0
 }
 
-# Verifies migration of dhcp4_options.client_classes column to not null.
-pgsql_migrate_dhcp4_options_client_classes() {
-    test_start "pgsql.pgsql_migrate_dhcp4_options_client_classes"
+# Verifies migration of dhcpX_options.client_classes column to not null.
+pgsql_migrate_dhcpX_options_client_classes() {
+    test_start "pgsql.pgsql_migrate_dhcpX_options_client_classes"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -3148,6 +3159,10 @@ pgsql_migrate_dhcp4_options_client_classes() {
         values (0, '222', 'dhcp4', 'foo' , current_timestamp); \
     insert into dhcp4_options (scope_id, code, space, formatted_value, client_classes, modification_ts) \
         values (0, '223', 'dhcp4', 'bar' , '[ \"cc-one\" ]', current_timestamp); \
+    insert into dhcp6_options (scope_id, code, space, formatted_value, modification_ts) \
+        values (0, '222', 'dhcp6', 'foo' , current_timestamp); \
+    insert into dhcp6_options (scope_id, code, space, formatted_value, client_classes, modification_ts) \
+        values (0, '223', 'dhcp6', 'bar' , '[ \"cc-one\" ]', current_timestamp); \
     select set_config('kea.disable_audit', 'false', false);"
 
     run_statement "insert option" "$sql"
@@ -3156,15 +3171,24 @@ pgsql_migrate_dhcp4_options_client_classes() {
     qry="select count(*) from dhcp4_options;"
     run_statement "#get 4_option_count before update" "$qry" 2
 
+    qry="select count(*) from dhcp6_options;"
+    run_statement "#get 6_option_count before update" "$qry" 2
+
     # Upgrade to schema 30.0
     pgsql_upgrade_schema_to_version 30.0
 
     # Verify the migrated records.
     qry="select code from dhcp4_options where client_classes = '[  ]';"
-    run_statement "#get 4_option_foo after update" "$qry" 222 
+    run_statement "#get 4_option_foo after update" "$qry" 222
 
     qry="select code from dhcp4_options where client_classes = '[ \"cc-one\" ]';"
-    run_statement "#get 4_option_foo after update" "$qry" 223 
+    run_statement "#get 4_option_foo after update" "$qry" 223
+
+    qry="select code from dhcp6_options where client_classes = '[  ]';"
+    run_statement "#get 6_option_foo after update" "$qry" 222
+
+    qry="select code from dhcp6_options where client_classes = '[ \"cc-one\" ]';"
+    run_statement "#get 6_option_foo after update" "$qry" 223
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -3201,4 +3225,4 @@ pgsql_reservation_mode_out_of_pool_parameters_test
 pgsql_migrate_opt_record_type
 pgsql_remove_control_socket_parameters_test
 pgsql_migrate_client_class_test
-pgsql_migrate_dhcp4_options_client_classes
+pgsql_migrate_dhcpX_options_client_classes
index 11f471a1539d2e015b98848bc53a13b2b036247f..4fbbf1290a56eb59bc1f84d0e273b95559b22911 100644 (file)
@@ -6718,6 +6718,8 @@ UPDATE dhcp4_options SET client_classes = '[  ]' WHERE client_classes IS NULL;
 ALTER TABLE dhcp4_options ALTER COLUMN client_classes SET NOT NULL;
 UPDATE dhcp6_options SET client_classes = '[  ]' WHERE client_classes IS NULL;
 ALTER TABLE dhcp6_options ALTER COLUMN client_classes SET NOT NULL;
+ALTER TABLE dhcp6_options ADD COLUMN IF NOT EXISTS modification_ts TIMESTAMP
+    WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
 SELECT set_config('kea.disable_audit', 'false', false);
 
 -- Update the schema version number.
index ef6f77ce36edac092c95a7920d44ecbad6acfc04..bfc7b9354d3228a22cc641c4f7f76fc82dd80acd 100755 (executable)
@@ -307,6 +307,7 @@ ALTER TABLE dhcp6_options
   ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
   ADD COLUMN pool_id BIGINT DEFAULT NULL,
   ADD COLUMN pd_pool_id BIGINT DEFAULT NULL,
+  ADD COLUMN modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
   ADD CONSTRAINT fk_dhcp6_options_pd_pool FOREIGN KEY (pd_pool_id)
     REFERENCES dhcp6_pd_pool(id) ON DELETE CASCADE ON UPDATE CASCADE,
   ADD CONSTRAINT fk_dhcp6_options_pool FOREIGN KEY (pool_id)
index 106500779d38357826182bdd12c0f771a0a2e6b4..1a298f766a0db201eebe4c60ed6c2cb420a6b997 100755 (executable)
@@ -44,6 +44,8 @@ UPDATE dhcp4_options SET client_classes = '[  ]' WHERE client_classes IS NULL;
 ALTER TABLE dhcp4_options ALTER COLUMN client_classes SET NOT NULL;
 UPDATE dhcp6_options SET client_classes = '[  ]' WHERE client_classes IS NULL;
 ALTER TABLE dhcp6_options ALTER COLUMN client_classes SET NOT NULL;
+ALTER TABLE dhcp6_options ADD COLUMN IF NOT EXISTS modification_ts TIMESTAMP
+    WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
 SELECT set_config('kea.disable_audit', 'false', false);
 
 -- Update the schema version number.