Commit 69b2ca9f authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3798] assigned-addresses statistic handling in Release processing

parent 46081406
......@@ -40,6 +40,7 @@
#include <hooks/callout_handle.h>
#include <hooks/hooks_log.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <util/strutil.h>
#include <asio.hpp>
......@@ -1745,6 +1746,12 @@ Dhcpv4Srv::processRelease(Pkt4Ptr& release) {
.arg(release->getLabel())
.arg(lease->addr_.toText());
// Need to decrease statistic for assigned addresses.
std::stringstream name;
name << "subnet[" << lease->subnet_id_ << "].assigned-addresses";
isc::stats::StatsMgr::instance().addValue(name.str(),
static_cast<uint64_t>(-1));
if (CfgMgr::instance().ddnsEnabled()) {
// Remove existing DNS entries for the lease, if any.
queueNameChangeRequest(isc::dhcp_ddns::CHG_REMOVE, lease);
......
......@@ -29,6 +29,7 @@
#include <dhcpsrv/lease.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <stats/stats_mgr.h>
using namespace std;
using namespace isc::asiolink;
......@@ -40,6 +41,10 @@ namespace test {
Dhcpv4SrvTest::Dhcpv4SrvTest()
:rcode_(-1), srv_(0) {
// Wipe any existing statistics
isc::stats::StatsMgr::instance().removeAll();
subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1000,
2000, 3000));
pool_ = Pool4Ptr(new Pool4(IOAddress("192.0.2.100"), IOAddress("192.0.2.110")));
......@@ -60,6 +65,9 @@ Dhcpv4SrvTest::~Dhcpv4SrvTest() {
// Make sure that we revert to default value
CfgMgr::instance().clear();
CfgMgr::instance().echoClientId(true);
// Wipe any existing statistics
isc::stats::StatsMgr::instance().removeAll();
}
void Dhcpv4SrvTest::addPrlOption(Pkt4Ptr& pkt) {
......
......@@ -21,13 +21,16 @@
#include <dhcpsrv/subnet_id.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/dhcp4_client.h>
#include <stats/stats_mgr.h>
#include <boost/shared_ptr.hpp>
#include <sstream>
using namespace isc;
using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::stats;
namespace {
......@@ -144,6 +147,18 @@ ReleaseTest::acquireAndRelease(const std::string& hw_address_1,
// Perform 4-way exchange to obtain a new lease.
acquireLease(client);
std::stringstream name;
// Let's get the subnet-id and generate statistics name out of it
const Subnet4Collection* subnets =
CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
ASSERT_EQ(1, subnets->size());
name << "subnet[" << subnets->at(0)->getID() << "].assigned-addresses";
ObservationPtr assigned_cnt = StatsMgr::instance().getObservation(name.str());
ASSERT_TRUE(assigned_cnt);
uint64_t before = assigned_cnt->getInteger().first;
// Remember the acquired address.
IOAddress leased_address = client.config_.lease_.addr_;
......@@ -157,14 +172,25 @@ ReleaseTest::acquireAndRelease(const std::string& hw_address_1,
ASSERT_NO_THROW(client.doRelease());
Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(leased_address);
assigned_cnt = StatsMgr::instance().getObservation(name.str());
ASSERT_TRUE(assigned_cnt);
uint64_t after = assigned_cnt->getInteger().first;
// We check if the release process was successful by checking if the
// lease is in the database. It is expected that it is not present,
// i.e. has been deleted with the release.
if (expected_result == SHOULD_PASS) {
EXPECT_FALSE(lease);
// The removal succeded, so the assigned-addresses statistic should
// be decreased by one
EXPECT_EQ(before, after + 1);
} else {
EXPECT_TRUE(lease);
// The removal failed, so the assigned-address should be the same
// as before
EXPECT_EQ(before, after);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment