]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2419] Modify existing unit tests that cause reservation conflicts to ensure stats...
authorDan Theisen <djt@isc.org>
Thu, 7 Jul 2022 20:49:01 +0000 (14:49 -0600)
committerDan Theisen <djt@isc.org>
Fri, 8 Jul 2022 19:18:55 +0000 (12:18 -0700)
src/bin/dhcp4/tests/dora_unittest.cc
src/bin/dhcp4/tests/host_unittest.cc
src/bin/dhcp4/tests/shared_network_unittest.cc

index 90bfb281776df7d24cbbbed6c30385f5c5149ffb..54a5a1b715aabda0167d200263f08f3c65f045f3 100644 (file)
@@ -33,6 +33,7 @@ using namespace isc::asiolink;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::stats;
 
 namespace {
 
@@ -2023,6 +2024,14 @@ DORATest::reservationsWithConflicts() {
     ASSERT_EQ(DHCPACK, static_cast<int>(clientB.getContext().response_->getType()));
     IOAddress client_b_addr = clientB.config_.lease_.addr_;
     ASSERT_NE(client_b_addr, in_pool_addr);
+    // Ensure stats are being recorded for HR conflicts
+    ObservationPtr subnet_conflicts = StatsMgr::instance().getObservation(
+        "subnet[1].reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
+    subnet_conflicts = StatsMgr::instance().getObservation("v4-reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
 
     // Client A renews the lease.
     client.setState(Dhcp4Client::RENEWING);
@@ -2046,6 +2055,13 @@ DORATest::reservationsWithConflicts() {
     ASSERT_EQ(DHCPACK, static_cast<int>(clientB.getContext().response_->getType()));
     ASSERT_NE(clientB.config_.lease_.addr_, in_pool_addr);
     ASSERT_EQ(client_b_addr, clientB.config_.lease_.addr_);
+    // Ensure stats are being recorded for HR conflicts
+    subnet_conflicts = StatsMgr::instance().getObservation("subnet[1].reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(2, subnet_conflicts->getInteger().first);
+    subnet_conflicts = StatsMgr::instance().getObservation("v4-reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(2, subnet_conflicts->getInteger().first);
 
     // Client B renews its lease.
     clientB.setState(Dhcp4Client::RENEWING);
index 6502f68fa2f1fe7b8ed9bdfaa9557619d08307e6..acbd3d88bd85864b4a98aed85aa9d9727e06d93c 100644 (file)
@@ -23,6 +23,8 @@ using namespace isc::asiolink;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::stats;
+
 
 namespace {
 
@@ -768,6 +770,14 @@ TEST_F(HostTest, firstClientGetsReservedAddress) {
     // server should not assign this address because another client
     // has taken it already.
     EXPECT_NE("10.0.0.123", resp->getYiaddr().toText());
+    // Ensure stats are being recorded for HR conflicts
+    ObservationPtr subnet_conflicts = StatsMgr::instance().getObservation(
+        "subnet[10].reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
+    subnet_conflicts = StatsMgr::instance().getObservation("v4-reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
 
     // If the client1 releases the reserved lease, the client2 should acquire it.
     ASSERT_NO_THROW(client1.doRelease());
index 8e9601f96960ac5b3f1e8a94618351ee2ea80e01..b75f3941796901bc7548d9aa3eac49ad734b2b37 100644 (file)
@@ -1705,6 +1705,14 @@ TEST_F(Dhcpv4SharedNetworkTest, reservationInSharedNetwork) {
     EXPECT_EQ(DHCPACK, resp1->getType());
     EXPECT_NE("10.0.0.29", resp1->getYiaddr().toText());
     EXPECT_NE("192.0.2.28", resp1->getYiaddr().toText());
+    // Ensure stats are being recorded for HR conflicts
+    ObservationPtr subnet_conflicts = StatsMgr::instance().getObservation(
+        "subnet[10].reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
+    subnet_conflicts = StatsMgr::instance().getObservation("v4-reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
 
     // Client #2 is now doing 4-way exchange and should get its newly reserved
     // address, released by the 4-way transaction of client 1.
@@ -1774,10 +1782,9 @@ TEST_F(Dhcpv4SharedNetworkTest, reservationInSharedNetworkTwoClientsSameIdentifi
         "subnet[10].reservation-conflicts");
     ASSERT_TRUE(subnet_conflicts);
     ASSERT_EQ(1, subnet_conflicts->getInteger().first);
-    ObservationPtr global_conflicts = StatsMgr::instance().getObservation(
-        "v4-reservation-conflicts");
-    ASSERT_TRUE(global_conflicts);
-    ASSERT_EQ(1, global_conflicts->getInteger().first);
+    subnet_conflicts = StatsMgr::instance().getObservation("v4-reservation-conflicts");
+    ASSERT_TRUE(subnet_conflicts);
+    ASSERT_EQ(1, subnet_conflicts->getInteger().first);
 }
 
 // Reserved address can't be assigned as long as access to a subnet is