]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3476] Add foreign key UTs
authorThomas Markwalder <tmark@isc.org>
Thu, 11 Jul 2024 18:14:23 +0000 (14:14 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 18 Jul 2024 15:17:41 +0000 (11:17 -0400)
/src/bin/admin/tests/mysql_tests.sh.in
    mysql_migrate_opt_record_type() - new test

/src/bin/admin/tests/pgsql_tests.sh.in
    pgsql_migrate_opt_record_type() - new test

/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
    TEST_F(MySqlConfigBackendDHCPv4Test, invalidOptionDefDataType4Test)
    TEST_F(MySqlConfigBackendDHCPv4Test, allOptionDefDataTypes4Test)

/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
    TEST_F(MySqlConfigBackendDHCPv6Test, invalidOptionDefDataType6Test)
    TEST_F(MySqlConfigBackendDHCPv6Test, allOptionDefDataTypes6Test)

/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_dhcp4_unittest.cc
    TEST_F(PgSqlConfigBackendDHCPv4Test, invalidOptionDefDataType4Test)
    TEST_F(PgSqlConfigBackendDHCPv4Test, allOptionDefDataTypes4Test)

/src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_dhcp6_unittest.cc
    TEST_F(PgSqlConfigBackendDHCPv6Test, invalidOptionDefDataType6Test)
    TEST_F(PgSqlConfigBackendDHCPv6Test, allOptionDefDataTypes4Test)

/src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.*
    GenericConfigBackendDHCPv4Test::invalidOptionDefDataType4Test()
    GenericConfigBackendDHCPv4Test::allOptionDefDataTypes4Test()

/src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.*
    GenericConfigBackendDHCPv6Test::invalidOptionDefDataType6Test()
    GenericConfigBackendDHCPv6Test::allOptionDefDataTypes6Test()

/src/share/database/scripts/mysql/dhcpdb_create.mysql
/src/share/database/scripts/mysql/upgrade_023_to_024.sh.in
/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
/src/share/database/scripts/pgsql/upgrade_023_to_024.sh.in
    Modify table updates to only consider record_types

/src/share/database/scripts/mysql/upgrade_022_to_023.sh.in
/src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in
    Check for 22.0 or 22.1

16 files changed:
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_dhcp4_unittest.cc
src/hooks/dhcp/pgsql_cb/tests/pgsql_cb_dhcp6_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp4_unittest.h
src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.cc
src/lib/dhcpsrv/testutils/generic_cb_dhcp6_unittest.h
src/share/database/scripts/mysql/dhcpdb_create.mysql
src/share/database/scripts/mysql/upgrade_022_to_023.sh.in
src/share/database/scripts/mysql/upgrade_023_to_024.sh.in
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in
src/share/database/scripts/pgsql/upgrade_023_to_024.sh.in

index 4c79c0afeab83f03f5e14204ec0757af361e92f1..a57879374936c04b9283be4a4465abc22dac8f90 100644 (file)
@@ -3315,6 +3315,77 @@ mysql_reservation_mode_out_of_pool_parameters_test() {
     test_finish 0
 }
 
+# Verifies that OPT_RECORD_TYPE values are updated
+mysql_migrate_opt_record_type() {
+    test_start "mysql.migrate_opt_record_type"
+
+    # Let's wipe the whole database
+    mysql_wipe
+
+    # We need to create an older database with lease data so we can
+    # verify the upgrade mechanisms which prepopulate the lease stat
+    # tables.
+    #
+    # Initialize database to schema 1.0.
+    mysql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
+    assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
+
+    # Now upgrade to schema 23.0
+    mysql_upgrade_schema_to_version 23.0
+
+    # Now insert option definitions.
+    sql=\
+"set @disable_audit = 1; \
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('222','foo','dhcp4',17,current_timestamp,NULL, false, false);\
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('223','bar','dhcp4',17,current_timestamp,'10, 7, 2, 14', false, false);\
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('224','bar2','dhcp4',18,current_timestamp,'10, 7, 2, 14', false, false);
+ insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('222','foo','dhcp6',17,current_timestamp,NULL, false, false);\
+ insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('223','bar','dhcp6',17,current_timestamp,'10, 7, 2, 14', false, false);\
+ 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"
+
+    # Verify the inserted record counts.
+    qry="select count(*) from dhcp4_option_def;"
+    run_statement "#get 4_option_def_count before update" "$qry" 3
+
+    qry="select count(*) from dhcp6_option_def;"
+    run_statement "#get 6_option_def_count before update" "$qry" 3
+
+    # Upgrade to schema 24.0
+    mysql_upgrade_schema_to_version 24.0
+
+    # Verify the migrated records.
+    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';"
+    run_statement "#get 4_option_def_bar after update" "$qry" 254 
+
+    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';"
+    run_statement "#get 6_option_def_foo after update" "$qry" 17
+
+    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';"
+    run_statement "#get 6_option_def_bar2 after update" "$qry" 254
+
+    # Let's wipe the whole database
+    mysql_wipe
+
+    test_finish 0
+}
+
 # Run tests.
 mysql_db_init_test
 mysql_host_reservation_init_test
@@ -3347,3 +3418,4 @@ mysql_reservation_mode_off_parameters_test
 mysql_reservation_mode_all_parameters_test
 mysql_reservation_mode_global_parameters_test
 mysql_reservation_mode_out_of_pool_parameters_test
+mysql_migrate_opt_record_type
index b05c0aba10a2fe7651c626f53b00ea81ed1a669e..d4f6cbfe9b18fe64cb86b4c7300a9d2e443484f0 100644 (file)
@@ -2576,6 +2576,77 @@ pgsql_reservation_mode_out_of_pool_parameters_test() {
     test_finish 0
 }
 
+# Verifies that OPT_RECORD_TYPE values are updated
+pgsql_migrate_opt_record_type() {
+    test_start "pgsql.migrate_opt_record_type"
+
+    # Let's wipe the whole database
+    pgsql_wipe
+
+    # We need to create an older database with lease data so we can
+    # verify the upgrade mechanisms which prepopulate the lease stat
+    # tables.
+    #
+    # Initialize database to schema 1.0.
+    pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
+    assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
+
+    # Now upgrade to schema 23.0
+    pgsql_upgrade_schema_to_version 23.0
+
+    # Now insert option definitions.
+    sql=\
+"select set_config('kea.disable_audit', 'true', false);\
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('222','foo','dhcp4',17,current_timestamp,NULL, false, false);\
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('223','bar','dhcp4',17,current_timestamp,'10, 7, 2, 14', false, false);\
+ insert into dhcp4_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('224','bar2','dhcp4',18,current_timestamp,'10, 7, 2, 14', false, false);
+ insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('222','foo','dhcp6',17,current_timestamp,NULL, false, false);\
+ insert into dhcp6_option_def (code,name,space,type,modification_ts,record_types, is_array, encapsulate)\
+    values ('223','bar','dhcp6',17,current_timestamp,'10, 7, 2, 14', false, false);\
+ 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"
+
+    # Verify the inserted record counts.
+    qry="select count(*) from dhcp4_option_def;"
+    run_statement "#get 4_option_def_count before update" "$qry" 3
+
+    qry="select count(*) from dhcp6_option_def;"
+    run_statement "#get 6_option_def_count before update" "$qry" 3
+
+    # Upgrade to schema 24.0
+    pgsql_upgrade_schema_to_version 24.0
+
+    # Verify the migrated records.
+    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';"
+    run_statement "#get 4_option_def_bar after update" "$qry" 254 
+
+    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';"
+    run_statement "#get 6_option_def_foo after update" "$qry" 17
+
+    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';"
+    run_statement "#get 6_option_def_bar2 after update" "$qry" 254
+
+    # Let's wipe the whole database
+    pgsql_wipe
+
+    test_finish 0
+}
+
 # Run tests.
 pgsql_db_init_test
 pgsql_db_version_test
@@ -2602,3 +2673,4 @@ pgsql_reservation_mode_off_parameters_test
 pgsql_reservation_mode_all_parameters_test
 pgsql_reservation_mode_global_parameters_test
 pgsql_reservation_mode_out_of_pool_parameters_test
+pgsql_migrate_opt_record_type
index eadb257ff55e90dee3f50161139052c6f7ce0367..72b873451ca7d052ed7dc600208f6afe8ad47c55 100644 (file)
@@ -319,6 +319,14 @@ TEST_F(MySqlConfigBackendDHCPv4Test, optionDefs4WithServerTagsTest) {
     optionDefs4WithServerTagsTest();
 }
 
+TEST_F(MySqlConfigBackendDHCPv4Test, invalidOptionDefDataType4Test) {
+    invalidOptionDefDataType4Test();
+}
+
+TEST_F(MySqlConfigBackendDHCPv4Test, allOptionDefDataTypes4Test) {
+    allOptionDefDataTypes4Test();
+}
+
 TEST_F(MySqlConfigBackendDHCPv4Test, getAllOptionDefs4Test) {
     getAllOptionDefs4Test();
 }
index adbe57611442bc8cdb3fdc3ab13bd703421d5191..d758b54e05152e3eeeffa29b5b51bf500522a76e 100644 (file)
@@ -319,6 +319,14 @@ TEST_F(MySqlConfigBackendDHCPv6Test, optionDefs6WithServerTagsTest) {
     optionDefs6WithServerTagsTest();
 }
 
+TEST_F(MySqlConfigBackendDHCPv6Test, invalidOptionDefDataType6Test) {
+    invalidOptionDefDataType6Test();
+}
+
+TEST_F(MySqlConfigBackendDHCPv6Test, allOptionDefDataTypes6Test) {
+    allOptionDefDataTypes6Test();
+}
+
 TEST_F(MySqlConfigBackendDHCPv6Test, getAllOptionDefs6Test) {
     getAllOptionDefs6Test();
 }
index f6faa1bbd1b43373c7b83d57ed5584edef18e227..7ecdf3bc6cac382fb3861c2e005a5ec46a1439c8 100644 (file)
@@ -145,6 +145,14 @@ TEST_F(PgSqlConfigBackendDHCPv4Test, globalParameters4WithServerTagsTest) {
     globalParameters4WithServerTagsTest();
 }
 
+TEST_F(PgSqlConfigBackendDHCPv4Test, invalidOptionDefDataType4Test) {
+    invalidOptionDefDataType4Test();
+}
+
+TEST_F(PgSqlConfigBackendDHCPv4Test, allOptionDefDataTypes4Test) {
+    allOptionDefDataTypes4Test();
+}
+
 TEST_F(PgSqlConfigBackendDHCPv4Test, getAllGlobalParameters4Test) {
     getAllGlobalParameters4Test();
 }
index 44e2e6671b9f945c485f4ec358506feb6ba50bd6..c1720587f1130639e857b16c09dece21b37c8ad2 100644 (file)
@@ -317,6 +317,14 @@ TEST_F(PgSqlConfigBackendDHCPv6Test, optionDefs6WithServerTagsTest) {
     optionDefs6WithServerTagsTest();
 }
 
+TEST_F(PgSqlConfigBackendDHCPv6Test, invalidOptionDefDataType6Test) {
+    invalidOptionDefDataType6Test();
+}
+
+TEST_F(PgSqlConfigBackendDHCPv6Test, allOptionDefDataTypes4Test) {
+    allOptionDefDataTypes6Test();
+}
+
 TEST_F(PgSqlConfigBackendDHCPv6Test, getAllOptionDefs6Test) {
     getAllOptionDefs6Test();
 }
index ca9a42366f9545f63fccaf8c7b5d38b8578a5fef..51569d798c85030045e5d0277e4b100ae1652a84 100644 (file)
@@ -18,6 +18,7 @@
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/client_class_def.h>
 #include <dhcpsrv/config_backend_dhcp4_mgr.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/testutils/generic_cb_dhcp4_unittest.h>
@@ -320,7 +321,7 @@ GenericConfigBackendDHCPv4Test::initTestOptionDefs() {
     test_option_defs_.push_back(option_def);
 
     option_def.reset(new OptionDefinition("foobar", 234, DHCP4_OPTION_SPACE,
-                                          "uint64", true));
+                                          "uint16", true));
     test_option_defs_.push_back(option_def);
 }
 
@@ -3063,6 +3064,116 @@ GenericConfigBackendDHCPv4Test::optionDefs4WithServerTagsTest() {
     }
 }
 
+void
+GenericConfigBackendDHCPv4Test::invalidOptionDefDataType4Test() {
+    OptionDefinitionPtr test_def;
+    ASSERT_NO_THROW_LOG(test_def.reset(new OptionDefinition("foobar", 234, DHCP4_OPTION_SPACE,
+                                                              "unknown", true)));
+    ASSERT_TRUE(test_def);
+    ASSERT_THROW(cbptr_->createUpdateOptionDef4(ServerSelector::ALL(), test_def), 
+                 DbOperationError);
+}
+
+void
+GenericConfigBackendDHCPv4Test::allOptionDefDataTypes4Test() {
+
+    OptionDefListParser parser(AF_INET);
+    std::string defs_str = R"([
+    {
+        "name": "my-empty", "code": 221, "type": "empty", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-binary", "code": 222, "type": "binary", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-boolean", "code": 223, "type": "boolean", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-int8", "code": 224, "type": "int8", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-int16", "code": 225, "type": "int16", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-int32", "code": 226, "type": "int32", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-uint8", "code": 227, "type": "uint8", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-uint16", "code": 228, "type": "uint16", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-uint32", "code": 229, "type": "uint32", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv4-address", "code": 230, "type": "ipv4-address", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv6-address", "code": 231, "type": "ipv6-address", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv6-prefix", "code": 232, "type": "ipv6-prefix", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-psid", "code": 233, "type": "psid", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-string", "code": 234, "type": "string", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-tuple", "code": 235, "type": "tuple", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-fqdn", "code": 236, "type": "fqdn", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-internal", "code": 237, "type": "internal", "array": false,
+        "record-types": "", "space": "dhcp4", "encapsulate": ""
+    },
+    {
+        "name": "my-record", "code": 238, "type": "record", "array": false,
+        "record-types": "uint8, uint8", "space": "dhcp4", "encapsulate": ""
+    }
+    ])";
+
+    ConstElementPtr defs_elem;
+    ASSERT_NO_THROW_LOG(defs_elem = Element::fromJSON(defs_str));
+
+    CfgOptionDefPtr storage(new CfgOptionDef());
+    ASSERT_NO_THROW_LOG(parser.parse(storage, defs_elem));
+
+    auto test_defs = storage->getAll("dhcp4");
+    ASSERT_EQ(test_defs->size(), 18); 
+
+    // Insert each option definition into the database.
+    for (auto const& test_def : *test_defs) {
+        ASSERT_NO_THROW_LOG(cbptr_->createUpdateOptionDef4(ServerSelector::ALL(), test_def));
+        auto found_def = cbptr_->getOptionDef4(ServerSelector::ALL(),
+                                               test_def->getCode(), "dhcp4");
+
+        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;
+    }
+}
+
 void
 GenericConfigBackendDHCPv4Test::getAllOptionDefs4Test() {
     // Insert test option definitions into the database. Note that the second
index a2fa5dcea323a78ee2b7d96e4b4f0e4c8325738b..4375cb426db05c9ad59fa9db0f8e2e14c90bd994 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2022-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -287,6 +287,14 @@ public:
     /// all servers.
     void optionDefs4WithServerTagsTest();
 
+    /// @brief This test verifies that the back end prevents storage
+    /// of definitions with invalid data types
+    void invalidOptionDefDataType4Test();
+
+    /// @brief This test verifies that it is possible to create options of each
+    /// valid data type.
+    void allOptionDefDataTypes4Test();
+
     /// @brief Test that all option definitions can be fetched.
     void getAllOptionDefs4Test();
 
index a778dcd56394e80507c079c0e7e79fe05332cb7d..cd18e8b1db8d3522e3340337fb5d03e8e582684f 100644 (file)
@@ -18,6 +18,7 @@
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/client_class_def.h>
 #include <dhcpsrv/config_backend_dhcp6_mgr.h>
+#include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/testutils/generic_cb_dhcp6_unittest.h>
@@ -355,7 +356,7 @@ GenericConfigBackendDHCPv6Test::initTestOptionDefs() {
     test_option_defs_.push_back(option_def);
 
     option_def.reset(new OptionDefinition("bar", 1234, DHCP6_OPTION_SPACE,
-                                          "uint64", true));
+                                          "uint16", true));
     test_option_defs_.push_back(option_def);
 }
 
@@ -3089,6 +3090,116 @@ GenericConfigBackendDHCPv6Test::optionDefs6WithServerTagsTest() {
     }
 }
 
+void
+GenericConfigBackendDHCPv6Test::invalidOptionDefDataType6Test() {
+    OptionDefinitionPtr test_def;
+    ASSERT_NO_THROW_LOG(test_def.reset(new OptionDefinition("foobar", 234, DHCP6_OPTION_SPACE,
+                                                              "unknown", true)));
+    ASSERT_TRUE(test_def);
+    ASSERT_THROW(cbptr_->createUpdateOptionDef6(ServerSelector::ALL(), test_def), 
+                 DbOperationError);
+}
+
+void
+GenericConfigBackendDHCPv6Test::allOptionDefDataTypes6Test() {
+
+    OptionDefListParser parser(AF_INET);
+    std::string defs_str = R"([
+    {
+        "name": "my-empty", "code": 221, "type": "empty", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-binary", "code": 222, "type": "binary", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-boolean", "code": 223, "type": "boolean", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-int8", "code": 224, "type": "int8", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-int16", "code": 225, "type": "int16", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-int32", "code": 226, "type": "int32", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-uint8", "code": 227, "type": "uint8", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-uint16", "code": 228, "type": "uint16", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-uint32", "code": 229, "type": "uint32", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv4-address", "code": 230, "type": "ipv4-address", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv6-address", "code": 231, "type": "ipv6-address", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-ipv6-prefix", "code": 232, "type": "ipv6-prefix", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-psid", "code": 233, "type": "psid", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-string", "code": 234, "type": "string", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-tuple", "code": 235, "type": "tuple", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-fqdn", "code": 236, "type": "fqdn", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-internal", "code": 237, "type": "internal", "array": false,
+        "record-types": "", "space": "dhcp6", "encapsulate": ""
+    },
+    {
+        "name": "my-record", "code": 238, "type": "record", "array": false,
+        "record-types": "uint8, uint8", "space": "dhcp6", "encapsulate": ""
+    }
+    ])";
+
+    ConstElementPtr defs_elem;
+    ASSERT_NO_THROW_LOG(defs_elem = Element::fromJSON(defs_str));
+
+    CfgOptionDefPtr storage(new CfgOptionDef());
+    ASSERT_NO_THROW_LOG(parser.parse(storage, defs_elem));
+
+    auto test_defs = storage->getAll("dhcp6");
+    ASSERT_EQ(test_defs->size(), 18); 
+
+    // Insert each option definition into the database.
+    for (auto const& test_def : *test_defs) {
+        ASSERT_NO_THROW_LOG(cbptr_->createUpdateOptionDef6(ServerSelector::ALL(), test_def));
+        auto found_def = cbptr_->getOptionDef6(ServerSelector::ALL(),
+                                               test_def->getCode(), "dhcp6");
+
+        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;
+    }
+}
+
 void
 GenericConfigBackendDHCPv6Test::getAllOptionDefs6Test() {
     // Insert test option definitions into the database. Note that the second
index 61e85647c1af13070b4bed19cf68db0b5e35214e..6e74b1f8f8d3a3b3910d1e28ab574001ae9594ba 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2022-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -287,6 +287,14 @@ public:
     /// all servers.
     void optionDefs6WithServerTagsTest();
 
+    /// @brief This test verifies that the back end prevents storage
+    /// of definitions with invalid data types
+    void invalidOptionDefDataType6Test();
+
+    /// @brief This test verifies that it is possible to create options of each
+    /// valid data type.
+    void allOptionDefDataTypes6Test();
+
     /// @brief Test that all option definitions can be fetched.
     void getAllOptionDefs6Test();
 
index b882c12fdc148574d590f65b67e426e08819dde8..2070e0cce930967c9cf988b7f1e5a272616b0cdc 100644 (file)
@@ -5946,8 +5946,9 @@ BEGIN
         -- If they're coming from pre-2.6.0 record type is 17, from
         -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
         -- started.
-        UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
-        UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+        SET @disable_audit = 1;
+        UPDATE dhcp4_option_def SET type = 254 WHERE record_types IS NOT NULL;
+        UPDATE dhcp6_option_def SET type = 254 WHERE record_types IS NOT NULL;
 
         -- Create the table that enumerates option definition data types.
         CREATE TABLE option_def_data_type (
index 3a4b7abed59e08b8b20337268788b32d116a47dd..ab2b80e118c9c3c2c62cc347d92c147dd384c4e5 100644 (file)
@@ -28,8 +28,8 @@ fi
 
 # Check version.
 version=$(mysql_version "${@}")
-if test "${version}" != "22.0"; then
-    printf 'This script upgrades 22.0 to 23.0. '
+if [ "$version" != "22.0" ] && [ "$version" != "22.1" ]; then
+    printf 'This script upgrades 22.0 or 22.1 to 23.0. '
     printf 'Reported version is %s. Skipping upgrade.\n' "${version}"
     exit 0
 fi
index f750a7d00156a741407398d4abd1e7e9baf86e41..37b34aa6edd6ee1eca63c975edabe1cb423243b5 100644 (file)
@@ -73,8 +73,9 @@ BEGIN
         -- If they're coming from pre-2.6.0 record type is 17, from
         -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
         -- started.
-        UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
-        UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+        SET @disable_audit = 1;
+        UPDATE dhcp4_option_def SET type = 254 WHERE record_types IS NOT NULL;
+        UPDATE dhcp6_option_def SET type = 254 WHERE record_types IS NOT NULL;
 
         -- Create the table that enumerates option definition data types.
         CREATE TABLE option_def_data_type (
index b70414e942a19af8813aa8a4e4188778c657a5da..a3c716eae24a7a4bd268ab3b814af8341d89508a 100644 (file)
@@ -6402,15 +6402,10 @@ BEGIN
         RETURN 'EXISTS';
     END IF;
 
-    -- First we migrate existing OPT_RECORD_TYPE values
-    -- If they're coming from pre-2.6.0 record type is 17, from
-    -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
-    -- started.
-
-    -- Can we attempt to discern between internal and rec by testing
-    -- record_types?
-    UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
-    UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+    -- First we migrate existing OPT_RECORD_TYPE values.
+    PERFORM set_config('kea.disable_audit', 'true', false);
+    UPDATE dhcp4_option_def SET type = 254 WHERE record_types IS NOT NULL;
+    UPDATE dhcp6_option_def SET type = 254 WHERE record_types IS NOT NULL;
 
     -- Create the table that enumerates option definition data types.
     CREATE TABLE option_def_data_type (
index 13d6d5a8f96adbe29ef7dded2219f2e407c3b01c..744a4494a54f84f9e95e7fc1364af248deb2fb2a 100644 (file)
@@ -28,8 +28,8 @@ fi
 
 VERSION=$(pgsql_version "$@")
 
-if [ "$VERSION" != "22.0" ]; then
-    printf 'This script upgrades 22.0 to 23.0. '
+if [ "$VERSION" != "22.0" ] && [ "$VERSION" != "22.1" ]; then
+    printf 'This script upgrades 22.0 or 22.1 to 23.0. '
     printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
     exit 0
 fi
index ecf920ee9fd576c8df0eea1d6116d71dd47bd66b..ce169aadc33f4cc0f074677164d9690c967b5b60 100644 (file)
@@ -52,15 +52,10 @@ BEGIN
         RETURN 'EXISTS';
     END IF;
 
-    -- First we migrate existing OPT_RECORD_TYPE values
-    -- If they're coming from pre-2.6.0 record type is 17, from
-    -- 2.6.0 or 2.7.0 it is 18. No viable to way to know where we
-    -- started.
-
-    -- Can we attempt to discern between internal and rec by testing
-    -- record_types?
-    UPDATE dhcp4_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
-    UPDATE dhcp6_option_def SET type = 254 WHERE type >= 17 AND record_types IS NOT NULL;
+    -- First we migrate existing OPT_RECORD_TYPE values.
+    PERFORM set_config('kea.disable_audit', 'true', false);
+    UPDATE dhcp4_option_def SET type = 254 WHERE record_types IS NOT NULL;
+    UPDATE dhcp6_option_def SET type = 254 WHERE record_types IS NOT NULL;
 
     -- Create the table that enumerates option definition data types.
     CREATE TABLE option_def_data_type (