Skip to content

Commit aaaae03

Browse files
committed
[#3294] adding UTs
1 parent 387edbe commit aaaae03

4 files changed

+54
-0
lines changed

src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,13 @@ TEST_F(MySQLHostMgrTest, del) {
16711671
testDeleteByIDAndAddress(*getCfgHosts(), HostMgr::instance());
16721672
}
16731673

1674+
// This test verifies that the reservation can be deleted from database
1675+
// by providing subnet ID and address, and other reservations in the subnet
1676+
// remain undeleted.
1677+
TEST_F(MySQLHostMgrTest, delOneHost) {
1678+
testDeleteOneHostByIDAndAddress(HostMgr::instance());
1679+
}
1680+
16741681
// This test verifies that the IPv4 reservations can be deleted from a
16751682
// configuration file and a database by subnet ID and identifier.
16761683
TEST_F(MySQLHostMgrTest, del4) {

src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,13 @@ TEST_F(PgSQLHostMgrTest, del) {
16391639
testDeleteByIDAndAddress(*getCfgHosts(), HostMgr::instance());
16401640
}
16411641

1642+
// This test verifies that the reservation can be deleted from database
1643+
// by providing subnet ID and address, and other reservations in the subnet
1644+
// remain undeleted.
1645+
TEST_F(PgSQLHostMgrTest, delOneHost) {
1646+
testDeleteOneHostByIDAndAddress(HostMgr::instance());
1647+
}
1648+
16421649
// This test verifies that the IPv4 reservations can be deleted from a
16431650
// configuration file and a database by subnet ID and identifier.
16441651
TEST_F(PgSQLHostMgrTest, del4) {

src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5098,6 +5098,38 @@ HostMgrTest::testDeleteByIDAndAddress(BaseHostDataSource& data_source1,
50985098
HostMgr::instance().del(SubnetID(1), IOAddress("2001:db8:1::5"), HostMgrOperationTarget::ALL_SOURCES);
50995099
}
51005100

5101+
void
5102+
HostMgrTest::testDeleteOneHostByIDAndAddress(BaseHostDataSource& data_source) {
5103+
ASSERT_TRUE(HostMgr::instance().setIPReservationsUnique(false));
5104+
5105+
// This test expects alternate data source - MySQL or PostgreSQL hosts DB.
5106+
EXPECT_FALSE(isPrimaryDataSource(data_source));
5107+
5108+
// Add 3 IPv4 hosts.
5109+
addHost4(data_source, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.4"));
5110+
addHost4(data_source, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5"));
5111+
addHost4(data_source, hwaddrs_[2], SubnetID(1), IOAddress("192.0.2.6"));
5112+
5113+
// Add 3 IPv6 hosts.
5114+
addHost6(data_source, duids_[0], SubnetID(1), IOAddress("2001:db8:1::4"));
5115+
addHost6(data_source, duids_[1], SubnetID(1), IOAddress("2001:db8:1::5"));
5116+
addHost6(data_source, duids_[2], SubnetID(1), IOAddress("2001:db8:1::6"));
5117+
5118+
CfgMgr::instance().commit();
5119+
5120+
// Delete only one IPv4 host - provide SubnetId and IP address for the host to be deleted.
5121+
EXPECT_TRUE(HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.4")));
5122+
5123+
// Delete only one IPv6 host - provide SubnetId and IP address for the host to be deleted.
5124+
EXPECT_TRUE(HostMgr::instance().del(SubnetID(1), IOAddress("2001:db8:1::4")));
5125+
5126+
// Expect other two IPv4 hosts still in reservations.
5127+
EXPECT_EQ(4, HostMgr::instance().getAll4(SubnetID(1)).size());
5128+
5129+
// Expect other two IPv6 hosts still in reservations.
5130+
EXPECT_EQ(2, HostMgr::instance().getAll6(SubnetID(1)).size());
5131+
}
5132+
51015133
void
51025134
HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1,
51035135
BaseHostDataSource& data_source2) {

src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,14 @@ class HostMgrTest : public ::testing::Test {
10481048
void testDeleteByIDAndAddress(BaseHostDataSource& data_source1,
10491049
BaseHostDataSource& data_source2);
10501050

1051+
/// @brief This test verifies that HostMgr deletes only desired
1052+
/// reservations by the subnet ID and subnet address in alternate
1053+
/// data sources (hosts DB backends). It verifies that other reservations
1054+
/// in the subnet remain undeleted.
1055+
///
1056+
/// @param data_source alternate host data source
1057+
void testDeleteOneHostByIDAndAddress(BaseHostDataSource& data_source);
1058+
10511059
/// @brief This test verifies that HostMgr deletes the IPv4 reservations by
10521060
/// the subnet ID and identifier.
10531061
///

0 commit comments

Comments
 (0)