From: Shawn Routhier Date: Thu, 18 Jun 2015 03:55:15 +0000 (-0700) Subject: [3799] Add more tests X-Git-Tag: trac3910_base~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4963266a43960a9ebf30a0f823b371388451a34;p=thirdparty%2Fkea.git [3799] Add more tests Update the documents a bit Fix up handling reservations from outside the subnet Add more tests --- diff --git a/doc/guide/dhcp6-srv.xml b/doc/guide/dhcp6-srv.xml index ba8e782f77..459ee501b2 100644 --- a/doc/guide/dhcp6-srv.xml +++ b/doc/guide/dhcp6-srv.xml @@ -2608,13 +2608,14 @@ should include options from the isc option space: subnet[id].total-NAs integer - This statistic shows the total number of NA addresses available for the - DHCPv6 management. In other words, this is the sum of all addresses in - all configured pools. This statistic changes only during configuration - changes. Note it does not take into account any addresses that may be - reserved due to host reservation. The id is the - subnet-id of a given subnet. This statistic is exposed for each subnet - separately. This statistic is reset during reconfiguration event. + This statistic shows the total number of NA addresses available for + DHCPv6 management for a given subnet. In other words, this is the sum + of all addresses in all configured pools. This statistic changes only + during configuration changes. Note it does not take into account any + addresses that may be reserved due to host reservation. The + id is the subnet-id of a given subnet. This + statistic is exposed for each subnet separately. This statistic is + reset during a reconfiguration event. @@ -2622,14 +2623,14 @@ should include options from the isc option space: subnet[id].assigned-NAs integer - This statistic shows the number of assigned NA addresses in a given subnet. - This statistic increases every time a new lease is allocated (as a result - of receiving a REQUEST message) and is decreased every time a lease is - released (a RELEASE message is received). When lease expiration + This statistic shows the number of NA addresses in a given subnet that + are assigned. This statistic increases every time a new lease is allocated + (as a result of receiving a REQUEST message) and is decreased every time a + lease is released (a RELEASE message is received). When lease expiration is implemented (planned for Kea 1.0), it will also decrease when a lease is expired. The id is the subnet-id of a given subnet. This statistic is exposed for each subnet separately. This - statistic is reset during reconfiguration event. + statistic is reset during a reconfiguration event. @@ -2637,13 +2638,14 @@ should include options from the isc option space: subnet[id].total-PDs integer - This statistic shows the total number of PD prefixes available for the - DHCPv6 management. In other words, this is the sum of all prefixes in - all configured pools. This statistic changes only during configuration - changes. Note it does not take into account any prefixes that may be - reserved due to host reservation. The id is the - subnet-id of a given subnet. This statistic is exposed for each subnet - separately. This statistic is reset during reconfiguration event. + This statistic shows the total number of PD prefixes available for + DHCPv6 management for a given subnet. In other words, this is the sum + of all prefixes in all configured pools. This statistic changes only + during configuration changes. Note it does not take into account any + prefixes that may be reserved due to host reservation. The + id is the subnet-id of a given subnet. This + statistic is exposed for each subnet separately. This statistic is + reset during a reconfiguration event. @@ -2651,14 +2653,14 @@ should include options from the isc option space: subnet[id].assigned-PDs integer - This statistic shows the number of assigned PD prefixes in a given subnet. - This statistic increases every time a new lease is allocated (as a result - of receiving a REQUEST message) and is decreased every time a lease is - released (a RELEASE message is received). When lease expiration + This statistic shows the number of PD prefixes in a given subnet that + are assigned. This statistic increases every time a new lease is allocated + (as a result of receiving a REQUEST message) and is decreased every time a + lease is released (a RELEASE message is received). When lease expiration is implemented (planned for Kea 1.0), it will also decrease when a lease is expired. The id is the subnet-id of a given subnet. This statistic is exposed for each subnet separately. This - statistic is reset during reconfiguration event. + statistic is reset during a reconfiguration event. diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index eb308e711a..bc19453db4 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -966,6 +966,7 @@ TEST_F(Dhcpv6SrvTest, pdRenewReject) { // - returned REPLY message has server-id // - returned REPLY message has IA_NA that does not include an IAADDR // - lease is actually removed from LeaseMgr +// - assigned-NAs stats counter is properly decremented TEST_F(Dhcpv6SrvTest, ReleaseBasic) { testReleaseBasic(Lease::TYPE_NA, IOAddress("2001:db8:1:1::cafe:babe"), IOAddress("2001:db8:1:1::cafe:babe")); @@ -980,6 +981,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseBasic) { // - returned REPLY message has server-id // - returned REPLY message has IA_PD that does not include an IAPREFIX // - lease is actually removed from LeaseMgr +// - assigned-PDs stats counter is properly decremented TEST_F(Dhcpv6SrvTest, pdReleaseBasic) { testReleaseBasic(Lease::TYPE_PD, IOAddress("2001:db8:1:2::"), IOAddress("2001:db8:1:2::")); @@ -998,6 +1000,7 @@ TEST_F(Dhcpv6SrvTest, pdReleaseBasic) { // - returned REPLY message has server-id // - returned REPLY message has IA_NA that includes STATUS-CODE // - No lease in LeaseMgr +// - assigned-NAs stats counter is properly not decremented TEST_F(Dhcpv6SrvTest, ReleaseReject) { testReleaseReject(Lease::TYPE_NA, IOAddress("2001:db8:1:1::dead")); } @@ -1015,6 +1018,7 @@ TEST_F(Dhcpv6SrvTest, ReleaseReject) { // - returned REPLY message has server-id // - returned REPLY message has IA_PD that includes STATUS-CODE // - No lease in LeaseMgr +// - assigned-PDs stats counter is properly not decremented TEST_F(Dhcpv6SrvTest, pdReleaseReject) { testReleaseReject(Lease::TYPE_PD, IOAddress("2001:db8:1:2::")); } diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.cc b/src/bin/dhcp6/tests/dhcp6_test_utils.cc index 550fb5244c..5beb1951f8 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.cc +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ using namespace isc::data; using namespace isc::dhcp; using namespace isc::asiolink; +using namespace isc::stats; namespace isc { namespace test { @@ -590,6 +592,12 @@ Dhcpv6SrvTest::testReleaseBasic(Lease::Type type, const IOAddress& existing, Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, existing); ASSERT_TRUE(l); + // And prepopulate the stats counter + std::string name = StatsMgr::generateName("subnet", subnet_->getID(), + type == Lease::TYPE_NA ? "assigned-NAs" : + "assigned-PDs"); + StatsMgr::instance().setValue(name, static_cast(1)); + // Let's create a RELEASE Pkt6Ptr rel = createMessage(DHCPV6_RELEASE, type, release_addr, prefix_len, iaid); @@ -628,6 +636,11 @@ Dhcpv6SrvTest::testReleaseBasic(Lease::Type type, const IOAddress& existing, l = LeaseMgrFactory::instance().getLease6(type, *duid_, iaid, subnet_->getID()); ASSERT_FALSE(l); + + // We should have decremented the address counter + ObservationPtr stat = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(stat); + EXPECT_EQ(0, stat->getInteger().first); } void @@ -656,6 +669,12 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) { // GenerateClientId() also sets duid_ OptionPtr clientid = generateClientId(); + // Pretend we have allocated 1 lease + std::string name = StatsMgr::generateName("subnet", subnet_->getID(), + type == Lease::TYPE_NA ? "assigned-NAs" : + "assigned-PDs"); + StatsMgr::instance().setValue(name, static_cast(1)); + // Check that the lease is NOT in the database Lease6Ptr l = LeaseMgrFactory::instance().getLease6(type, addr); ASSERT_FALSE(l); @@ -685,6 +704,11 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) { l = LeaseMgrFactory::instance().getLease6(type, addr); ASSERT_FALSE(l); + // Verify we didn't decrement the stats counter + ObservationPtr stat = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(stat); + EXPECT_EQ(1, stat->getInteger().first); + // CASE 2: Lease is known and belongs to this client, but to a different IAID SCOPED_TRACE("CASE 2: Lease is known and belongs to this client, but to a different IAID"); @@ -713,6 +737,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) { l = LeaseMgrFactory::instance().getLease6(type, addr); ASSERT_TRUE(l); + // Verify we didn't decrement the stats counter + EXPECT_EQ(1, stat->getInteger().first); + // CASE 3: Lease belongs to a client with different client-id SCOPED_TRACE("CASE 3: Lease belongs to a client with different client-id"); @@ -737,6 +764,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) { l = LeaseMgrFactory::instance().getLease6(type, addr); ASSERT_TRUE(l); + // Verify we didn't decrement the stats counter + EXPECT_EQ(1, stat->getInteger().first); + // Finally, let's cleanup the database EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); } diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index d441a2c4ba..9103bc78a5 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -1038,12 +1038,15 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx, bool status = LeaseMgrFactory::instance().addLease(lease); if (status) { - // The lease insertion succeeded, let's bump up the statistic. - StatsMgr::instance().addValue( - StatsMgr::generateName("subnet", ctx.subnet_->getID(), - ctx.type_ == Lease::TYPE_NA ? "assigned-NAs" : - "assigned-PDs"), - static_cast(1)); + // The lease insertion succeeded - if the lease is in the + // current subnet lets bump up the statistic. + if (ctx.subnet_->inPool(ctx.type_, addr)) { + StatsMgr::instance().addValue( + StatsMgr::generateName("subnet", ctx.subnet_->getID(), + ctx.type_ == Lease::TYPE_NA ? "assigned-NAs" : + "assigned-PDs"), + static_cast(1)); + } return (lease); } else { diff --git a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc index c0c8fb64e2..42a875101f 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc @@ -53,59 +53,51 @@ TEST_F(AllocEngine6Test, constructor) { } // This test checks if the simple allocation (REQUEST) can succeed +// and the stats counter is properly bumped by 1 TEST_F(AllocEngine6Test, simpleAlloc6) { - // Pretend our pool has allocated 100 addresses - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); - StatsMgr::instance().addValue(name, static_cast(100)); - simpleAlloc6Test(pool_, IOAddress("::"), false); // We should have bumped the address counter by 1 + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(101, stat->getInteger().first); } // This test checks if the simple PD allocation (REQUEST) can succeed +// and the stats counter is properly bumped by 1 TEST_F(AllocEngine6Test, pdSimpleAlloc6) { - // Pretend our pool has allocated 100 prefixes - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"); - StatsMgr::instance().addValue(name, static_cast(100)); - simpleAlloc6Test(pd_pool_, IOAddress("::"), false); // We should have bumped the address counter by 1 + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"); ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(101, stat->getInteger().first); } // This test checks if the fake allocation (for SOLICIT) can succeed +// and the stats counter isn't bumped TEST_F(AllocEngine6Test, fakeAlloc6) { - // Pretend our pool has allocated 100 prefixes - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); - StatsMgr::instance().addValue(name, static_cast(100)); - simpleAlloc6Test(pool_, IOAddress("::"), true); // We should not have bumped the address counter + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(100, stat->getInteger().first); } // This test checks if the fake PD allocation (for SOLICIT) can succeed +// and the stats counter isn't bumped TEST_F(AllocEngine6Test, pdFakeAlloc6) { - // Pretend our pool has allocated 100 prefixes - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"); - StatsMgr::instance().addValue(name, static_cast(100)); - simpleAlloc6Test(pd_pool_, IOAddress("::"), true); // We should not have bumped the address counter + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"); ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(100, stat->getInteger().first); @@ -566,6 +558,10 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) { lease->hostname_ = "myhost.example.com."; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); + // By default we pretend our subnet has 100 addresses + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); + StatsMgr::instance().setValue(name, static_cast(100)); + // A client comes along, asking specifically for this address AllocEngine::ClientContext6 ctx(subnet_, duid_, iaid_, addr, Lease::TYPE_NA, false, false, "", false); @@ -596,6 +592,13 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) { // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); + + // We should not have bumped the address counter + // NOTE: when we start expiring addresses and removing them from + // the stats this will no longer be true. + ObservationPtr stat = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(stat); + EXPECT_EQ(100, stat->getInteger().first); } // --- v6 host reservation --- @@ -639,9 +642,9 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestNoHint) { AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); - // Pretend our pool has allocated 100 addresses + // By default we pretend our subnet has 100 addresses string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); - StatsMgr::instance().addValue(name, static_cast(100)); + StatsMgr::instance().setValue(name, static_cast(100)); Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false); ASSERT_TRUE(lease); @@ -757,7 +760,7 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolRequestMatchingHint) { // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. -// - Client has an in-pool reservation. +// - Client has an out-of-pool reservation. // - Client sends SOLICIT without any hints. // - Client is allocated a reserved address. // @@ -773,13 +776,14 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitNoHint) { Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), true, false); ASSERT_TRUE(lease); EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); + } -// Checks that a client gets the address reserved (in-pool case) +// Checks that a client gets the address reserved (out-of-pool case) // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. -// - Client has an in-pool reservation. +// - Client has an out-of-pool reservation. // - Client sends REQUEST without any hints. // - Client is allocated a reserved address. // @@ -792,9 +796,18 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestNoHint) { AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); + // By default we pretend our subnet has 100 addresses + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); + StatsMgr::instance().setValue(name, static_cast(100)); + Lease6Ptr lease = simpleAlloc6Test(pool_, IOAddress("::"), false, false); ASSERT_TRUE(lease); EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); + + // We should not have bumped the address counter + ObservationPtr stat = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(stat); + EXPECT_EQ(100, stat->getInteger().first); } // Checks that a client gets the address reserved (in-pool case) @@ -822,11 +835,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitValidHint) { EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); } -// Checks that a client gets the address reserved (in-pool case) +// Checks that a client gets the address reserved (out-of-pool case) // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. -// - Client has an in-pool reservation. +// - Client has an out-of-pool reservation. // - Client sends REQUEST with a hint that does not match reservation // - Client is allocated a reserved address, not the hint. // @@ -847,11 +860,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestValidHint) { EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); } -// Checks that a client gets the address reserved (in-pool case) +// Checks that a client gets the address reserved (out-of-pool case) // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. -// - Client has an in-pool reservation. +// - Client has an out-of-pool reservation. // - Client sends SOLICIT with a hint that does matches reservation // - Client is allocated a reserved address, not the hint. // @@ -872,11 +885,11 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolSolicitMatchingHint) { EXPECT_EQ("2001:db8::abcd", lease->addr_.toText()); } -// Checks that a client gets the address reserved (in-pool case) +// Checks that a client gets the address reserved (out-of-pool case) // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. -// - Client has an in-pool reservation. +// - Client has an out-of-pool reservation. // - Client sends REQUEST with a hint that does not match reservation // - Client is allocated a reserved address, not the hint. // @@ -903,18 +916,16 @@ TEST_F(AllocEngine6Test, reservedAddressOutOfPoolRequestMatchingHint) { // - client tries to get address A: // Check that his existing lease for lease A is removed // Check that he is assigned a new lease for B +// - verify that the number of assigned address behaves as expected TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) { AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); - // Pretend our pool has allocated 100 addresses - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); - StatsMgr::instance().addValue(name, static_cast(100)); - // Client gets an address Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false); ASSERT_TRUE(lease1); // We should have bumped the address counter + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(101, stat->getInteger().first); @@ -959,9 +970,7 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedThis) { // Lastly check to see that the address counter is still 101 we should have // have decremented it on the implied release and incremented it on the reserved EXPECT_EQ(101, stat->getInteger().first); - } - // In the following situation: // - client X is assigned an address A // - HR is made for client Y (*other* client) to get A @@ -975,12 +984,21 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) { Lease6Ptr lease1 = simpleAlloc6Test(pool_, IOAddress("::"), false); ASSERT_TRUE(lease1); + // We should have bumped the address counter + string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); + ObservationPtr stat = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(stat); + EXPECT_EQ(101, stat->getInteger().first); + // Just check that if the client requests again, it will get the same // address. Lease6Ptr lease2 = simpleAlloc6Test(pool_, lease1->addr_, false); ASSERT_TRUE(lease2); detailCompareLease(lease1, lease2); + // We should not have bumped the address counter again + EXPECT_EQ(101, stat->getInteger().first); + // Now admin creates a reservation for this client. Let's use the // address client X just received. Let's generate a host, but don't add it // to the HostMgr yet. @@ -1014,6 +1032,10 @@ TEST_F(AllocEngine6Test, reservedAddressInPoolReassignedOther) { // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease3, from_mgr); + + // Lastly check to see that the address counter is still 101 we should have + // have decremented it on the implied release and incremented it on the reserved + EXPECT_EQ(101, stat->getInteger().first); } // Checks that a reserved address for client A is not assigned when @@ -1430,30 +1452,6 @@ TEST_F(AllocEngine6Test, reservedAddressByMacInPoolRequestValidHint) { } -// This test checks that NULL values are handled properly -TEST_F(AllocEngine6Test, allocateAddress6Stats) { - boost::scoped_ptr engine; - ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100))); - ASSERT_TRUE(engine); - - // Verify our pool hasn't allocated any addresses - string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"); - StatsMgr::instance().addValue(name, static_cast(100)); - - Lease6Ptr lease; - AllocEngine::ClientContext6 ctx1(subnet_, duid_, iaid_, IOAddress("::"), - Lease::TYPE_NA, false, false, "", false); - ctx1.query_.reset(new Pkt6(DHCPV6_REQUEST, 1234)); - EXPECT_NO_THROW(lease = expectOneLease(engine->allocateLeases6(ctx1))); - ASSERT_TRUE(lease); - - // We should have bumped the address counter by 1 - ObservationPtr stat = StatsMgr::instance().getObservation(name); - ASSERT_TRUE(stat); - EXPECT_EQ(101, stat->getInteger().first); -} - - }; // namespace test }; // namespace dhcp }; // namespace isc diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc index d6246dd64a..5321da12e2 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ using namespace std; using namespace isc::hooks; using namespace isc::asiolink; +using namespace isc::stats; namespace isc { namespace dhcp { @@ -82,6 +84,14 @@ AllocEngine6Test::initSubnet(const asiolink::IOAddress& subnet, cfg_mgr.getStagingCfg()->getCfgSubnets6()->add(subnet_); cfg_mgr.commit(); + + // By default we pretend our subnet has 100 addresses and prefixes allocated. + StatsMgr::instance().setValue( + StatsMgr::generateName("subnet", subnet_->getID(), "assigned-NAs"), + static_cast(100)); + StatsMgr::instance().setValue( + StatsMgr::generateName("subnet", subnet_->getID(), "assigned-PDs"), + static_cast(100)); } void diff --git a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc index c43ea6cf71..cf4949a422 100644 --- a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc @@ -583,7 +583,7 @@ TEST_F(CfgMgrTest, commitStats4) { StatsMgr& stats_mgr = StatsMgr::instance(); // Let's prepare the "old" configuration: a subnet with id 123 - // and pretend there ware addresses assigned, so statistics are non-zero. + // and pretend there were addresses assigned, so statistics are non-zero. Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123)); CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4(); subnets->add(subnet1); @@ -622,7 +622,7 @@ TEST_F(CfgMgrTest, clearStats4) { StatsMgr& stats_mgr = StatsMgr::instance(); // Let's prepare the "old" configuration: a subnet with id 123 - // and pretend there ware addresses assigned, so statistics are non-zero. + // and pretend there were addresses assigned, so statistics are non-zero. Subnet4Ptr subnet1(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3, 123)); CfgSubnets4Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4(); subnets->add(subnet1); @@ -649,7 +649,7 @@ TEST_F(CfgMgrTest, commitStats6) { StatsMgr& stats_mgr = StatsMgr::instance(); // Let's prepare the "old" configuration: a subnet with id 123 - // and pretend there ware addresses assigned, so statistics are non-zero. + // and pretend there were addresses assigned, so statistics are non-zero. Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123)); CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6(); subnets->add(subnet1); @@ -700,7 +700,7 @@ TEST_F(CfgMgrTest, clearStats6) { StatsMgr& stats_mgr = StatsMgr::instance(); // Let's prepare the "old" configuration: a subnet with id 123 - // and pretend there ware addresses assigned, so statistics are non-zero. + // and pretend there were addresses assigned, so statistics are non-zero. Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4, 123)); CfgSubnets6Ptr subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6(); subnets->add(subnet1);