]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3484] Clean up based on 3476 review
authorThomas Markwalder <tmark@isc.org>
Wed, 17 Jul 2024 18:21:14 +0000 (14:21 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 18 Jul 2024 17:52:00 +0000 (13:52 -0400)
/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

src/bin/admin/kea-admin.in
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/dhcp/option_data_types.h
src/lib/dhcp/tests/option_definition_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc
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

index 283e446c47db53cf3c1328c7f64bd8d3cc1c6d20..b1172ff8ca6f87334f41a27dd18b11fa0acd0037 100644 (file)
@@ -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}" \
index 514b5d17d9e67126781b088dd4b88f89ae5de268..627b17d603403a110921103a23183baaa4a86480 100644 (file)
@@ -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
index 662f85e40e7b82a1eda673c16fe44e3a074d0919..e877fbfec5232f2de3d9ae0e230b01e59f4497eb 100644 (file)
@@ -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
index 52e8a2e18d58d3c6681d1d9c7b577193995d588c..f224c22528466cc9fd74bb354ebdd0b283d3ce1d 100644 (file)
@@ -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.
index 5ca6175de76928b27b94e0b01bfc4c8a9b11ae47..6bdd691fefd3f0da5d2e5ec3dc3d0c438bb12861 100644 (file)
@@ -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));
 }
index 8409db06dfdd3daba6990f9dad234995e2f1fd1e..56e404a54a5ba0eb997e3e496c90e23853130eb6 100644 (file)
@@ -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;
     }
 }
index c894e87cdf99aa5328de126d424d2c61572e94fd..ea453ac525b15a542d870a4ad4aa605d11d9aa9d 100644 (file)
@@ -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;
     }
 }
index b2203f3a44af7ad375d9a6fc2a6aae948277339f..ce80460e169ce758ebc4379268fb6c633ebddc9c 100644 (file)
@@ -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';
index d69b17834eba263ea153b225ba62377982c7ebeb..ea43f3323c7a5c50fe58505b20032c324698937f 100644 (file)
@@ -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';
index b32d6706e33de23027dfe7ccd599f1175d2c21ea..8b469cfc9346a9d179439875f762f9e0229bba04 100644 (file)
@@ -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';
 
index f68323951beb4c0ee9c25021e323b62bef3b72d6..8a3725582b43a4990de39c817f680db6bb78f6b2 100644 (file)
@@ -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';