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
/// @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)
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);
/// @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.
///
/// @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)
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);
/// @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.
///
/// @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);
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);
/// @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.
///
/// @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);
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);
/// @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.
///
/// @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.
///
/// @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.
///
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
/// @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.
///
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
/// @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.
///
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());
}
}
}
}
- {
- 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.
}
}
+ {
+ 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.
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");
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());
}
}
}
}
- {
- 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.
}
}
+ {
+ 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.
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(); ) {
/// @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.
///
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(); ) {
/// @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.
///