/// or option definitions having the same id (typically id of 0).
/// When configuration backend is in use it sets the unique ids
/// from the database. In cases when the configuration backend is
- /// not used, the ids default to 0.
-
+ /// not used, the ids default to 0. Passing the id of 0 would
+ /// result in deleting all options or option definitions that were
+ /// not added via the database.
+ ///
/// @param id Identifier of the items to be deleted.
///
/// @return Number of deleted options or option definitions.
range = index.equal_range(boost::make_tuple("dhcp4_subnet",
AuditEntry::ModificationType::DELETE));
for (auto entry = range.first; entry != range.second; ++entry) {
- cfg->getCfgSubnets4()->del((*entry)->getObjectId());
+ // If the deleted subnet belongs to a shared network and the
+ // shared network is not being removed, we need to detach the
+ // subnet from the shared network.
+ auto subnet = cfg->getCfgSubnets4()->getBySubnetId((*entry)->getObjectId());
+ if (subnet) {
+ // Check if the subnet belongs to a shared network.
+ SharedNetwork4Ptr network;
+ subnet->getSharedNetwork(network);
+ if (network) {
+ // Detach the subnet from the shared network.
+ network->del(subnet->getID());
+ }
+ // Actually delete the subnet from the configuration.
+ cfg->getCfgSubnets4()->del((*entry)->getObjectId());
+ }
}
} catch (...) {
/// having the same id (typically id of 0). When configuration backend
/// is in use it sets the unique ids from the database. In cases when
/// the configuration backend is not used, the ids default to 0.
+ /// Passing the id of 0 would result in deleting all options that were
+ /// not added via the database.
///
/// Both regular and vendor specific options are deleted with this
/// method.
/// definitions having the same id (typically id of 0). When
/// configuration backend is in use it sets the unique ids from the
/// database. In cases when the configuration backend is not used,
- /// the ids default to 0.
+ /// the ids default to 0. Passing the id of 0 would result in
+ /// deleting all option definitions that were not added via the
+ /// database.
///
/// @param id Identifier of the option definitions to be deleted.
///
/// networks having the same id (typically id of 0). When configuration
/// backend is in use it sets the unique ids from the database.
/// In cases when the configuration backend is not used, the ids
- /// default to 0.
+ /// default to 0. Passing the id of 0 would result in deleting all
+ /// shared networks that were not added via the database.
///
/// @param id Identifier of the shared networks to be deleted.
///
// Insert subnets into the database.
Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.3.0"), 26, 1, 2, 3, SubnetID(1)));
subnet->setModificationTime(getTimestamp("dhcp4_subnet"));
+ subnet->setSharedNetworkName("one");
mgr.getPool()->createUpdateSubnet4(BackendSelector::UNSPEC(), ServerSelector::ALL(),
subnet);
if (deleteConfigElement("dhcp4_subnet", 1)) {
EXPECT_FALSE(found_subnet);
+ // If the subnet has been deleted, make sure that
+ // it was detached from the shared network it belonged
+ // to, if the shared network still exists.
+ auto found_network = srv_cfg->getCfgSharedNetworks4()->getByName("one");
+ if (found_network) {
+ EXPECT_TRUE(found_network->getAllSubnets()->empty());
+ }
+
} else {
EXPECT_TRUE(found_subnet);
}
// This test verifies that only a subnet is merged into the current
// configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplySubnet) {
+ addCreateAuditEntry("dhcp4_shared_network");
addCreateAuditEntry("dhcp4_subnet");
testDatabaseConfigApply(getTimestamp(-5));
}
option_name << "option-" << code;
OptionDefinitionPtr def(new OptionDefinition(option_name.str(), code,
"uint16"));
+ // We're setting id of 123 for all option definitions in this
+ // code range.
def->setId(123);
// Add option definition to "isc" option space.
option_name << "option-" << code;
OptionDefinitionPtr def(new OptionDefinition(option_name.str(), code,
"uint16"));
-
+ // We're setting id of 234 for all option definitions in this
+ // code range.
def->setId(234);
ASSERT_NO_THROW(cfg.add(def, "abcde"));