diff options
author | Slawek Figiel <slawek@isc.org> | 2023-04-18 13:21:49 +0200 |
---|---|---|
committer | Slawek Figiel <slawek@isc.org> | 2023-05-25 13:29:29 +0200 |
commit | d2c20f271705e45c05ac8b56b708ad5c3c6b87f3 (patch) | |
tree | 80f042a2d94b36e5340709a6b2256b1c7abbc121 /src/lib/dhcpsrv/testutils | |
parent | [#2815] Fix unit test (diff) | |
download | kea-d2c20f271705e45c05ac8b56b708ad5c3c6b87f3.tar.xz kea-d2c20f271705e45c05ac8b56b708ad5c3c6b87f3.zip |
[#2815] Fix unit test
Diffstat (limited to 'src/lib/dhcpsrv/testutils')
-rw-r--r-- | src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc | 114 |
1 files changed, 75 insertions, 39 deletions
diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index a2db72e3e3..a066a33ea0 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -4636,8 +4636,14 @@ HostMgrTest::testDeleteByIDAndAddress(BaseHostDataSource& data_source1, void HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, BaseHostDataSource& data_source2) { + // Set the mode of operation with multiple reservations for the same + // IP address. + ASSERT_TRUE(HostMgr::instance().setIPReservationsUnique(false)); + CfgMgr::instance().getStagingCfg()->getCfgHosts()->setIPReservationsUnique(false); + bool is_first_source_primary = isPrimaryDataSource(data_source1); bool is_second_source_primary = isPrimaryDataSource(data_source2); + bool has_alternate_source = !is_first_source_primary || !is_second_source_primary; size_t hosts_in_primary_source = is_first_source_primary + is_second_source_primary; size_t hosts_in_alternate_sources = 2 - hosts_in_primary_source; @@ -4646,30 +4652,43 @@ HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); CfgMgr::instance().commit(); - HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, - &hwaddrs_[0]->hwaddr_[0], - hwaddrs_[0]->hwaddr_.size(), - HostMgrOperationTarget::ALL_SOURCES); - HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, - &hwaddrs_[1]->hwaddr_[0], - hwaddrs_[1]->hwaddr_.size(), - HostMgrOperationTarget::ALL_SOURCES); + EXPECT_TRUE(HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size(), + HostMgrOperationTarget::ALL_SOURCES)); + EXPECT_TRUE(HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size(), + HostMgrOperationTarget::ALL_SOURCES)); - ASSERT_TRUE(HostMgr::instance().getAll4(SubnetID(1)).empty()); + EXPECT_TRUE(HostMgr::instance().getAll4(SubnetID(1)).empty()); // Delete from the default operation target. addHost4(data_source1, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.5")); addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); CfgMgr::instance().commit(); - HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, - &hwaddrs_[0]->hwaddr_[0], - hwaddrs_[0]->hwaddr_.size()); - HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, - &hwaddrs_[1]->hwaddr_[0], - hwaddrs_[1]->hwaddr_.size()); + if (has_alternate_source) { + EXPECT_EQ(!is_first_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size())); + EXPECT_EQ(!is_second_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size())); + } else { + EXPECT_THROW(HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size()), + NoHostDataSourceManager); + EXPECT_THROW(HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size()), + NoHostDataSourceManager); + } - ASSERT_EQ(hosts_in_primary_source, HostMgr::instance().getAll4(SubnetID(1)).size()); + EXPECT_EQ(hosts_in_primary_source, HostMgr::instance().getAll4(SubnetID(1)).size()); HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.5"), HostMgrOperationTarget::ALL_SOURCES); @@ -4678,16 +4697,31 @@ HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); CfgMgr::instance().commit(); - HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, - &hwaddrs_[0]->hwaddr_[0], - hwaddrs_[0]->hwaddr_.size(), - HostMgrOperationTarget::ALTERNATE_SOURCES); - HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, - &hwaddrs_[1]->hwaddr_[0], - hwaddrs_[1]->hwaddr_.size(), - HostMgrOperationTarget::ALTERNATE_SOURCES); + if (has_alternate_source) { + EXPECT_EQ(!is_first_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size(), + HostMgrOperationTarget::ALTERNATE_SOURCES)); + EXPECT_EQ(!is_second_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size(), + HostMgrOperationTarget::ALTERNATE_SOURCES)); + } else { + EXPECT_THROW(HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size(), + HostMgrOperationTarget::ALTERNATE_SOURCES), + NoHostDataSourceManager); + EXPECT_THROW(HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size(), + HostMgrOperationTarget::ALTERNATE_SOURCES), + NoHostDataSourceManager); + } - ASSERT_EQ(hosts_in_primary_source, HostMgr::instance().getAll4(SubnetID(1)).size()); + EXPECT_EQ(hosts_in_primary_source, HostMgr::instance().getAll4(SubnetID(1)).size()); HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.5"), HostMgrOperationTarget::ALL_SOURCES); @@ -4696,16 +4730,18 @@ HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); CfgMgr::instance().commit(); - HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, - &hwaddrs_[0]->hwaddr_[0], - hwaddrs_[0]->hwaddr_.size(), - HostMgrOperationTarget::PRIMARY_SOURCE); - HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, - &hwaddrs_[1]->hwaddr_[0], - hwaddrs_[1]->hwaddr_.size(), - HostMgrOperationTarget::PRIMARY_SOURCE); + EXPECT_EQ(is_first_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[0]->hwaddr_[0], + hwaddrs_[0]->hwaddr_.size(), + HostMgrOperationTarget::PRIMARY_SOURCE)); + EXPECT_EQ(is_second_source_primary, HostMgr::instance().del4(SubnetID(1), + Host::IDENT_HWADDR, + &hwaddrs_[1]->hwaddr_[0], + hwaddrs_[1]->hwaddr_.size(), + HostMgrOperationTarget::PRIMARY_SOURCE)); - ASSERT_EQ(hosts_in_alternate_sources, HostMgr::instance().getAll4(SubnetID(1)).size()); + EXPECT_EQ(hosts_in_alternate_sources, HostMgr::instance().getAll4(SubnetID(1)).size()); HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.5"), HostMgrOperationTarget::ALL_SOURCES); @@ -4714,16 +4750,16 @@ HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, addHost4(data_source2, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); CfgMgr::instance().commit(); - HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, + EXPECT_FALSE(HostMgr::instance().del4(SubnetID(1),Host::IDENT_HWADDR, &hwaddrs_[0]->hwaddr_[0], hwaddrs_[0]->hwaddr_.size(), - HostMgrOperationTarget::UNSPECIFIED_SOURCE); - HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, + HostMgrOperationTarget::UNSPECIFIED_SOURCE)); + EXPECT_FALSE(HostMgr::instance().del4(SubnetID(1), Host::IDENT_HWADDR, &hwaddrs_[1]->hwaddr_[0], hwaddrs_[1]->hwaddr_.size(), - HostMgrOperationTarget::UNSPECIFIED_SOURCE); + HostMgrOperationTarget::UNSPECIFIED_SOURCE)); - ASSERT_EQ(2, HostMgr::instance().getAll4(SubnetID(1)).size()); + EXPECT_EQ(2, HostMgr::instance().getAll4(SubnetID(1)).size()); HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.5"), HostMgrOperationTarget::ALL_SOURCES); } |