]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2882] fix pgsql_unused_subnet_id_test
authorAndrei Pavel <andrei@isc.org>
Tue, 13 Aug 2024 10:36:16 +0000 (13:36 +0300)
committerAndrei Pavel <andrei@isc.org>
Tue, 20 Aug 2024 10:05:50 +0000 (13:05 +0300)
Adding `--set ON_ERROR_STOP=1` to `pgsql_upgrade` made `pgsql_unused_subnet_id` fail while attempting to upgrade a 4.0 schema with some data to the latest schema.
```
Processing src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh file...
Schema upgraded to 4.0
NOTICE:  index "key_dhcp4_ipv4_address_subnet_id" does not exist, skipping
ERROR:  insert or update on table "dhcp6_options" violates foreign key constraint "fk_dhcp6_options_subnet"
DETAIL:  Key (dhcp6_subnet_id)=(6) is not present in table "dhcp6_subnet".
```
The test is not trying to cover a negative scenario as far as I can tell.
It seems that in the end, the schema ended up being upgraded to the target version of the last script that worked without errors, in this case 7.0. It tried to advance to other upgrade scripts, but skipped them because of versions mismatch.
```
Processing src/share/database/scripts/pgsql/upgrade_007_to_008.sh file...
Processing src/share/database/scripts/pgsql/upgrade_008_to_009.sh file...
This script upgrades 8.0 to 9.0. Reported version is 7.0. Skipping upgrade.
[...]
Processing src/share/database/scripts/pgsql/upgrade_023_to_024.sh file...
This script upgrades 23.0 to 24.0. Reported version is 7.0. Skipping upgrade.
Schema version reported after upgrade: 7.0
```
Previously, the error was not reported by the testing framework because it was also ignored by kea-admin.
Now, it is consistent with the MySQL behavior in kea-admin and it no longer ignores upgrade errors.
You can see the same upgrade done to a prior version done in the equivalent test `mysql_unused_subnet_id_test`.

src/bin/admin/tests/pgsql_tests.sh.in

index aa7a179d0a6d8345b05b9d92bd2b3652b01c8656..11584e6c7344faef8181f918e5f4da828a161508 100644 (file)
@@ -1980,12 +1980,15 @@ pgsql_unused_subnet_id_test() {
 
     run_statement "insert options" "$qry"
 
-    # Let's upgrade it to the latest version.
-    run_command \
-        "${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+    # We have a 4.0 database with hosts and options. Let's upgrade it to 6.2.
+    # For versions higher than 6.2 some new constraints fail to be added
+    # with the not empty tables, for instance the 6.2 -> 7.0 upgrade script
+    # can raise a key constraing violation for fk_dhcp6_options_subnet.
+    pgsql_upgrade_schema_to_version 6.2
 
-    # Upgrade should succeed
-    assert_eq 0 "${EXIT_CODE}" "upgrade failed"
+    # Version should be new 6.2
+    version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
+    assert_str_eq "6.2" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Two hosts should have null v4 subnet ids
     qry="select count(host_id) from hosts where dhcp4_subnet_id is null"