From: Thomas Markwalder Date: Wed, 17 Jul 2024 18:21:14 +0000 (-0400) Subject: [#3484] Clean up based on 3476 review X-Git-Tag: Kea-2.6.1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbc7b8114a0b4029b0599b040786d7e1eba653de;p=thirdparty%2Fkea.git [#3484] Clean up based on 3476 review /src/bin/admin/kea-admin.in fix sorting /src/bin/admin/tests/mysql_tests.sh.in /src/bin/admin/tests/pgsql_tests.sh.in cosmetics /src/lib/dhcp/option_data_types.h explicit types, add comments /src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc /src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc cleanup /src/share/database/scripts/mysql/dhcpdb_create.mysql /src/share/database/scripts/mysql/upgrade_022_to_022.1.sh.in /src/share/database/scripts/pgsql/dhcpdb_create.pgsql /src/share/database/scripts/pgsql/upgrade_022_to_022.1.sh.in reset session variable --- diff --git a/src/bin/admin/kea-admin.in b/src/bin/admin/kea-admin.in index 283e446c47..b1172ff8ca 100644 --- a/src/bin/admin/kea-admin.in +++ b/src/bin/admin/kea-admin.in @@ -371,7 +371,8 @@ mysql_upgrade() { printf "Verifying upgrade permissions for %s\n" "$db_user" mysql_can_create - for script in "${upgrade_scripts_dir}"/upgrade*.sh + upgrade_scripts=$(find "${upgrade_scripts_dir}" -type f -name 'upgrade_*.sh' | sort -V) + for script in ${upgrade_scripts} do echo "Processing $script file..." "${script}" --host="${db_host}" --user="${db_user}" \ @@ -418,7 +419,8 @@ pgsql_upgrade() { # thru an env export PGPASSWORD=$db_password - for script in "${upgrade_scripts_dir}"/upgrade*.sh + upgrade_scripts=$(find "${upgrade_scripts_dir}" -type f -name 'upgrade_*.sh' | sort -V) + for script in ${upgrade_scripts} do echo "Processing $script file..." "${script}" -U "${db_user}" -h "${db_host}" \ diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 514b5d17d9..627b17d603 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -814,7 +814,7 @@ mysql_upgrade_18_to_19_test() { } mysql_upgrade_22_0_to_22_1_test() { - query="SELECT count(id) from option_def_data_type" + query="SELECT count(id) FROM option_def_data_type" run_command \ mysql_execute "${query}" assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" @@ -3337,7 +3337,7 @@ mysql_migrate_opt_record_type() { insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\ values ('224','bar2','dhcp6',18,current_timestamp,'10, 7, 2, 14', false, false); " - run_statement "insert otion definitions" "$sql" + run_statement "insert option definitions" "$sql" # Verify the inserted record counts. qry="select count(*) from dhcp4_option_def;" @@ -3350,22 +3350,22 @@ mysql_migrate_opt_record_type() { mysql_upgrade_schema_to_version 22.1 # Verify the migrated records. - qry="select type from dhcp4_option_def where name = 'foo';" + qry="select type from dhcp4_option_def = 'foo';" run_statement "#get 4_option_def_foo after update" "$qry" 17 - qry="select type from dhcp4_option_def where name = 'bar';" + qry="select type from dhcp4_option_def = 'bar';" run_statement "#get 4_option_def_bar after update" "$qry" 254 - qry="select type from dhcp4_option_def where name = 'bar2';" + qry="select type from dhcp4_option_def = 'bar2';" run_statement "#get 4_option_def_bar2 after update" "$qry" 254 - qry="select type from dhcp6_option_def where name = 'foo';" + qry="select type from dhcp6_option_def = 'foo';" run_statement "#get 6_option_def_foo after update" "$qry" 17 - qry="select type from dhcp6_option_def where name = 'bar';" + qry="select type from dhcp6_option_def = 'bar';" run_statement "#get 6_option_def_bar after update" "$qry" 254 - qry="select type from dhcp6_option_def where name = 'bar2';" + qry="select type from dhcp6_option_def = 'bar2';" run_statement "#get 6_option_def_bar2 after update" "$qry" 254 # Let's wipe the whole database diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 662f85e40e..e877fbfec5 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -910,7 +910,7 @@ pgsql_upgrade_20_to_21_test() { } pgsql_upgrade_22_to_22_1_test() { - query="SELECT count(id) from option_def_data_type" + query="SELECT count(id) FROM option_def_data_type" run_command \ pgsql_execute "${query}" assert_eq 0 "${EXIT_CODE}" "${query}: expected %d, returned %d" @@ -2599,7 +2599,7 @@ pgsql_migrate_opt_record_type() { insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\ values ('224','bar2','dhcp6',18,current_timestamp,'10, 7, 2, 14', false, false); " - run_statement "insert otion definitions" "$sql" + run_statement "insert option definitions" "$sql" # Verify the inserted record counts. qry="select count(*) from dhcp4_option_def;" @@ -2612,22 +2612,22 @@ pgsql_migrate_opt_record_type() { pgsql_upgrade_schema_to_version 24.0 # Verify the migrated records. - qry="select type from dhcp4_option_def where name = 'foo';" + qry="select type from dhcp4_option_def where name = 'foo';" run_statement "#get 4_option_def_foo after update" "$qry" 17 - qry="select type from dhcp4_option_def where name = 'bar';" + qry="select type from dhcp4_option_def where name = 'bar';" run_statement "#get 4_option_def_bar after update" "$qry" 254 - qry="select type from dhcp4_option_def where name = 'bar2';" + qry="select type from dhcp4_option_def where name = 'bar2';" run_statement "#get 4_option_def_bar2 after update" "$qry" 254 - qry="select type from dhcp6_option_def where name = 'foo';" + qry="select type from dhcp6_option_def where name = 'foo';" run_statement "#get 6_option_def_foo after update" "$qry" 17 - qry="select type from dhcp6_option_def where name = 'bar';" + qry="select type from dhcp6_option_def where name = 'bar';" run_statement "#get 6_option_def_bar after update" "$qry" 254 - qry="select type from dhcp6_option_def where name = 'bar2';" + qry="select type from dhcp6_option_def where name = 'bar2';" run_statement "#get 6_option_def_bar2 after update" "$qry" 254 # Let's wipe the whole database diff --git a/src/lib/dhcp/option_data_types.h b/src/lib/dhcp/option_data_types.h index 52e8a2e18d..f224c22528 100644 --- a/src/lib/dhcp/option_data_types.h +++ b/src/lib/dhcp/option_data_types.h @@ -35,34 +35,35 @@ public: /// @brief Data types of DHCP option fields. /// -/// @warning The order of data types matters: OPT_UNKNOWN_TYPE -/// must always be the last position. Also, OPT_RECORD_TYPE -/// must be at last but one position. This is because some -/// functions perform sanity checks on data type values using -/// '>' operators, assuming that all values beyond the -/// OPT_RECORD_TYPE are invalid. -enum OptionDataType { - OPT_EMPTY_TYPE, - OPT_BINARY_TYPE, - OPT_BOOLEAN_TYPE, - OPT_INT8_TYPE, - OPT_INT16_TYPE, - OPT_INT32_TYPE, - OPT_UINT8_TYPE, - OPT_UINT16_TYPE, - OPT_UINT32_TYPE, - OPT_ANY_ADDRESS_TYPE, - OPT_IPV4_ADDRESS_TYPE, - OPT_IPV6_ADDRESS_TYPE, - OPT_IPV6_PREFIX_TYPE, - OPT_PSID_TYPE, - OPT_STRING_TYPE, - OPT_TUPLE_TYPE, - OPT_FQDN_TYPE, +/// @warning Do NOT alter existing values to add (or remove) new types. +/// These values are stored by config backend. Altering any existing +/// values will produce code that is incompatiable with pre-existing data. +/// Futhermore, the order of data types matters: OPT_UNKNOWN_TYPE +/// must always be and OPT_RECORD_TYPE must be at second to last. +/// This is because some functions perform sanity checks on data type +/// values using '>' operators, assuming that all values beyond the +enum OptionDataType : int { + OPT_EMPTY_TYPE = 0, + OPT_BINARY_TYPE = 1, + OPT_BOOLEAN_TYPE = 2, + OPT_INT8_TYPE = 3, + OPT_INT16_TYPE = 4, + OPT_INT32_TYPE = 5, + OPT_UINT8_TYPE = 6, + OPT_UINT16_TYPE = 7, + OPT_UINT32_TYPE = 8, + OPT_ANY_ADDRESS_TYPE = 9, + OPT_IPV4_ADDRESS_TYPE = 10, + OPT_IPV6_ADDRESS_TYPE = 11, + OPT_IPV6_PREFIX_TYPE = 12, + OPT_PSID_TYPE = 13, + OPT_STRING_TYPE = 14, + OPT_TUPLE_TYPE = 15, + OPT_FQDN_TYPE = 16, // Type to be used only internally. Allows convenient notation of the option config. - OPT_INTERNAL_TYPE, - OPT_RECORD_TYPE = 254, // Do not alter this value. - OPT_UNKNOWN_TYPE = 255 // Do not alter this value. + OPT_INTERNAL_TYPE = 17, + OPT_RECORD_TYPE = 254, + OPT_UNKNOWN_TYPE = 255 }; /// @brief Parameters being used to make up an option definition. diff --git a/src/lib/dhcp/tests/option_definition_unittest.cc b/src/lib/dhcp/tests/option_definition_unittest.cc index 5ca6175de7..6bdd691fef 100644 --- a/src/lib/dhcp/tests/option_definition_unittest.cc +++ b/src/lib/dhcp/tests/option_definition_unittest.cc @@ -2173,7 +2173,7 @@ TEST(OptionDataTypeUtil, typeToString) { EXPECT_EQ(OPT_STRING_TYPE, OptionDataTypeUtil::getDataType("string")); EXPECT_EQ(OPT_TUPLE_TYPE, OptionDataTypeUtil::getDataType("tuple")); EXPECT_EQ(OPT_FQDN_TYPE, OptionDataTypeUtil::getDataType("fqdn")); - // EXPECT_EQ(OPT_INTERNAL_TYPE, OptionDataTypeUtil::getDataType("internal")); + EXPECT_EQ(OPT_INTERNAL_TYPE, OptionDataTypeUtil::getDataType("internal")); EXPECT_EQ(OPT_RECORD_TYPE, OptionDataTypeUtil::getDataType("record")); EXPECT_EQ(OPT_UNKNOWN_TYPE, OptionDataTypeUtil::getDataType("bogus")); } @@ -2196,7 +2196,7 @@ TEST(OptionDataTypeUtil, stringToType) { EXPECT_EQ("string", OptionDataTypeUtil::getDataTypeName(OPT_STRING_TYPE)); EXPECT_EQ("tuple", OptionDataTypeUtil::getDataTypeName(OPT_TUPLE_TYPE)); EXPECT_EQ("fqdn", OptionDataTypeUtil::getDataTypeName(OPT_FQDN_TYPE)); - // EXPECT_EQ("internal", OptionDataTypeUtil::getDataTypeName(OPT_INTERNAL_TYPE)); + EXPECT_EQ("internal", OptionDataTypeUtil::getDataTypeName(OPT_INTERNAL_TYPE)); EXPECT_EQ("record", OptionDataTypeUtil::getDataTypeName(OPT_RECORD_TYPE)); EXPECT_EQ("unknown", OptionDataTypeUtil::getDataTypeName(OPT_UNKNOWN_TYPE)); } diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc index 8409db06df..56e404a54a 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc @@ -4625,7 +4625,7 @@ void GenericConfigBackendDHCPv4Test::invalidOptionDefDataType4Test() { OptionDefinitionPtr test_def; ASSERT_NO_THROW_LOG(test_def.reset(new OptionDefinition("foobar", 234, DHCP4_OPTION_SPACE, - "unknown", true))); + "unknown", true))); ASSERT_TRUE(test_def); ASSERT_THROW(cbptr_->createUpdateOptionDef4(ServerSelector::ALL(), test_def), DbOperationError); @@ -4727,6 +4727,5 @@ GenericConfigBackendDHCPv4Test::allOptionDefDataTypes4Test() { ASSERT_TRUE(found_def) << "no option found for " << test_def->getName(); ASSERT_EQ(*found_def, *test_def); - std::cout << "option ok for " << found_def->getName() << std::endl; } } diff --git a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc index c894e87cdf..ea453ac525 100644 --- a/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc @@ -4776,7 +4776,7 @@ void GenericConfigBackendDHCPv6Test::invalidOptionDefDataType6Test() { OptionDefinitionPtr test_def; ASSERT_NO_THROW_LOG(test_def.reset(new OptionDefinition("foobar", 234, DHCP6_OPTION_SPACE, - "unknown", true))); + "unknown", true))); ASSERT_TRUE(test_def); ASSERT_THROW(cbptr_->createUpdateOptionDef6(ServerSelector::ALL(), test_def), DbOperationError); @@ -4878,6 +4878,5 @@ GenericConfigBackendDHCPv6Test::allOptionDefDataTypes6Test() { ASSERT_TRUE(found_def) << "no option found for " << test_def->getName(); ASSERT_EQ(*found_def, *test_def); - std::cout << "option ok for " << found_def->getName() << std::endl; } } diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index b2203f3a44..ce80460e16 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -5948,6 +5948,7 @@ ALTER TABLE dhcp4_option_def ALTER TABLE dhcp6_option_def ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id); +SET @disable_audit = 1; -- Update the schema version number. UPDATE schema_version SET version = '22', minor = '1'; diff --git a/src/share/database/scripts/mysql/upgrade_022_to_022.1.sh.in b/src/share/database/scripts/mysql/upgrade_022_to_022.1.sh.in index d69b17834e..ea43f3323c 100644 --- a/src/share/database/scripts/mysql/upgrade_022_to_022.1.sh.in +++ b/src/share/database/scripts/mysql/upgrade_022_to_022.1.sh.in @@ -95,6 +95,7 @@ ALTER TABLE dhcp4_option_def ALTER TABLE dhcp6_option_def ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id); +SET @disable_audit = 0; -- Update the schema version number. UPDATE schema_version SET version = '22', minor = '1'; diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql index b32d6706e3..8b469cfc93 100644 --- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql +++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql @@ -6420,6 +6420,7 @@ ALTER TABLE dhcp4_option_def ALTER TABLE dhcp6_option_def ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id); +SELECT set_config('kea.disable_audit', 'false', false); UPDATE schema_version SET version = '22', minor = '1'; diff --git a/src/share/database/scripts/pgsql/upgrade_022_to_022.1.sh.in b/src/share/database/scripts/pgsql/upgrade_022_to_022.1.sh.in index f68323951b..8a3725582b 100644 --- a/src/share/database/scripts/pgsql/upgrade_022_to_022.1.sh.in +++ b/src/share/database/scripts/pgsql/upgrade_022_to_022.1.sh.in @@ -80,6 +80,7 @@ ALTER TABLE dhcp4_option_def ALTER TABLE dhcp6_option_def ADD CONSTRAINT fk_option_def_data_type6 FOREIGN KEY (type) REFERENCES option_def_data_type(id); +SELECT set_config('kea.disable_audit', 'false', false); UPDATE schema_version SET version = '22', minor = '1';