From ead7df0ea6df68507805d763066f5f09e0123f73 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 11 Oct 2022 16:14:48 +0200 Subject: [PATCH] [#2588] Updated code and unit tests --- src/lib/dhcpsrv/alloc_engine.cc | 1 + .../tests/alloc_engine_expiration_unittest.cc | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/dhcpsrv/alloc_engine.cc b/src/lib/dhcpsrv/alloc_engine.cc index 3c868f469d..c77605ba89 100644 --- a/src/lib/dhcpsrv/alloc_engine.cc +++ b/src/lib/dhcpsrv/alloc_engine.cc @@ -3147,6 +3147,7 @@ void AllocEngine::reclaimLeaseInDatabase(const LeasePtrType& lease, lease->fqdn_fwd_ = false; lease->fqdn_rev_ = false; lease->state_ = Lease::STATE_EXPIRED_RECLAIMED; + lease->setContext(ElementPtr()); lease_update_fun(lease); } else { diff --git a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc index c758e476c0..ccb3924679 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -24,6 +24,7 @@ using namespace std; using namespace isc; using namespace isc::asiolink; +using namespace isc::data; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::dhcp_ddns; @@ -426,7 +427,7 @@ public: static bool leaseReclaimed(const LeasePtrType& lease) { return (lease && lease->stateExpiredReclaimed() && lease->hostname_.empty() && !lease->fqdn_fwd_ && - !lease->fqdn_rev_); + !lease->fqdn_rev_ && !lease->getContext()); } /// @brief Lease algorithm checking if lease state is Declined. @@ -1279,7 +1280,11 @@ ExpirationAllocEngine6Test::createLeases() { Lease6Ptr lease(new Lease6(Lease::TYPE_NA, address, duid, 1, 50, 60, SubnetID(1), true, true, generateHostnameForLeaseIndex(i))); + ElementPtr user_context = Element::createMap(); + user_context->set("index", Element::create(static_cast(i))); + lease->setContext(user_context); leases_.push_back(lease); + // Copy the lease before adding it to the lease manager. We want to // make sure that modifications to the leases held in the leases_ // container doesn't affect the leases in the lease manager. @@ -1841,6 +1846,9 @@ ExpirationAllocEngine4Test::createLeases() { Lease4Ptr lease(new Lease4(address, hwaddr, ClientIdPtr(), 60, time(NULL), SubnetID(1), true, true, generateHostnameForLeaseIndex(i))); + ElementPtr user_context = Element::createMap(); + user_context->set("index", Element::create(static_cast(i))); + lease->setContext(user_context); leases_.push_back(lease); // Copy the lease before adding it to the lease manager. We want to // make sure that modifications to the leases held in the leases_ @@ -2320,4 +2328,4 @@ TEST_F(ExpirationAllocEngine4Test, reclaimDeclinedHook2) { testReclaimDeclinedHook(true); // true = use skip callout } -}; // end of anonymous namespace +} // end of anonymous namespace