2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-02 23:15:20 +00:00

[#1928] Test DHCPv4 CB supports follow_class_name

This commit is contained in:
Marcin Siodelski
2021-07-12 20:34:30 +02:00
parent 4355febb75
commit 11aec081e5
2 changed files with 69 additions and 22 deletions

View File

@@ -512,7 +512,13 @@ TestConfigBackendDHCPv4::getModifiedGlobalParameters4(const db::ServerSelector&
ClientClassDefPtr ClientClassDefPtr
TestConfigBackendDHCPv4::getClientClass4(const db::ServerSelector& server_selector, TestConfigBackendDHCPv4::getClientClass4(const db::ServerSelector& server_selector,
const std::string& name) const { const std::string& name) const {
auto client_class = classes_.findClass(name); ClientClassDefPtr client_class;
for (auto c : classes_) {
if (c->getName() == name) {
client_class = c;
break;
}
}
if (!client_class || server_selector.amAny()) { if (!client_class || server_selector.amAny()) {
return (client_class); return (client_class);
} }
@@ -532,7 +538,7 @@ ClientClassDictionary
TestConfigBackendDHCPv4::getAllClientClasses4(const db::ServerSelector& server_selector) const { TestConfigBackendDHCPv4::getAllClientClasses4(const db::ServerSelector& server_selector) const {
auto tags = server_selector.getTags(); auto tags = server_selector.getTags();
ClientClassDictionary all_classes; ClientClassDictionary all_classes;
for (auto client_class : *classes_.getClasses()) { for (auto client_class : classes_) {
auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class); auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class);
if (server_selector.amAny()) { if (server_selector.amAny()) {
all_classes.addClass(non_const_client_class); all_classes.addClass(non_const_client_class);
@@ -567,7 +573,7 @@ TestConfigBackendDHCPv4::getModifiedClientClasses4(const db::ServerSelector& ser
const boost::posix_time::ptime& modification_time) const { const boost::posix_time::ptime& modification_time) const {
auto tags = server_selector.getTags(); auto tags = server_selector.getTags();
ClientClassDictionary modified_classes; ClientClassDictionary modified_classes;
for (auto client_class : *classes_.getClasses()) { for (auto client_class : classes_) {
if (client_class->getModificationTime() >= modification_time) { if (client_class->getModificationTime() >= modification_time) {
auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class); auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class);
bool got = false; bool got = false;
@@ -592,15 +598,47 @@ TestConfigBackendDHCPv4::getModifiedClientClasses4(const db::ServerSelector& ser
void void
TestConfigBackendDHCPv4::createUpdateClientClass4(const db::ServerSelector& server_selector, TestConfigBackendDHCPv4::createUpdateClientClass4(const db::ServerSelector& server_selector,
const ClientClassDefPtr& client_class, const ClientClassDefPtr& client_class,
const std::string&) { const std::string& follow_class_name) {
int follow_class_index = -1;
if (!follow_class_name.empty()) {
for (auto i = 0; i < classes_.size(); ++i) {
if (classes_[i]->getName() == follow_class_name) {
follow_class_index = i;
break;
}
}
if (follow_class_index < 0) {
isc_throw(BadValue, "class " << follow_class_name << " does not exist");
}
}
mergeServerTags(client_class, server_selector); mergeServerTags(client_class, server_selector);
auto existing_class = classes_.findClass(client_class->getName()); int existing_class_index = -1;
if (existing_class) { for (auto i = 0; i < classes_.size(); ++i) {
classes_.removeClass(client_class->getName()); if (classes_[i]->getName() == client_class->getName()) {
existing_class_index = i;
break;
}
} }
auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class); auto non_const_client_class = boost::const_pointer_cast<ClientClassDef>(client_class);
classes_.addClass(non_const_client_class);
if (follow_class_index < 0) {
if (existing_class_index >= 0) {
classes_[existing_class_index] = non_const_client_class;
} else {
classes_.push_back(non_const_client_class);
}
} else {
if (existing_class_index < 0) {
classes_.insert(classes_.begin() + follow_class_index + 1, client_class);
} else {
classes_.erase(classes_.begin() + existing_class_index);
classes_.insert(classes_.begin() + follow_class_index + 1, client_class);
}
}
} }
AuditEntryCollection AuditEntryCollection
@@ -1322,7 +1360,14 @@ TestConfigBackendDHCPv4::deleteAllGlobalParameters4(const db::ServerSelector& se
uint64_t uint64_t
TestConfigBackendDHCPv4::deleteClientClass4(const db::ServerSelector& server_selector, TestConfigBackendDHCPv4::deleteClientClass4(const db::ServerSelector& server_selector,
const std::string& name) { const std::string& name) {
auto existing_class = classes_.findClass(name); ClientClassDefPtr existing_class;
auto c = classes_.begin();
for (; c != classes_.end(); ++c) {
if ((*c)->getName() == name) {
existing_class = (*c);
break;
}
}
if (!existing_class) { if (!existing_class) {
return (0); return (0);
} }
@@ -1343,21 +1388,24 @@ TestConfigBackendDHCPv4::deleteClientClass4(const db::ServerSelector& server_sel
return (0); return (0);
} }
} }
classes_.removeClass(name); classes_.erase(c);
return (1); return (1);
} }
uint64_t uint64_t
TestConfigBackendDHCPv4::deleteAllClientClasses4(const db::ServerSelector& server_selector) { TestConfigBackendDHCPv4::deleteAllClientClasses4(const db::ServerSelector& server_selector) {
std::list<std::string> class_names; uint64_t count = 0;
for (auto client_class : (*classes_.getClasses())) { for (auto c = classes_.begin(); c != classes_.end(); ++c) {
auto client_class = *c;
if (server_selector.amAny()) { if (server_selector.amAny()) {
class_names.push_back(client_class->getName()); c = classes_.erase(c);
++count;
continue; continue;
} }
if (server_selector.amUnassigned()) { if (server_selector.amUnassigned()) {
if (client_class->getServerTags().empty()) { if (client_class->getServerTags().empty()) {
class_names.push_back(client_class->getName()); c = classes_.erase(c);
++count;
} }
continue; continue;
} }
@@ -1365,7 +1413,8 @@ TestConfigBackendDHCPv4::deleteAllClientClasses4(const db::ServerSelector& serve
auto tags = server_selector.getTags(); auto tags = server_selector.getTags();
for (auto tag : tags) { for (auto tag : tags) {
if (client_class->hasServerTag(ServerTag(tag))) { if (client_class->hasServerTag(ServerTag(tag))) {
class_names.push_back(client_class->getName()); c = classes_.erase(c);
++count;
got = true; got = true;
break; break;
} }
@@ -1374,15 +1423,12 @@ TestConfigBackendDHCPv4::deleteAllClientClasses4(const db::ServerSelector& serve
continue; continue;
} }
if (client_class->hasAllServerTag()) { if (client_class->hasAllServerTag()) {
class_names.push_back(client_class->getName()); c = classes_.erase(c);
++count;
} }
} }
// Erase client classes. return (count);
for (auto name : class_names) {
classes_.removeClass(name);
}
return (class_names.size());
} }
uint64_t uint64_t

View File

@@ -20,6 +20,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
@@ -534,7 +535,7 @@ public:
OptionDefContainer option_defs_; OptionDefContainer option_defs_;
OptionContainer options_; OptionContainer options_;
data::StampedValueCollection globals_; data::StampedValueCollection globals_;
ClientClassDictionary classes_; std::vector<ClientClassDefPtr> classes_;
db::ServerCollection servers_; db::ServerCollection servers_;
/// @} /// @}
}; };