]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3961] Add force parameter to option def delete
authorThomas Markwalder <tmark@isc.org>
Wed, 3 Sep 2025 19:38:46 +0000 (15:38 -0400)
committerRazvan Becheriu <razvan@isc.org>
Tue, 9 Sep 2025 12:34:14 +0000 (15:34 +0300)
Initial implementation and updated existing UTs.
Need to add specific UTs and update ARM.

/src/hooks/dhcp/mysql/mysql_cb_dhcp4.*
/src/hooks/dhcp/pgsql/pgsql_cb_dhcp4.*
/src/lib/dhcpsrv/config_backend_dhcp4.h
/src/lib/dhcpsrv/config_backend_pool_dhcp4.*
    Add force parameter to deleteOption4Def

/src/hooks/dhcp/mysql/mysql_cb_dhcp6.*
/src/hooks/dhcp/pgsql/pgsql_cb_dhcp6.*
/src/lib/dhcpsrv/config_backend_dhcp6.h
/src/lib/dhcpsrv/config_backend_pool_dhcp6.*
    Add force parameter to deleteOption6Def

/src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc
/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.*
/src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.*
    Updated tests

19 files changed:
src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql/mysql_cb_dhcp4.h
src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc
src/hooks/dhcp/mysql/mysql_cb_dhcp6.h
src/hooks/dhcp/pgsql/pgsql_cb_dhcp4.cc
src/hooks/dhcp/pgsql/pgsql_cb_dhcp4.h
src/hooks/dhcp/pgsql/pgsql_cb_dhcp6.cc
src/hooks/dhcp/pgsql/pgsql_cb_dhcp6.h
src/lib/dhcpsrv/config_backend_dhcp4.h
src/lib/dhcpsrv/config_backend_dhcp6.h
src/lib/dhcpsrv/config_backend_pool_dhcp4.cc
src/lib/dhcpsrv/config_backend_pool_dhcp4.h
src/lib/dhcpsrv/config_backend_pool_dhcp6.cc
src/lib/dhcpsrv/config_backend_pool_dhcp6.h
src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h

index 4701444544761fda4d03c12b94517f67e98dbb2d..d9f5d2c56c0a39888e63e8b15d91c5d8b8f35c48 100644 (file)
@@ -2194,10 +2194,23 @@ public:
     /// @param server_selector Server selector.
     /// @param code Option code.
     /// @param name Option name.
+    /// @param force When true, delete is done without checking for
+    /// dependent options.
     /// @return Number of deleted option definitions.
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     uint64_t deleteOptionDef4(const ServerSelector& server_selector,
                               const uint16_t code,
-                              const std::string& space) {
+                              const std::string& space,
+                              bool force) {
+        if (!force) {
+            auto option = getOption(GET_OPTION4_CODE_SPACE, Option::V4,
+                                    server_selector, code, space);
+            if (option) {
+                isc_throw(InvalidOperation, "option exists for option defintion");
+            }
+        }
+
         MySqlBindingCollection in_bindings = {
             MySqlBinding::createInteger<uint16_t>(code),
             MySqlBinding::createString(space)
@@ -4231,10 +4244,11 @@ MySqlConfigBackendDHCPv4::deleteAllSharedNetworks4(const ServerSelector& server_
 uint64_t
 MySqlConfigBackendDHCPv4::deleteOptionDef4(const ServerSelector& server_selector,
                                            const uint16_t code,
-                                           const std::string& space) {
+                                           const std::string& space,
+                                           bool force /* = false */) {
     LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_DELETE_OPTION_DEF4)
         .arg(code).arg(space);
-    uint64_t result = impl_->deleteOptionDef4(server_selector, code, space);
+    uint64_t result = impl_->deleteOptionDef4(server_selector, code, space, force);
     LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_DELETE_OPTION_DEF4_RESULT)
         .arg(result);
     return (result);
index 7fa7858f352c0933b0e9240cd12822788772bba1..abbf8ea8a57ca7ee3356bd4e348a24426834548b 100644 (file)
@@ -450,11 +450,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     /// @throw NotImplemented if server selector is "unassigned".
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     virtual uint64_t
     deleteOptionDef4(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index 6efda22e901b419752108678dda9fd8a41459a8b..92f1e5b20fac961bbf6f559f4f7600a140e891d7 100644 (file)
@@ -2575,10 +2575,24 @@ public:
     /// @param server_selector Server selector.
     /// @param code Option code.
     /// @param name Option name.
+    /// @param force When true, delete is done without checking for
+    /// dependent options.
     /// @return Number of deleted option definitions.
+    /// @throw NotImplemented if server selector is "unassigned".
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     uint64_t deleteOptionDef6(const ServerSelector& server_selector,
                               const uint16_t code,
-                              const std::string& space) {
+                              const std::string& space,
+                              bool force) {
+        if (!force) {
+            auto option = getOption(GET_OPTION6_CODE_SPACE, Option::V6,
+                                    server_selector, code, space);
+            if (option) {
+                isc_throw(InvalidOperation, "option exists for option defintion");
+            }
+        }
+
         MySqlBindingCollection in_bindings = {
             MySqlBinding::createInteger<uint16_t>(code),
             MySqlBinding::createString(space)
@@ -4668,10 +4682,11 @@ MySqlConfigBackendDHCPv6::deleteAllSharedNetworks6(const ServerSelector& server_
 uint64_t
 MySqlConfigBackendDHCPv6::deleteOptionDef6(const ServerSelector& server_selector,
                                            const uint16_t code,
-                                           const std::string& space) {
+                                           const std::string& space,
+                                           bool force /* = false*/) {
     LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_DELETE_OPTION_DEF6)
         .arg(code).arg(space);
-    uint64_t result = impl_->deleteOptionDef6(server_selector, code, space);
+    uint64_t result = impl_->deleteOptionDef6(server_selector, code, space, force);
     LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_DELETE_OPTION_DEF6_RESULT)
         .arg(result);
     return (result);
index 5495b6dfb3e4266068aad228d6af305484a05ccb..dd1297bbe15f3dc68dda0f9b7ce99becad275878 100644 (file)
@@ -465,11 +465,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     /// @throw NotImplemented if server selector is "unassigned".
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     virtual uint64_t
     deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index 17d77f34e94beb8cec11c58b47e8871f3b00a48e..c1ee9aefb9a5cca01fb2f60517c7842b87881cc0 100644 (file)
@@ -2056,10 +2056,23 @@ public:
     /// @param server_selector Server selector.
     /// @param code Option code.
     /// @param name Option name.
+    /// @param force When true, delete is done without checking for
+    /// dependent options.
     /// @return Number of deleted option definitions.
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     uint64_t deleteOptionDef4(const ServerSelector& server_selector,
                               const uint16_t code,
-                              const std::string& space) {
+                              const std::string& space,
+                              bool force) {
+        if (!force) {
+            auto option = getOption(GET_OPTION4_CODE_SPACE, Option::V4,
+                                    server_selector, code, space);
+            if (option) {
+                isc_throw(InvalidOperation, "option exists for option defintion");
+            }
+        }
+
         PsqlBindArray in_bindings;
         in_bindings.add(code);
         in_bindings.add(space);
@@ -5178,10 +5191,11 @@ PgSqlConfigBackendDHCPv4::deleteAllSharedNetworks4(const ServerSelector& server_
 uint64_t
 PgSqlConfigBackendDHCPv4::deleteOptionDef4(const ServerSelector& server_selector,
                                            const uint16_t code,
-                                           const std::string& space) {
+                                           const std::string& space,
+                                           bool force /* = false */) {
     LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF4)
         .arg(code).arg(space);
-    uint64_t result = impl_->deleteOptionDef4(server_selector, code, space);
+    uint64_t result = impl_->deleteOptionDef4(server_selector, code, space, force);
     LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF4_RESULT)
         .arg(result);
     return (result);
index 517fcc65b844f29371cec860479947456f8a6b35..61cd332b751213de67fd5519cacd53e96a8b72f2 100644 (file)
@@ -450,11 +450,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     /// @throw NotImplemented if server selector is "unassigned".
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     virtual uint64_t
     deleteOptionDef4(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index c644dabad887f0ef201c64d6fdd045f698801967..a42ff32dd3a8d5437887606263692cd10b979859 100644 (file)
@@ -2360,10 +2360,23 @@ public:
     /// @param server_selector Server selector.
     /// @param code Option code.
     /// @param name Option name.
+    /// @param force When true, delete is done without checking for
+    /// dependent options.
     /// @return Number of deleted option definitions.
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     uint64_t deleteOptionDef6(const ServerSelector& server_selector,
                               const uint16_t code,
-                              const std::string& space) {
+                              const std::string& space,
+                              bool force) {
+        if (!force) {
+            auto option = getOption(GET_OPTION6_CODE_SPACE, Option::V6,
+                                    server_selector, code, space);
+            if (option) {
+                isc_throw(InvalidOperation, "option exists for option defintion");
+            }
+        }
+
         PsqlBindArray in_bindings;
         in_bindings.add(code);
         in_bindings.add(space);
@@ -5657,10 +5670,11 @@ PgSqlConfigBackendDHCPv6::deleteAllSharedNetworks6(const ServerSelector& server_
 uint64_t
 PgSqlConfigBackendDHCPv6::deleteOptionDef6(const ServerSelector& server_selector,
                                            const uint16_t code,
-                                           const std::string& space) {
+                                           const std::string& space,
+                                           bool force /* = false */) {
     LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF6)
         .arg(code).arg(space);
-    uint64_t result = impl_->deleteOptionDef6(server_selector, code, space);
+    uint64_t result = impl_->deleteOptionDef6(server_selector, code, space, force);
     LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF6_RESULT)
         .arg(result);
     return (result);
index 51a8c59322ea93fa8d90cdb744a5bbebc0e12525..29d3dde9c4dfa792b1492dcfec0fa410f0e5b567 100644 (file)
@@ -465,11 +465,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     /// @throw NotImplemented if server selector is "unassigned".
+    /// @throw InvalidOperation if force is false and there is an option
+    /// matching server, code, and space.
     virtual uint64_t
     deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index fe2520bf87bfb2ff97649a7e7abf902e88bac9d3..19f9b578bfc11ce9b78da20acc4e7b38ae674741 100644 (file)
@@ -550,10 +550,14 @@ public:
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
     /// @return Number of deleted option definitions.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
+    /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef4(const db::ServerSelector& server_selector,
                      const uint16_t code,
-                     const std::string& space) = 0;
+                     const std::string& space,
+                     bool force = false) = 0;
 
     /// @brief Deletes all option definitions.
     ///
index 9b0450c4e135420638fc7ee00d29134d62ce5741..9f9ab2f5dbd503902f9547c78e3971db26e85697 100644 (file)
@@ -567,11 +567,14 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef6(const db::ServerSelector& server_selector,
                      const uint16_t code,
-                     const std::string& space) = 0;
+                     const std::string& space,
+                     bool force = false) = 0;
 
     /// @brief Deletes all option definitions.
     ///
index a6c2cf397c182160f4fbca3c4d39b590576c50eb..e44c928f4ac5af77646dba5d5c42003bb039a51f 100644 (file)
@@ -415,10 +415,11 @@ uint64_t
 ConfigBackendPoolDHCPv4::deleteOptionDef4(const BackendSelector& backend_selector,
                                           const ServerSelector& server_selector,
                                           const uint16_t code,
-                                          const std::string& space) {
+                                          const std::string& space,
+                                          bool force /* = false */) {
     return (createUpdateDeleteProperty<uint64_t, uint16_t, const std::string&>
             (&ConfigBackendDHCPv4::deleteOptionDef4, backend_selector,
-             server_selector, code, space));
+             server_selector, code, space, force));
 }
 
 uint64_t
index 0523c3d09215a1e00b74edb8eb62eb50e034faae..03c124aec136fa21cc2e45135bbbb207c49243e1 100644 (file)
@@ -479,12 +479,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef4(const db::BackendSelector& backend_selector,
                      const db::ServerSelector& server_selector,
                      const uint16_t code,
-                     const std::string& space);
+                     const std::string& space,
+                     bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index f8bebd30185e6278a483c57de9e3e6cd76ec152f..f8f39009d6aa5ab79ce39a8aa9e64862094b43de 100644 (file)
@@ -427,10 +427,11 @@ uint64_t
 ConfigBackendPoolDHCPv6::deleteOptionDef6(const BackendSelector& backend_selector,
                                           const ServerSelector& server_selector,
                                           const uint16_t code,
-                                          const std::string& space) {
+                                          const std::string& space,
+                                          bool force /* = false */) {
     return (createUpdateDeleteProperty<uint64_t, uint16_t, const std::string&>
             (&ConfigBackendDHCPv6::deleteOptionDef6, backend_selector,
-             server_selector, code, space));
+             server_selector, code, space, force));
 }
 
 uint64_t
index 96ee9d06d2c13cd9393ec86164a98916560dc70d..0aee097be6399760ca5a4634eb04e685e46429d0 100644 (file)
@@ -494,12 +494,15 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef6(const db::BackendSelector& backend_selector,
                      const db::ServerSelector& server_selector,
                      const uint16_t code,
-                     const std::string& space);
+                     const std::string& space,
+                     bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index 3cdf63357778f90e284fc1ac891083f3a29387c3..7448adddae6320bc240a72b978e027af53793346 100644 (file)
@@ -474,11 +474,10 @@ public:
         auto option = mgr.getPool()->getOption4(BackendSelector::UNSPEC(),
                                                 ServerSelector::ALL(),
                                                 code, space);
-
         if (option) {
-            mgr.getPool()->deleteOptionDef4(BackendSelector::UNSPEC(), ServerSelector::ALL(),
-                                            code, space);
-            addDeleteAuditEntry("dhcp4_option_def", option->getId());
+            mgr.getPool()->deleteOption4(BackendSelector::UNSPEC(), ServerSelector::ALL(),
+                                         code, space);
+            addDeleteAuditEntry("dhcp4_option", option->getId());
         }
     }
 
@@ -718,19 +717,6 @@ public:
             }
         }
 
-        {
-            SCOPED_TRACE("option definitions");
-            // One of the option definitions should still be there.
-            EXPECT_TRUE(srv_cfg->getCfgOptionDef()->get("isc", "two"));
-            auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
-            if (deleteConfigElement("dhcp4_option_def", 1)) {
-                EXPECT_FALSE(found_def);
-
-            } else {
-                EXPECT_TRUE(found_def);
-            }
-        }
-
         {
             SCOPED_TRACE("global options");
             // One of the options should still be there.
@@ -746,6 +732,19 @@ public:
             }
         }
 
+        {
+            SCOPED_TRACE("option definitions");
+            // One of the option definitions should still be there.
+            EXPECT_TRUE(srv_cfg->getCfgOptionDef()->get("isc", "two"));
+            auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
+            if (deleteConfigElement("dhcp4_option_def", 1)) {
+                EXPECT_FALSE(found_def);
+
+            } else {
+                EXPECT_TRUE(found_def);
+            }
+        }
+
         {
             SCOPED_TRACE("shared networks");
             // One of the shared networks should still be there.
@@ -825,8 +824,8 @@ TEST_F(CBControlDHCPv4Test, databaseConfigApplyAll) {
 TEST_F(CBControlDHCPv4Test, databaseConfigApplyDeleteAll) {
     testDatabaseConfigApplyDelete(getTimestamp(-5), [this]() {
         remoteDeleteGlobalParameter("comment", 1);
-        remoteDeleteOptionDef(101, "isc");
         remoteDeleteOption(DHO_HOST_NAME, DHCP4_OPTION_SPACE);
+        remoteDeleteOptionDef(101, "isc");
         remoteDeleteSharedNetwork("one");
         remoteDeleteSubnet(SubnetID(1));
         remoteDeleteClientClass("first-class");
@@ -1395,9 +1394,9 @@ public:
                                                 code, space);
 
         if (option) {
-            mgr.getPool()->deleteOptionDef6(BackendSelector::UNSPEC(), ServerSelector::ALL(),
-                                            code, space);
-            addDeleteAuditEntry("dhcp6_option_def", option->getId());
+            mgr.getPool()->deleteOption6(BackendSelector::UNSPEC(), ServerSelector::ALL(),
+                                         code, space);
+            addDeleteAuditEntry("dhcp6_option", option->getId());
         }
     }
 
@@ -1630,19 +1629,6 @@ public:
             }
         }
 
-        {
-            SCOPED_TRACE("option definitions");
-            // One of the option definitions should still be there.
-            EXPECT_TRUE(srv_cfg->getCfgOptionDef()->get("isc", "two"));
-            auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
-            if (deleteConfigElement("dhcp6_option_def", 1)) {
-                EXPECT_FALSE(found_def);
-
-            } else {
-                EXPECT_TRUE(found_def);
-            }
-        }
-
         {
             SCOPED_TRACE("global options");
             // One of the options should still be there.
@@ -1658,6 +1644,19 @@ public:
             }
         }
 
+        {
+            SCOPED_TRACE("option definitions");
+            // One of the option definitions should still be there.
+            EXPECT_TRUE(srv_cfg->getCfgOptionDef()->get("isc", "two"));
+            auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
+            if (deleteConfigElement("dhcp6_option_def", 1)) {
+                EXPECT_FALSE(found_def);
+
+            } else {
+                EXPECT_TRUE(found_def);
+            }
+        }
+
         {
             SCOPED_TRACE("shared networks");
             // One of the shared networks should still be there.
index b3a87228e639e3193f1d7d7fb568c2d7fe4da62c..de9aee74fe06b3ecdce6746554c72304b8f1c5f5 100644 (file)
@@ -1150,7 +1150,16 @@ TestConfigBackendDHCPv4::deleteAllSharedNetworks4(const db::ServerSelector& serv
 uint64_t
 TestConfigBackendDHCPv4::deleteOptionDef4(const db::ServerSelector& server_selector,
                                           const uint16_t code,
-                                          const std::string& space) {
+                                          const std::string& space,
+                                          bool force /* = false */) {
+    if (!force) {
+        auto option = getOption4(server_selector, code, space);
+        if (option) {
+            isc_throw(InvalidOperation, "option exists for option definition " 
+                      << space << "." << code);
+        }
+    }
+
     auto tag = getServerTag(server_selector);
     uint64_t erased = 0;
     for (auto option_def_it = option_defs_.begin(); option_def_it != option_defs_.end(); ) {
index b75d151c85053da00c3e2550b7f9d9a3be5ecc74..76b508d295420bea61eb7782158d8f9e3e174703 100644 (file)
@@ -423,10 +423,12 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef4(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///
index 15d8edbd1de9cb3f94021359e31d760871e01781..314a9078bde9ad5478ebc5d5e2964660ba7fc833 100644 (file)
@@ -1205,7 +1205,15 @@ TestConfigBackendDHCPv6::deleteAllSharedNetworks6(const db::ServerSelector& serv
 uint64_t
 TestConfigBackendDHCPv6::deleteOptionDef6(const db::ServerSelector& server_selector,
                                           const uint16_t code,
-                                          const std::string& space) {
+                                          const std::string& space,
+                                          bool force /* = false */) {
+    if (!force) {
+        auto option = getOption6(server_selector, code, space);
+        if (option) {
+            isc_throw(InvalidOperation, "option exists for option definition");
+        }
+    }
+
     auto const& tag = getServerTag(server_selector);
     uint64_t erased = 0;
     for (auto option_def_it = option_defs_.begin(); option_def_it != option_defs_.end(); ) {
index f2ccbc32f415bb7441cc4e1306f7302bc8080d71..21f8274881d2776202bad7bdc709b79972c615f5 100644 (file)
@@ -436,10 +436,12 @@ public:
     /// @param server_selector Server selector.
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
+    /// @param force When true, delete is done without checking for
+    /// dependent options. Defaults to false.
     /// @return Number of deleted option definitions.
     virtual uint64_t
     deleteOptionDef6(const db::ServerSelector& server_selector, const uint16_t code,
-                     const std::string& space);
+                     const std::string& space, bool force = false);
 
     /// @brief Deletes all option definitions.
     ///