mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 15:05:16 +00:00
[#1654] Checkpoint: UT and hook to do
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2012-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
|
||||
|
@@ -829,7 +829,8 @@ public:
|
||||
/// or equal to this value will be included
|
||||
///
|
||||
/// @return collection of IPv4 leases
|
||||
virtual Lease4Collection getLeases4ByRelayId(const OptionBuffer& relay_id,
|
||||
virtual Lease4Collection
|
||||
getLeases4ByRelayId(const OptionBuffer& relay_id,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size,
|
||||
const time_t& qry_start_time = 0,
|
||||
@@ -847,7 +848,8 @@ public:
|
||||
/// or equal to this value will be included. Defaults to zero.
|
||||
///
|
||||
/// @return collection of IPv4 leases
|
||||
virtual Lease4Collection getLeases4ByRemoteId(const OptionBuffer& remote_id,
|
||||
virtual Lease4Collection
|
||||
getLeases4ByRemoteId(const OptionBuffer& remote_id,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size,
|
||||
const time_t& qry_start_time = 0,
|
||||
@@ -862,7 +864,8 @@ public:
|
||||
/// @param page_size maximum size of the page returned.
|
||||
///
|
||||
/// @return collection of IPv6 leases
|
||||
virtual Lease6Collection getLeases6ByRelayId(const DUID& relay_id,
|
||||
virtual Lease6Collection
|
||||
getLeases6ByRelayId(const DUID& relay_id,
|
||||
const asiolink::IOAddress& link_addr,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size) = 0;
|
||||
@@ -876,7 +879,8 @@ public:
|
||||
/// @param page_size maximum size of the page returned.
|
||||
///
|
||||
/// @return collection of IPv6 leases
|
||||
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer& remote_id,
|
||||
virtual Lease6Collection
|
||||
getLeases6ByRemoteId(const OptionBuffer& remote_id,
|
||||
const asiolink::IOAddress& link_addr,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size) = 0;
|
||||
@@ -889,10 +893,21 @@ public:
|
||||
/// @param page_size maximum size of the page returned.
|
||||
///
|
||||
/// @return collection of IPv6 leases
|
||||
virtual Lease6Collection getLeases6ByLink(const asiolink::IOAddress& link_addr,
|
||||
virtual Lease6Collection
|
||||
getLeases6ByLink(const asiolink::IOAddress& link_addr,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size) = 0;
|
||||
|
||||
/// @brief Write V4 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
virtual void writeLeases4(const std::string& filename) = 0;
|
||||
|
||||
/// @brief Write V6 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
virtual void writeLeases6(const std::string& filename) = 0;
|
||||
|
||||
private:
|
||||
/// The IOService object, used for all ASIO operations.
|
||||
static isc::asiolink::IOServicePtr io_service_;
|
||||
|
@@ -2428,5 +2428,71 @@ Memfile_LeaseMgr::getLeases6ByLink(const IOAddress& /* link_addr */,
|
||||
isc_throw(NotImplemented, "Memfile_LeaseMgr::getLeases6ByLink not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
Memfile_LeaseMgr::writeLeases4(const std::string& filename) {
|
||||
if (MultiThreadingMgr::instance().getMode()) {
|
||||
std::lock_guard<std::mutex> lock(*mutex_);
|
||||
writeLeases4Internal(filename);
|
||||
} else {
|
||||
writeLeases4Internal(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Memfile_LeaseMgr::writeLeases4Internal(const std::string& filename) {
|
||||
if (lease_file4_->getFilename() == filename) {
|
||||
lease_file4_->close();
|
||||
}
|
||||
try {
|
||||
std::ostringstream old;
|
||||
old << filename << ".bak" << getpid();
|
||||
::rename(filename.c_str(), old.str().c_str());
|
||||
CSVLeaseFile4 backup(filename);
|
||||
backup.open();
|
||||
for (const auto& lease : storage4_) {
|
||||
backup.append(*lease);
|
||||
}
|
||||
backup.close();
|
||||
} catch (const std::exception&) {
|
||||
if (lease_file4_->getFilename() == filename) {
|
||||
lease_file4_->open(true);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Memfile_LeaseMgr::writeLeases6(const std::string& filename) {
|
||||
if (MultiThreadingMgr::instance().getMode()) {
|
||||
std::lock_guard<std::mutex> lock(*mutex_);
|
||||
writeLeases6Internal(filename);
|
||||
} else {
|
||||
writeLeases6Internal(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Memfile_LeaseMgr::writeLeases6Internal(const std::string& filename) {
|
||||
if (lease_file6_->getFilename() == filename) {
|
||||
lease_file6_->close();
|
||||
}
|
||||
try {
|
||||
std::ostringstream old;
|
||||
old << filename << ".bak" << getpid();
|
||||
::rename(filename.c_str(), old.str().c_str());
|
||||
CSVLeaseFile6 backup(filename);
|
||||
backup.open();
|
||||
for (const auto& lease : storage6_) {
|
||||
backup.append(*lease);
|
||||
}
|
||||
backup.close();
|
||||
} catch (const std::exception&) {
|
||||
if (lease_file6_->getFilename() == filename) {
|
||||
lease_file6_->open(true);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dhcp
|
||||
} // namespace isc
|
||||
|
@@ -1066,6 +1066,7 @@ private:
|
||||
/// @brief stores IPv6 leases
|
||||
Lease6Storage storage6_;
|
||||
|
||||
protected:
|
||||
/// @brief Holds the pointer to the DHCPv4 lease file IO.
|
||||
boost::shared_ptr<CSVLeaseFile4> lease_file4_;
|
||||
|
||||
@@ -1356,6 +1357,29 @@ public:
|
||||
getLeases6ByLink(const asiolink::IOAddress& link_addr,
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size) override;
|
||||
|
||||
/// @brief Write V4 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
virtual void writeLeases4(const std::string& filename) override;
|
||||
|
||||
/// @brief Write V6 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
virtual void writeLeases6(const std::string& filename) override;
|
||||
|
||||
private:
|
||||
/// @brief Write V4 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
/// Must be called from a thread-safe context.
|
||||
virtual void writeLeases4Internal(const std::string& filename);
|
||||
|
||||
/// @brief Write V6 leases to a file.
|
||||
///
|
||||
/// @param filename File name to write leases.
|
||||
/// Must be called from a thread-safe context.
|
||||
virtual void writeLeases6Internal(const std::string& filename);
|
||||
};
|
||||
|
||||
} // namespace dhcp
|
||||
|
@@ -3210,6 +3210,16 @@ MySqlLeaseMgr::clearClassLeaseCounts() {
|
||||
isc_throw(NotImplemented, "MySqlLeaseMgr::clearClassLeaseCounts() not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
MySqlLeaseMgr::writeLeases4(const std::string&) {
|
||||
isc_throw(NotImplemented, "MySqlLeaseMgr::writeLeases4() not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
MySqlLeaseMgr::writeLeases6(const std::string&) {
|
||||
isc_throw(NotImplemented, "MySqlLeaseMgr::writeLeases6() not implemented");
|
||||
}
|
||||
|
||||
LeaseStatsQueryPtr
|
||||
MySqlLeaseMgr::startLeaseStatsQuery4() {
|
||||
// Get a context
|
||||
|
@@ -997,6 +997,12 @@ private:
|
||||
/// @brief Clears the class-lease count map.
|
||||
virtual void clearClassLeaseCounts() override;
|
||||
|
||||
/// @brief Write V4 leases to a file.
|
||||
virtual void writeLeases4(const std::string& /*filename*/) override;
|
||||
|
||||
/// @brief Write V6 leases to a file.
|
||||
virtual void writeLeases6(const std::string& /*filename*/) override;
|
||||
|
||||
/// @brief Check Error and Throw Exception
|
||||
///
|
||||
/// This method invokes @ref MySqlConnection::checkError.
|
||||
|
@@ -2413,6 +2413,16 @@ PgSqlLeaseMgr::clearClassLeaseCounts() {
|
||||
isc_throw(NotImplemented, "PgSqlLeaseMgr::clearClassLeaseCounts() not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
PgSqlLeaseMgr::writeLeases4(const std::string&) {
|
||||
isc_throw(NotImplemented, "PgSqlLeaseMgr::writeLeases4() not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
PgSqlLeaseMgr::writeLeases6(const std::string&) {
|
||||
isc_throw(NotImplemented, "PgSqlLeaseMgr::writeLeases6() not implemented");
|
||||
}
|
||||
|
||||
LeaseStatsQueryPtr
|
||||
PgSqlLeaseMgr::startLeaseStatsQuery4() {
|
||||
// Get a context
|
||||
|
@@ -1056,6 +1056,12 @@ private:
|
||||
const asiolink::IOAddress& lower_bound_address,
|
||||
const LeasePageSize& page_size) override;
|
||||
|
||||
/// @brief Write V4 leases to a file.
|
||||
virtual void writeLeases4(const std::string& /*filename*/) override;
|
||||
|
||||
/// @brief Write V6 leases to a file.
|
||||
virtual void writeLeases6(const std::string& /*filename*/) override;
|
||||
|
||||
/// @brief Context RAII Allocator.
|
||||
class PgSqlLeaseContextAlloc {
|
||||
public:
|
||||
|
@@ -396,7 +396,6 @@ public:
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::clearClassLeaseCounts() not implemented");
|
||||
}
|
||||
|
||||
|
||||
/// @brief Stub implementation.
|
||||
Lease4Collection
|
||||
getLeases4ByRelayId(const OptionBuffer& /* relay_id */,
|
||||
@@ -441,6 +440,15 @@ public:
|
||||
const IOAddress& /* lower_bound_address */,
|
||||
const LeasePageSize& /* page_size */) override {
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::getLeases6ByLink not implemented");
|
||||
|
||||
/// @brief Pretends to write V4 leases to a file.
|
||||
virtual void writeLeases4(const std::string&) override {
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::writeLeases4() not implemented");
|
||||
}
|
||||
|
||||
/// @brief Pretends to write V6 leases to a file.
|
||||
virtual void writeLeases6(const std::string&) override {
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::writeLeases6() not implemented");
|
||||
}
|
||||
|
||||
/// @brief Returns backend type.
|
||||
|
@@ -2804,4 +2804,20 @@ TEST_F(MemfileLeaseMgrTest, classLeaseRecount6) {
|
||||
EXPECT_EQ(2, memfile_mgr->getClassLeaseCount("slice", Lease::TYPE_PD));
|
||||
}
|
||||
|
||||
/// @brief Class derived from @c Memfile_LeaseMgr to test write to file.
|
||||
class WFMemfileLeaseMgr : public Memfile_LeaseMgr {
|
||||
public:
|
||||
|
||||
/// @brief Constructor.
|
||||
WFMemfileLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
|
||||
: Memfile_LeaseMgr(parameters) {
|
||||
}
|
||||
|
||||
using Memfile_LeaseMgr::lease_file4_;
|
||||
using Memfile_LeaseMgr::lease_file6_;
|
||||
};
|
||||
|
||||
//////// test plan:
|
||||
// bad file, basic, overwrite file, not-persistent x v4/v6
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user