Skip to content

Commit 3e93864

Browse files
committed
[#3375] Addressed comments
1 parent 91378b3 commit 3e93864

6 files changed

+155
-3
lines changed

src/lib/dhcpsrv/hosts_messages.mes

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ This debug message is issued when no host was found using the specified
278278
subnet id and host identifier.
279279

280280
% HOSTS_CFG_UPDATE_ADD add the host for reservations: %1
281-
This debug message is issued when new host (with reservations) is
281+
This debug message is issued when a new host (with reservations) is
282282
added to the server's configuration during an update. The argument
283283
describes the host and its reservations in detail.
284284

src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc

+38-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CfgHostsTest : public ::testing::Test {
7272
void testDeleteForIPv4();
7373
void testDeleteForIPv6();
7474
void testDelete2ForIPv6();
75+
void testDeleteBothForIPv6();
7576
void testDel4();
7677
void testDel6();
7778
void testDeleteAll4();
@@ -719,7 +720,7 @@ TEST_F(CfgHostsTest, deleteForIPv6MultiThreading) {
719720
void
720721
CfgHostsTest::testDelete2ForIPv6() {
721722
CfgHosts cfg;
722-
// Add host with two addresses.
723+
// Add a host with two addresses.
723724
IOAddress address1("2001:db8:1::1");
724725
IOAddress address2("2001:db8:2::2");
725726
size_t host_count = 10;
@@ -732,7 +733,7 @@ CfgHostsTest::testDelete2ForIPv6() {
732733
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address2));
733734
cfg.add(host);
734735

735-
// Delete one host using first address.
736+
// Delete the host using its first address.
736737
EXPECT_TRUE(cfg.del(subnet_id, address1));
737738

738739
// Check if all addresses were removed.
@@ -749,6 +750,41 @@ TEST_F(CfgHostsTest, delete2ForIPv6MultiThreading) {
749750
testDelete2ForIPv6();
750751
}
751752

753+
// This test checks that IPv6 address and prefix reservations for the specified
754+
// subnet ID and IPv6 address can be deleted.
755+
void
756+
CfgHostsTest::testDeleteBothForIPv6() {
757+
CfgHosts cfg;
758+
// Add a host with two addresses.
759+
IOAddress address1("2001:db8:1::1");
760+
IOAddress address2("2001:db8:2::");
761+
size_t host_count = 10;
762+
SubnetID subnet_id(42);
763+
764+
HostPtr host = HostPtr(new Host(duids_[0]->toText(), "duid",
765+
SUBNET_ID_UNUSED, subnet_id,
766+
IOAddress::IPV4_ZERO_ADDRESS()));
767+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
768+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, address2, 64));
769+
cfg.add(host);
770+
771+
// Delete the host using its address.
772+
EXPECT_TRUE(cfg.del(subnet_id, address1));
773+
774+
// Check if all reservations were removed.
775+
EXPECT_FALSE(cfg.get6(subnet_id, address2));
776+
EXPECT_FALSE(cfg.del(subnet_id, address2));
777+
}
778+
779+
TEST_F(CfgHostsTest, deleteBothForIPv6) {
780+
testDeleteBothForIPv6();
781+
}
782+
783+
TEST_F(CfgHostsTest, deleteBothForIPv6MultiThreading) {
784+
MultiThreadingTest mt(true);
785+
testDeleteBothForIPv6();
786+
}
787+
752788
// This test checks that false is returned for deleting the IPv4 reservation
753789
// that doesn't exist.
754790
TEST_F(CfgHostsTest, deleteForMissingIPv4) {

src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc

+26
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,32 @@ TEST_F(MySqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
14431443
testDeleteById6Options();
14441444
}
14451445

1446+
// This test verifies that all reservations can be deleted from database
1447+
// by providing subnet ID and one address.
1448+
TEST_F(MySqlHostDataSourceTest, del2) {
1449+
testDelete2ForIPv6();
1450+
}
1451+
1452+
// This test verifies that all reservations can be deleted from database
1453+
// by providing subnet ID and one address.
1454+
TEST_F(MySqlHostDataSourceTest, del2MultiThreading) {
1455+
MultiThreadingTest mt(true);
1456+
testDelete2ForIPv6();
1457+
}
1458+
1459+
// This test verifies that address and PD reservations can be deleted from database
1460+
// by providing subnet ID and the address.
1461+
TEST_F(MySqlHostDataSourceTest, delBoth) {
1462+
testDelete2ForIPv6();
1463+
}
1464+
1465+
// This test verifies that address and PD reservations can be deleted from database
1466+
// by providing subnet ID and the address.
1467+
TEST_F(MySqlHostDataSourceTest, delBothMultiThreading) {
1468+
MultiThreadingTest mt(true);
1469+
testDelete2ForIPv6();
1470+
}
1471+
14461472
/// @brief Tests that multiple reservations without IPv4 addresses can be
14471473
/// specified within a subnet.
14481474
TEST_F(MySqlHostDataSourceTest, testMultipleHostsNoAddress4) {

src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc

+26
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,32 @@ TEST_F(PgSqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
14111411
testDeleteById6Options();
14121412
}
14131413

1414+
// This test verifies that all reservations can be deleted from database
1415+
// by providing subnet ID and one address.
1416+
TEST_F(PgSqlHostDataSourceTest, del2) {
1417+
testDelete2ForIPv6();
1418+
}
1419+
1420+
// This test verifies that all reservations can be deleted from database
1421+
// by providing subnet ID and one address.
1422+
TEST_F(PgSqlHostDataSourceTest, del2MultiThreading) {
1423+
MultiThreadingTest mt(true);
1424+
testDelete2ForIPv6();
1425+
}
1426+
1427+
// This test verifies that address and PD reservations can be deleted from database
1428+
// by providing subnet ID and the address.
1429+
TEST_F(PgSqlHostDataSourceTest, delBoth) {
1430+
testDelete2ForIPv6();
1431+
}
1432+
1433+
// This test verifies that address and PD reservations can be deleted from database
1434+
// by providing subnet ID and the address.
1435+
TEST_F(PgSqlHostDataSourceTest, delBothMultiThreading) {
1436+
MultiThreadingTest mt(true);
1437+
testDelete2ForIPv6();
1438+
}
1439+
14141440
/// @brief Tests that multiple reservations without IPv4 addresses can be
14151441
/// specified within a subnet.
14161442
TEST_F(PgSqlHostDataSourceTest, testMultipleHostsNoAddress4) {

src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc

+56
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,62 @@ GenericHostDataSourceTest::testDeleteById6Options() {
26192619
EXPECT_FALSE(result);
26202620
}
26212621

2622+
void
2623+
GenericHostDataSourceTest::testDelete2ForIPv6() {
2624+
// Make sure we have a pointer to the host data source.
2625+
ASSERT_TRUE(hdsptr_);
2626+
2627+
// Let's create a v6 host...
2628+
IOAddress address1("2001:db8:1::1");
2629+
IOAddress address2("2001:db8:2::2");
2630+
SubnetID subnet_id(42);
2631+
auto ident = HostDataSourceUtils::generateIdentifier(Host::IDENT_DUID);
2632+
HostPtr host = HostPtr(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
2633+
SUBNET_ID_UNUSED, subnet_id,
2634+
IOAddress::IPV4_ZERO_ADDRESS()));
2635+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
2636+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address2));
2637+
// ... and add it to the data source.
2638+
ASSERT_NO_THROW(hdsptr_->add(host));
2639+
EXPECT_EQ(2, countDBReservations6());
2640+
2641+
// Delete the host using its first address.
2642+
EXPECT_TRUE(hdsptr_->del(subnet_id, address1));
2643+
2644+
// Check if all addresses were removed.
2645+
EXPECT_EQ(0, countDBReservations6());
2646+
EXPECT_FALSE(hdsptr_->get6(subnet_id, address2));
2647+
EXPECT_FALSE(hdsptr_->del(subnet_id, address2));
2648+
}
2649+
2650+
void
2651+
GenericHostDataSourceTest::testDeleteBothForIPv6() {
2652+
// Make sure we have a pointer to the host data source.
2653+
ASSERT_TRUE(hdsptr_);
2654+
2655+
// Let's create a v6 host...
2656+
IOAddress address1("2001:db8:1::1");
2657+
IOAddress address2("2001:db8:2::");
2658+
SubnetID subnet_id(42);
2659+
auto ident = HostDataSourceUtils::generateIdentifier(Host::IDENT_DUID);
2660+
HostPtr host = HostPtr(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
2661+
SUBNET_ID_UNUSED, subnet_id,
2662+
IOAddress::IPV4_ZERO_ADDRESS()));
2663+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
2664+
host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, address2, 64));
2665+
// ... and add it to the data source.
2666+
ASSERT_NO_THROW(hdsptr_->add(host));
2667+
EXPECT_EQ(2, countDBReservations6());
2668+
2669+
// Delete the host using its address.
2670+
EXPECT_TRUE(hdsptr_->del(subnet_id, address1));
2671+
2672+
// Check if all reservations were removed.
2673+
EXPECT_EQ(0, countDBReservations6());
2674+
EXPECT_FALSE(hdsptr_->get6(subnet_id, address2));
2675+
EXPECT_FALSE(hdsptr_->del(subnet_id, address2));
2676+
}
2677+
26222678
void
26232679
GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
26242680
// Make sure we have a pointer to the host data source.

src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

+8
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ class GenericHostDataSourceTest : public GenericBackendTest {
508508
/// Uses gtest macros to report failures.
509509
void testDeleteById6Options();
510510

511+
/// @brief Tests that two IPv6 reservations for the specified subnet ID
512+
/// and IPv6 address can be deleted.
513+
void testDelete2ForIPv6();
514+
515+
/// @brief Tests that IPv6 address and prefix reservations for the specified
516+
/// subnet ID and IPv6 address can be deleted.
517+
void testDeleteBothForIPv6();
518+
511519
/// @brief Tests that multiple reservations without IPv4 addresses can be
512520
/// specified within a subnet.
513521
///

0 commit comments

Comments
 (0)