]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3375] Addressed comments
authorFrancis Dupont <fdupont@isc.org>
Mon, 10 Jun 2024 08:38:08 +0000 (10:38 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 10 Jun 2024 08:38:08 +0000 (10:38 +0200)
src/lib/dhcpsrv/hosts_messages.mes
src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

index 93e89b4d77cfb7333f4fdc843b874ec1151b243d..58ed525082fd68849c8ce31af0b477145d99b11c 100644 (file)
@@ -278,7 +278,7 @@ This debug message is issued when no host was found using the specified
 subnet id and host identifier.
 
 % HOSTS_CFG_UPDATE_ADD add the host for reservations: %1
-This debug message is issued when new host (with reservations) is
+This debug message is issued when new host (with reservations) is
 added to the server's configuration during an update. The argument
 describes the host and its reservations in detail.
 
index 66ccd54e4d805d69056e29142923c00c7c46c303..2076a5cdf714c7a1f936c2459f07130d46691409 100644 (file)
@@ -72,6 +72,7 @@ public:
     void testDeleteForIPv4();
     void testDeleteForIPv6();
     void testDelete2ForIPv6();
+    void testDeleteBothForIPv6();
     void testDel4();
     void testDel6();
     void testDeleteAll4();
@@ -719,7 +720,7 @@ TEST_F(CfgHostsTest, deleteForIPv6MultiThreading) {
 void
 CfgHostsTest::testDelete2ForIPv6() {
     CfgHosts cfg;
-    // Add host with two addresses.
+    // Add host with two addresses.
     IOAddress address1("2001:db8:1::1");
     IOAddress address2("2001:db8:2::2");
     size_t host_count = 10;
@@ -732,7 +733,7 @@ CfgHostsTest::testDelete2ForIPv6() {
     host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address2));
     cfg.add(host);
 
-    // Delete one host using first address.
+    // Delete the host using its first address.
     EXPECT_TRUE(cfg.del(subnet_id, address1));
 
     // Check if all addresses were removed.
@@ -749,6 +750,41 @@ TEST_F(CfgHostsTest, delete2ForIPv6MultiThreading) {
     testDelete2ForIPv6();
 }
 
+// This test checks that IPv6 address and prefix reservations for the specified
+// subnet ID and IPv6 address can be deleted.
+void
+CfgHostsTest::testDeleteBothForIPv6() {
+    CfgHosts cfg;
+    // Add a host with two addresses.
+    IOAddress address1("2001:db8:1::1");
+    IOAddress address2("2001:db8:2::");
+    size_t host_count = 10;
+    SubnetID subnet_id(42);
+
+    HostPtr host = HostPtr(new Host(duids_[0]->toText(), "duid",
+                                    SUBNET_ID_UNUSED, subnet_id,
+                                    IOAddress::IPV4_ZERO_ADDRESS()));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, address2, 64));
+    cfg.add(host);
+
+    // Delete the host using its address.
+    EXPECT_TRUE(cfg.del(subnet_id, address1));
+
+    // Check if all reservations were removed.
+    EXPECT_FALSE(cfg.get6(subnet_id, address2));
+    EXPECT_FALSE(cfg.del(subnet_id, address2));
+}
+
+TEST_F(CfgHostsTest, deleteBothForIPv6) {
+    testDeleteBothForIPv6();
+}
+
+TEST_F(CfgHostsTest, deleteBothForIPv6MultiThreading) {
+    MultiThreadingTest mt(true);
+    testDeleteBothForIPv6();
+}
+
 // This test checks that false is returned for deleting the IPv4 reservation
 // that doesn't exist.
 TEST_F(CfgHostsTest, deleteForMissingIPv4) {
index fe1fa67a565a33e8e6d736f2e365a072f1bf7e09..830a4dd96acf9c687db9743c789d4272fe88908b 100644 (file)
@@ -1443,6 +1443,32 @@ TEST_F(MySqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
     testDeleteById6Options();
 }
 
+// This test verifies that all reservations can be deleted from database
+// by providing subnet ID and one address.
+TEST_F(MySqlHostDataSourceTest, del2) {
+    testDelete2ForIPv6();
+}
+
+// This test verifies that all reservations can be deleted from database
+// by providing subnet ID and one address.
+TEST_F(MySqlHostDataSourceTest, del2MultiThreading) {
+    MultiThreadingTest mt(true);
+    testDelete2ForIPv6();
+}
+
+// This test verifies that address and PD reservations can be deleted from database
+// by providing subnet ID and the address.
+TEST_F(MySqlHostDataSourceTest, delBoth) {
+    testDelete2ForIPv6();
+}
+
+// This test verifies that address and PD reservations can be deleted from database
+// by providing subnet ID and the address.
+TEST_F(MySqlHostDataSourceTest, delBothMultiThreading) {
+    MultiThreadingTest mt(true);
+    testDelete2ForIPv6();
+}
+
 /// @brief Tests that multiple reservations without IPv4 addresses can be
 /// specified within a subnet.
 TEST_F(MySqlHostDataSourceTest, testMultipleHostsNoAddress4) {
index 543ba9f1a7d736375cf4c3e76cc970436f76be68..1f136cffb6046e01281c01890b294948dff8a6df 100644 (file)
@@ -1411,6 +1411,32 @@ TEST_F(PgSqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
     testDeleteById6Options();
 }
 
+// This test verifies that all reservations can be deleted from database
+// by providing subnet ID and one address.
+TEST_F(PgSqlHostDataSourceTest, del2) {
+    testDelete2ForIPv6();
+}
+
+// This test verifies that all reservations can be deleted from database
+// by providing subnet ID and one address.
+TEST_F(PgSqlHostDataSourceTest, del2MultiThreading) {
+    MultiThreadingTest mt(true);
+    testDelete2ForIPv6();
+}
+
+// This test verifies that address and PD reservations can be deleted from database
+// by providing subnet ID and the address.
+TEST_F(PgSqlHostDataSourceTest, delBoth) {
+    testDelete2ForIPv6();
+}
+
+// This test verifies that address and PD reservations can be deleted from database
+// by providing subnet ID and the address.
+TEST_F(PgSqlHostDataSourceTest, delBothMultiThreading) {
+    MultiThreadingTest mt(true);
+    testDelete2ForIPv6();
+}
+
 /// @brief Tests that multiple reservations without IPv4 addresses can be
 /// specified within a subnet.
 TEST_F(PgSqlHostDataSourceTest, testMultipleHostsNoAddress4) {
index 3b612f4bd06b3064dba1152c0bed010269fbfa86..8fce65f21646d8a153c9aab3083da314b818b330 100644 (file)
@@ -2619,6 +2619,62 @@ GenericHostDataSourceTest::testDeleteById6Options() {
     EXPECT_FALSE(result);
 }
 
+void
+GenericHostDataSourceTest::testDelete2ForIPv6() {
+    // Make sure we have a pointer to the host data source.
+    ASSERT_TRUE(hdsptr_);
+
+    // Let's create a v6 host...
+    IOAddress address1("2001:db8:1::1");
+    IOAddress address2("2001:db8:2::2");
+    SubnetID subnet_id(42);
+    auto ident = HostDataSourceUtils::generateIdentifier(Host::IDENT_DUID);
+    HostPtr host = HostPtr(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
+                                    SUBNET_ID_UNUSED, subnet_id,
+                                    IOAddress::IPV4_ZERO_ADDRESS()));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address2));
+    // ... and add it to the data source.
+    ASSERT_NO_THROW(hdsptr_->add(host));
+    EXPECT_EQ(2, countDBReservations6());
+
+    // Delete the host using its first address.
+    EXPECT_TRUE(hdsptr_->del(subnet_id, address1));
+
+    // Check if all addresses were removed.
+    EXPECT_EQ(0, countDBReservations6());
+    EXPECT_FALSE(hdsptr_->get6(subnet_id, address2));
+    EXPECT_FALSE(hdsptr_->del(subnet_id, address2));
+}
+
+void
+GenericHostDataSourceTest::testDeleteBothForIPv6() {
+    // Make sure we have a pointer to the host data source.
+    ASSERT_TRUE(hdsptr_);
+
+    // Let's create a v6 host...
+    IOAddress address1("2001:db8:1::1");
+    IOAddress address2("2001:db8:2::");
+    SubnetID subnet_id(42);
+    auto ident = HostDataSourceUtils::generateIdentifier(Host::IDENT_DUID);
+    HostPtr host = HostPtr(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
+                                    SUBNET_ID_UNUSED, subnet_id,
+                                    IOAddress::IPV4_ZERO_ADDRESS()));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, address1));
+    host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, address2, 64));
+    // ... and add it to the data source.
+    ASSERT_NO_THROW(hdsptr_->add(host));
+    EXPECT_EQ(2, countDBReservations6());
+
+    // Delete the host using its address.
+    EXPECT_TRUE(hdsptr_->del(subnet_id, address1));
+
+    // Check if all reservations were removed.
+    EXPECT_EQ(0, countDBReservations6());
+    EXPECT_FALSE(hdsptr_->get6(subnet_id, address2));
+    EXPECT_FALSE(hdsptr_->del(subnet_id, address2));
+}
+
 void
 GenericHostDataSourceTest::testMultipleHostsNoAddress4() {
     // Make sure we have a pointer to the host data source.
index 8eba40a2c8923ca6c6678335cb690c29b21cc168..944daa602d7faef5b601b0a7f50b47d8496688fd 100644 (file)
@@ -508,6 +508,14 @@ public:
     /// Uses gtest macros to report failures.
     void testDeleteById6Options();
 
+    /// @brief Tests that two IPv6 reservations for the specified subnet ID
+    /// and IPv6 address can be deleted.
+    void testDelete2ForIPv6();
+
+    /// @brief Tests that IPv6 address and prefix reservations for the specified
+    /// subnet ID and IPv6 address can be deleted.
+    void testDeleteBothForIPv6();
+
     /// @brief Tests that multiple reservations without IPv4 addresses can be
     /// specified within a subnet.
     ///