/// @brief Constructor.
CBControlDHCPTest()
- : timestamp_(), object_timestamp_(), audit_entries_() {
+ : timestamp_(), object_timestamp_(), audit_entries_(),
+ modification_id_(2345) {
CfgMgr::instance().clear();
initTimestamps();
callback_name_ = std::string("");
///
/// @param object_type Object type to be associated with the audit
/// entry.
- void addCreateAuditEntry(const std::string& object_type) {
- AuditEntryPtr entry(new AuditEntry(object_type, 1234,
+ /// @param object_id Identifier of the object to be associated with
+ /// the audit entry.
+ void addCreateAuditEntry(const std::string& object_type,
+ const uint64_t object_id) {
+ AuditEntryPtr entry(new AuditEntry(object_type, object_id,
AuditEntry::ModificationType::CREATE,
- 2345, "some log message"));
+ ++modification_id_,
+ "some log message"));
audit_entries_.insert(entry);
}
const uint64_t object_id) {
AuditEntryPtr entry(new AuditEntry(object_type, object_id,
AuditEntry::ModificationType::DELETE,
- 1234, "some log message"));
+ ++modification_id_,
+ "some log message"));
audit_entries_.insert(entry);
}
/// object types.
///
/// @param object_type Object type.
- bool fetchConfigElement(const std::string& object_type) const {
+ bool hasConfigElement(const std::string& object_type) const {
if (!audit_entries_.empty()) {
const auto& index = audit_entries_.get<AuditEntryObjectTypeTag>();
auto range = index.equal_range(object_type);
/// @brief Collection of audit entries used in the unit tests.
AuditEntryCollection audit_entries_;
+ /// @brief Modification id counter.
+ uint64_t modification_id_;
+
/// @brief Callback name.
static std::string callback_name_;
// If there is an audit entry for global parameter and the parameter
// modification time is later than last audit entry time it should
// be merged.
- if (fetchConfigElement("dhcp4_global_parameter") &&
+ if (hasConfigElement("dhcp4_global_parameter") &&
(getTimestamp("dhcp4_global_parameter") > lb_modification_time)) {
checkConfiguredGlobal(srv_cfg, "foo", Element::create("bar"));
// modification time is later than last audit entry time it should
// be merged.
auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
- if (fetchConfigElement("dhcp4_option_def") &&
+ if (hasConfigElement("dhcp4_option_def") &&
getTimestamp("dhcp4_option_def") > lb_modification_time) {
ASSERT_TRUE(found_def);
EXPECT_EQ(101, found_def->getCode());
// be merged.
auto options = srv_cfg->getCfgOption();
auto found_opt = options->get("dhcp4", DHO_HOST_NAME);
- if (fetchConfigElement("dhcp4_options") &&
+ if (hasConfigElement("dhcp4_options") &&
(getTimestamp("dhcp4_options") > lb_modification_time)) {
ASSERT_TRUE(found_opt.option_);
EXPECT_EQ("new.example.com", found_opt.option_->toString());
// be merged.
auto networks = srv_cfg->getCfgSharedNetworks4();
auto found_network = networks->getByName("one");
- if (fetchConfigElement("dhcp4_shared_network") &&
+ if (hasConfigElement("dhcp4_shared_network") &&
(getTimestamp("dhcp4_shared_network") > lb_modification_time)) {
ASSERT_TRUE(found_network);
EXPECT_TRUE(found_network->hasFetchGlobalsFn());
// time is later than last audit entry time it should be merged.
auto subnets = srv_cfg->getCfgSubnets4();
auto found_subnet = subnets->getSubnet(1);
- if (fetchConfigElement("dhcp4_subnet") &&
+ if (hasConfigElement("dhcp4_subnet") &&
(getTimestamp("dhcp4_subnet") > lb_modification_time)) {
ASSERT_TRUE(found_subnet);
EXPECT_TRUE(found_subnet->hasFetchGlobalsFn());
// types are merged into the current configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyAll) {
- addCreateAuditEntry("dhcp4_global_parameter");
- addCreateAuditEntry("dhcp4_option_def");
- addCreateAuditEntry("dhcp4_options");
- addCreateAuditEntry("dhcp4_shared_network");
- addCreateAuditEntry("dhcp4_subnet");
+ addCreateAuditEntry("dhcp4_global_parameter", 1);
+ addCreateAuditEntry("dhcp4_global_parameter", 2);
+ addCreateAuditEntry("dhcp4_option_def", 1);
+ addCreateAuditEntry("dhcp4_option_def", 2);
+ addCreateAuditEntry("dhcp4_options", 1);
+ addCreateAuditEntry("dhcp4_options", 2);
+ addCreateAuditEntry("dhcp4_shared_network", 1);
+ addCreateAuditEntry("dhcp4_shared_network", 2);
+ addCreateAuditEntry("dhcp4_subnet", 1);
+ addCreateAuditEntry("dhcp4_subnet", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// This test verifies that only a global parameter is merged into
// the current configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyGlobal) {
- addCreateAuditEntry("dhcp4_global_parameter");
+ addCreateAuditEntry("dhcp4_global_parameter", 1);
+ addCreateAuditEntry("dhcp4_global_parameter", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyGlobalNotFetched) {
- addCreateAuditEntry("dhcp4_global_parameter");
+ addCreateAuditEntry("dhcp4_global_parameter", 1);
+ addCreateAuditEntry("dhcp4_global_parameter", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only an option definition is merged into
// the current configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyOptionDef) {
- addCreateAuditEntry("dhcp4_option_def");
+ addCreateAuditEntry("dhcp4_option_def", 1);
+ addCreateAuditEntry("dhcp4_option_def", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyOptionDefNotFetched) {
- addCreateAuditEntry("dhcp4_option_def");
+ addCreateAuditEntry("dhcp4_option_def", 1);
+ addCreateAuditEntry("dhcp4_option_def", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a DHCPv4 option is merged into the
// current configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyOption) {
- addCreateAuditEntry("dhcp4_options");
+ addCreateAuditEntry("dhcp4_options", 1);
+ addCreateAuditEntry("dhcp4_options", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv4Test, databaseConfigApplyOptionNotFetched) {
- addCreateAuditEntry("dhcp4_options");
+ addCreateAuditEntry("dhcp4_options", 1);
+ addCreateAuditEntry("dhcp4_options", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a shared network is merged into the
// current configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplySharedNetwork) {
- addCreateAuditEntry("dhcp4_shared_network");
+ addCreateAuditEntry("dhcp4_shared_network", 1);
+ addCreateAuditEntry("dhcp4_shared_network", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv4Test, databaseConfigApplySharedNetworkNotFetched) {
- addCreateAuditEntry("dhcp4_shared_network");
+ addCreateAuditEntry("dhcp4_shared_network", 1);
+ addCreateAuditEntry("dhcp4_shared_network", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a subnet is merged into the current
// configuration.
TEST_F(CBControlDHCPv4Test, databaseConfigApplySubnet) {
- addCreateAuditEntry("dhcp4_shared_network");
- addCreateAuditEntry("dhcp4_subnet");
+ addCreateAuditEntry("dhcp4_shared_network", 1);
+ addCreateAuditEntry("dhcp4_shared_network", 2);
+ addCreateAuditEntry("dhcp4_subnet", 1);
+ addCreateAuditEntry("dhcp4_subnet", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// when the modification time is earlier than the last fetched audit
// entry.
TEST_F(CBControlDHCPv4Test, databaseConfigApplySubnetNotFetched) {
- addCreateAuditEntry("dhcp4_subnet");
+ addCreateAuditEntry("dhcp4_subnet", 1);
+ addCreateAuditEntry("dhcp4_subnet", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
"cb4_updated", cb4_updated_callout));
// Create audit entries.
- addCreateAuditEntry("dhcp4_global_parameter");
- addCreateAuditEntry("dhcp4_option_def");
- addCreateAuditEntry("dhcp4_options");
- addCreateAuditEntry("dhcp4_shared_network");
- addCreateAuditEntry("dhcp4_subnet");
+ addCreateAuditEntry("dhcp4_global_parameter", 1);
+ addCreateAuditEntry("dhcp4_global_parameter", 2);
+ addCreateAuditEntry("dhcp4_option_def", 1);
+ addCreateAuditEntry("dhcp4_option_def", 2);
+ addCreateAuditEntry("dhcp4_options", 1);
+ addCreateAuditEntry("dhcp4_options", 2);
+ addCreateAuditEntry("dhcp4_shared_network", 1);
+ addCreateAuditEntry("dhcp4_shared_network", 2);
+ addCreateAuditEntry("dhcp4_subnet", 1);
+ addCreateAuditEntry("dhcp4_subnet", 2);
// Run the test.
testDatabaseConfigApply(getTimestamp(-5));
// If there is an audit entry for global parameter and the parameter
// modification time is later than last audit entry time it should
// be merged.
- if (fetchConfigElement("dhcp6_global_parameter") &&
+ if (hasConfigElement("dhcp6_global_parameter") &&
(getTimestamp("dhcp6_global_parameter") > lb_modification_time)) {
checkConfiguredGlobal(srv_cfg, "foo", Element::create("bar"));
// modification time is later than last audit entry time it should
// be merged.
auto found_def = srv_cfg->getCfgOptionDef()->get("isc", "one");
- if (fetchConfigElement("dhcp6_option_def") &&
+ if (hasConfigElement("dhcp6_option_def") &&
getTimestamp("dhcp6_option_def") > lb_modification_time) {
ASSERT_TRUE(found_def);
EXPECT_EQ(101, found_def->getCode());
// be merged.
auto options = srv_cfg->getCfgOption();
auto found_opt = options->get("dhcp6", D6O_BOOTFILE_URL);
- if (fetchConfigElement("dhcp6_options") &&
+ if (hasConfigElement("dhcp6_options") &&
(getTimestamp("dhcp6_options") > lb_modification_time)) {
ASSERT_TRUE(found_opt.option_);
EXPECT_EQ("some.bootfile", found_opt.option_->toString());
// be merged.
auto networks = srv_cfg->getCfgSharedNetworks6();
auto found_network = networks->getByName("one");
- if (fetchConfigElement("dhcp6_shared_network") &&
+ if (hasConfigElement("dhcp6_shared_network") &&
(getTimestamp("dhcp6_shared_network") > lb_modification_time)) {
ASSERT_TRUE(found_network);
EXPECT_TRUE(found_network->hasFetchGlobalsFn());
// time is later than last audit entry time it should be merged.
auto subnets = srv_cfg->getCfgSubnets6();
auto found_subnet = subnets->getSubnet(1);
- if (fetchConfigElement("dhcp6_subnet") &&
+ if (hasConfigElement("dhcp6_subnet") &&
(getTimestamp("dhcp6_subnet") > lb_modification_time)) {
ASSERT_TRUE(found_subnet);
EXPECT_TRUE(found_subnet->hasFetchGlobalsFn());
// types are merged into the current configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyAll) {
- addCreateAuditEntry("dhcp6_global_parameter");
- addCreateAuditEntry("dhcp6_option_def");
- addCreateAuditEntry("dhcp6_options");
- addCreateAuditEntry("dhcp6_shared_network");
- addCreateAuditEntry("dhcp6_subnet");
+ addCreateAuditEntry("dhcp6_global_parameter", 1);
+ addCreateAuditEntry("dhcp6_global_parameter", 2);
+ addCreateAuditEntry("dhcp6_option_def", 1);
+ addCreateAuditEntry("dhcp6_option_def", 2);
+ addCreateAuditEntry("dhcp6_options", 1);
+ addCreateAuditEntry("dhcp6_options", 2);
+ addCreateAuditEntry("dhcp6_shared_network", 1);
+ addCreateAuditEntry("dhcp6_shared_network", 2);
+ addCreateAuditEntry("dhcp6_subnet", 1);
+ addCreateAuditEntry("dhcp6_subnet", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// This test verifies that only a global parameter is merged into
// the current configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyGlobal) {
- addCreateAuditEntry("dhcp6_global_parameter");
+ addCreateAuditEntry("dhcp6_global_parameter", 1);
+ addCreateAuditEntry("dhcp6_global_parameter", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyGlobalNotFetched) {
- addCreateAuditEntry("dhcp6_global_parameter");
+ addCreateAuditEntry("dhcp6_global_parameter", 1);
+ addCreateAuditEntry("dhcp6_global_parameter", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only an option definition is merged into
// the current configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyOptionDef) {
- addCreateAuditEntry("dhcp6_option_def");
+ addCreateAuditEntry("dhcp6_option_def", 1);
+ addCreateAuditEntry("dhcp6_option_def", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyOptionDefNotFetched) {
- addCreateAuditEntry("dhcp6_option_def");
+ addCreateAuditEntry("dhcp6_option_def", 1);
+ addCreateAuditEntry("dhcp6_option_def", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a DHCPv6 option is merged into the
// current configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyOption) {
- addCreateAuditEntry("dhcp6_options");
+ addCreateAuditEntry("dhcp6_options", 1);
+ addCreateAuditEntry("dhcp6_options", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv6Test, databaseConfigApplyOptionNotFetched) {
- addCreateAuditEntry("dhcp6_options");
+ addCreateAuditEntry("dhcp6_options", 1);
+ addCreateAuditEntry("dhcp6_options", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a shared network is merged into the
// current configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplySharedNetwork) {
- addCreateAuditEntry("dhcp6_shared_network");
+ addCreateAuditEntry("dhcp6_shared_network", 1);
+ addCreateAuditEntry("dhcp6_shared_network", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// database when the modification time is earlier than the last
// fetched audit entry.
TEST_F(CBControlDHCPv6Test, databaseConfigApplySharedNetworkNotFetched) {
- addCreateAuditEntry("dhcp6_shared_network");
+ addCreateAuditEntry("dhcp6_shared_network", 1);
+ addCreateAuditEntry("dhcp6_shared_network", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
// This test verifies that only a subnet is merged into the current
// configuration.
TEST_F(CBControlDHCPv6Test, databaseConfigApplySubnet) {
- addCreateAuditEntry("dhcp6_shared_network");
- addCreateAuditEntry("dhcp6_subnet");
+ addCreateAuditEntry("dhcp6_shared_network", 1);
+ addCreateAuditEntry("dhcp6_shared_network", 2);
+ addCreateAuditEntry("dhcp6_subnet", 1);
+ addCreateAuditEntry("dhcp6_subnet", 2);
testDatabaseConfigApply(getTimestamp(-5));
}
// when the modification time is earlier than the last fetched audit
// entry.
TEST_F(CBControlDHCPv6Test, databaseConfigApplySubnetNotFetched) {
- addCreateAuditEntry("dhcp6_subnet");
+ addCreateAuditEntry("dhcp6_subnet", 1);
+ addCreateAuditEntry("dhcp6_subnet", 2);
testDatabaseConfigApply(getTimestamp(-3));
}
"cb6_updated", cb6_updated_callout));
// Create audit entries.
- addCreateAuditEntry("dhcp6_global_parameter");
- addCreateAuditEntry("dhcp6_option_def");
- addCreateAuditEntry("dhcp6_options");
- addCreateAuditEntry("dhcp6_shared_network");
- addCreateAuditEntry("dhcp6_subnet");
+ addCreateAuditEntry("dhcp6_global_parameter", 1);
+ addCreateAuditEntry("dhcp6_global_parameter", 2);
+ addCreateAuditEntry("dhcp6_option_def", 1);
+ addCreateAuditEntry("dhcp6_option_def", 2);
+ addCreateAuditEntry("dhcp6_options", 1);
+ addCreateAuditEntry("dhcp6_options", 2);
+ addCreateAuditEntry("dhcp6_shared_network", 1);
+ addCreateAuditEntry("dhcp6_shared_network", 2);
+ addCreateAuditEntry("dhcp6_subnet", 1);
+ addCreateAuditEntry("dhcp6_subnet", 2);
// Run the test.
testDatabaseConfigApply(getTimestamp(-5));
EXPECT_EQ(0, cb_ctl_.getLastAuditEntryId());
}
-// This test verifies that it is correctly determined whether the
-// server should fetch the particular configuration element.
+// This test verifies that it is correctly determined what entries the
+// server should fetch for the particular configuration element.
TEST_F(CBControlBaseTest, fetchConfigElement) {
db::AuditEntryCollection audit_entries;
- // When audit entries collection is empty it indicates that this
- // is the case of the full server reconfiguration. Always indicate
- // that the configuration elements must be fetched.
- EXPECT_TRUE(cb_ctl_.fetchConfigElement(audit_entries, "my_object_type"));
+ db::AuditEntryCollection updated;
+ // When audit entries collection is empty any subset is empty too.
+ updated = cb_ctl_.fetchConfigElement(audit_entries, "my_object_type");
+ EXPECT_TRUE(updated.empty());
// Now test the case that there is a DELETE audit entry. In this case
// our function should indicate that the configuration should not be
AuditEntry::ModificationType::DELETE,
2345, "added audit entry"));
audit_entries.insert(audit_entry);
- EXPECT_FALSE(cb_ctl_.fetchConfigElement(audit_entries, "my_object_type"));
+ updated = cb_ctl_.fetchConfigElement(audit_entries, "my_object_type");
+ EXPECT_TRUE(updated.empty());
+ EXPECT_TRUE(hasObjectId(audit_entries, 1234));
+ EXPECT_FALSE(hasObjectId(audit_entries, 5678));
+ EXPECT_FALSE(hasObjectId(updated, 1234));
// Add another audit entry which indicates creation of the configuration element.
- // This time we should get 'true'.
+ // This time we should get it.
audit_entry.reset(new AuditEntry("my_object_type", 5678,
AuditEntry::ModificationType::CREATE,
6789, "added audit entry"));
audit_entries.insert(audit_entry);
- EXPECT_TRUE(cb_ctl_.fetchConfigElement(audit_entries, "my_object_type"));
+ updated = cb_ctl_.fetchConfigElement(audit_entries, "my_object_type");
+ ASSERT_EQ(1, updated.size());
+ AuditEntryPtr updated_entry = (*updated.begin());
+ ASSERT_TRUE(updated_entry);
+ EXPECT_EQ("my_object_type", updated_entry->getObjectType());
+ EXPECT_EQ(5678, updated_entry->getObjectId());
+ EXPECT_EQ(AuditEntry::ModificationType::CREATE, updated_entry->getModificationType());
+ EXPECT_TRUE(hasObjectId(audit_entries, 5678));
+ EXPECT_TRUE(hasObjectId(updated, 5678));
+ EXPECT_FALSE(hasObjectId(updated, 1234));
// Also we should get 'true' for the UPDATE case.
- audit_entry.reset(new AuditEntry("another_object_type",
+ audit_entry.reset(new AuditEntry("my_object_type",
5678, AuditEntry::ModificationType::UPDATE,
6790, "added audit entry"));
audit_entries.insert(audit_entry);
- EXPECT_TRUE(cb_ctl_.fetchConfigElement(audit_entries, "another_object_type"));
+ updated = cb_ctl_.fetchConfigElement(audit_entries, "my_object_type");
+ EXPECT_EQ(2, updated.size());
+ bool saw_create = false;
+ bool saw_update = false;
+ for (auto entry : updated) {
+ EXPECT_EQ("my_object_type", entry->getObjectType());
+ EXPECT_EQ(5678, entry->getObjectId());
+ if (AuditEntry::ModificationType::CREATE == entry->getModificationType()) {
+ EXPECT_FALSE(saw_create);
+ saw_create = true;
+ } else if (AuditEntry::ModificationType::UPDATE == entry->getModificationType()) {
+ EXPECT_FALSE(saw_update);
+ saw_update = true;
+ }
+ }
+ EXPECT_TRUE(saw_create);
+ EXPECT_TRUE(saw_update);
+ EXPECT_TRUE(hasObjectId(updated, 5678));
+ EXPECT_FALSE(hasObjectId(updated, 1234));
}
// This test verifies that true is return when the server successfully