|
@@ -18,7 +18,9 @@
|
|
|
#include <dhcp/duid.h>
|
|
|
#include <dhcpsrv/cfgmgr.h>
|
|
|
#include <dhcpsrv/lease_mgr.h>
|
|
|
+#include <dhcpsrv/lease_mgr_factory.h>
|
|
|
#include <dhcpsrv/memfile_lease_mgr.h>
|
|
|
+#include <dhcpsrv/tests/lease_file_io.h>
|
|
|
#include <dhcpsrv/tests/test_utils.h>
|
|
|
#include <dhcpsrv/tests/generic_lease_mgr_unittest.h>
|
|
|
#include <gtest/gtest.h>
|
|
@@ -33,6 +35,7 @@ using namespace isc::dhcp;
|
|
|
using namespace isc::dhcp::test;
|
|
|
|
|
|
namespace {
|
|
|
+
|
|
|
// empty class for now, but may be extended once Addr6 becomes bigger
|
|
|
class MemfileLeaseMgrTest : public GenericLeaseMgrTest {
|
|
|
public:
|
|
@@ -40,21 +43,35 @@ public:
|
|
|
/// @brief memfile lease mgr test constructor
|
|
|
///
|
|
|
/// Creates memfile and stores it in lmptr_ pointer
|
|
|
- MemfileLeaseMgrTest() {
|
|
|
- const LeaseMgr::ParameterMap pmap;
|
|
|
- lmptr_ = new Memfile_LeaseMgr(pmap);
|
|
|
+ MemfileLeaseMgrTest() :
|
|
|
+ io4_(getLeaseFilePath("leasefile4_0.csv")),
|
|
|
+ io6_(getLeaseFilePath("leasefile6_0.csv")) {
|
|
|
+
|
|
|
+ // Make sure there are no dangling files after previous tests.
|
|
|
+ io4_.removeFile();
|
|
|
+ io6_.removeFile();
|
|
|
+
|
|
|
+ try {
|
|
|
+ LeaseMgrFactory::create(getConfigString());
|
|
|
+ } catch (...) {
|
|
|
+ std::cerr << "*** ERROR: unable to create instance of the Memfile\n"
|
|
|
+ " lease database backend.\n";
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ lmptr_ = &(LeaseMgrFactory::instance());
|
|
|
}
|
|
|
|
|
|
virtual void reopen() {
|
|
|
- /// @todo: write lease to disk, flush, read file from disk
|
|
|
+ LeaseMgrFactory::destroy();
|
|
|
+ LeaseMgrFactory::create(getConfigString());
|
|
|
+ lmptr_ = &(LeaseMgrFactory::instance());
|
|
|
}
|
|
|
|
|
|
/// @brief destructor
|
|
|
///
|
|
|
/// destroys lease manager backend.
|
|
|
virtual ~MemfileLeaseMgrTest() {
|
|
|
- delete lmptr_;
|
|
|
- lmptr_ = 0;
|
|
|
+ LeaseMgrFactory::destroy();
|
|
|
}
|
|
|
|
|
|
/// @brief Return path to the lease file used by unit tests.
|
|
@@ -63,19 +80,41 @@ public:
|
|
|
/// directory where test data is held.
|
|
|
///
|
|
|
/// @return Full path to the lease file.
|
|
|
- std::string getLeaseFilePath(const std::string& filename) const {
|
|
|
+ static std::string getLeaseFilePath(const std::string& filename) {
|
|
|
std::ostringstream s;
|
|
|
s << TEST_DATA_BUILDDIR << "/" << filename;
|
|
|
return (s.str());
|
|
|
}
|
|
|
|
|
|
+ /// @brief Returns the configuration string for the backend.
|
|
|
+ ///
|
|
|
+ /// This string configures the @c LeaseMgrFactory to create the memfile
|
|
|
+ /// backend and use leasefile4_0.csv and leasefile6_0.csv files as
|
|
|
+ /// storage for leases.
|
|
|
+ ///
|
|
|
+ /// @return Configuration string for @c LeaseMgrFactory.
|
|
|
+ static std::string getConfigString() {
|
|
|
+ std::ostringstream s;
|
|
|
+ s << "type=memfile leasefile4=" << getLeaseFilePath("leasefile4_0.csv")
|
|
|
+ << " leasefile6=" << getLeaseFilePath("leasefile6_0.csv");
|
|
|
+ return (s.str());
|
|
|
+ }
|
|
|
+
|
|
|
+ /// @brief Object providing access to v4 lease IO.
|
|
|
+ LeaseFileIO io4_;
|
|
|
+
|
|
|
+ /// @brief Object providing access to v6 lease IO.
|
|
|
+ LeaseFileIO io6_;
|
|
|
+
|
|
|
};
|
|
|
|
|
|
// This test checks if the LeaseMgr can be instantiated and that it
|
|
|
// parses parameters string properly.
|
|
|
TEST_F(MemfileLeaseMgrTest, constructor) {
|
|
|
|
|
|
- const LeaseMgr::ParameterMap pmap; // Empty parameter map
|
|
|
+ LeaseMgr::ParameterMap pmap;
|
|
|
+ pmap["leasefile4"] = "";
|
|
|
+ pmap["leasefile6"] = "";
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr;
|
|
|
|
|
|
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
|
|
@@ -89,53 +128,42 @@ TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
|
|
|
|
|
|
// Checks if the path to the lease files is initialized correctly.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) {
|
|
|
+ // Initialize IO objects, so as the test csv files get removed after the
|
|
|
+ // test (when destructors are called).
|
|
|
+ LeaseFileIO io4(getLeaseFilePath("leasefile4_1.csv"));
|
|
|
+ LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
|
|
|
+
|
|
|
LeaseMgr::ParameterMap pmap;
|
|
|
+ pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
+ pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
|
|
|
- std::ostringstream s4;
|
|
|
- s4 << CfgMgr::instance().getDataDir() << "/" << "kea-leases4.csv";
|
|
|
- std::ostringstream s6;
|
|
|
- s6 << CfgMgr::instance().getDataDir() << "/" << "kea-leases6.csv";
|
|
|
- EXPECT_EQ(s4.str(),
|
|
|
- lease_mgr->getDefaultLeaseFilePath(Memfile_LeaseMgr::V4));
|
|
|
- EXPECT_EQ(s6.str(),
|
|
|
- lease_mgr->getDefaultLeaseFilePath(Memfile_LeaseMgr::V6));
|
|
|
-
|
|
|
-
|
|
|
- EXPECT_EQ(lease_mgr->getDefaultLeaseFilePath(Memfile_LeaseMgr::V4),
|
|
|
- lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4));
|
|
|
-
|
|
|
- EXPECT_EQ(lease_mgr->getDefaultLeaseFilePath(Memfile_LeaseMgr::V6),
|
|
|
- lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6));
|
|
|
-
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4.csv");
|
|
|
- lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
EXPECT_EQ(pmap["leasefile4"],
|
|
|
lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4));
|
|
|
- EXPECT_EQ(lease_mgr->getDefaultLeaseFilePath(Memfile_LeaseMgr::V6),
|
|
|
+ EXPECT_EQ(pmap["leasefile6"],
|
|
|
lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6));
|
|
|
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("kea-leases6.csv");
|
|
|
+ pmap["leasefile4"] = "";
|
|
|
+ pmap["leasefile6"] = "";
|
|
|
lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
- EXPECT_EQ(pmap["leasefile4"],
|
|
|
- lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4));
|
|
|
- EXPECT_EQ(pmap["leasefile6"],
|
|
|
- lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6));
|
|
|
+ EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4).empty());
|
|
|
+ EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6).empty());
|
|
|
}
|
|
|
|
|
|
// Check if the persitLeases correctly checks that leases should not be written
|
|
|
// to disk when lease file is set to empty value.
|
|
|
TEST_F(MemfileLeaseMgrTest, persistLeases) {
|
|
|
+ // Initialize IO objects, so as the test csv files get removed after the
|
|
|
+ // test (when destructors are called).
|
|
|
+ LeaseFileIO io4(getLeaseFilePath("leasefile4_1.csv"));
|
|
|
+ LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
|
|
|
+
|
|
|
LeaseMgr::ParameterMap pmap;
|
|
|
+ // Specify the names of the lease files. Leases will be written.
|
|
|
+ pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
+ pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
- // If the leasefile4 and leasefile6 are not specified, the default
|
|
|
- // file names will be used. The leases will be written to these files.
|
|
|
- EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
|
|
|
- EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
|
|
|
|
|
|
- // Specify the names of the lease files. Leases will be written.
|
|
|
- pmap["leasefile4"] = "leases4.csv";
|
|
|
- pmap["leasefile6"] = "leases6.csv";
|
|
|
lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
|
|
|
EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
|
|
@@ -200,10 +228,7 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
|
|
|
/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
|
|
/// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
|
|
|
/// (client-id is optional and may not be present)
|
|
|
-TEST_F(MemfileLeaseMgrTest, DISABLED_lease4NullClientId) {
|
|
|
-
|
|
|
- /// @todo Test is disabled, because memfile does not support disk storage, so
|
|
|
- /// all leases are lost after reopen()
|
|
|
+TEST_F(MemfileLeaseMgrTest, lease4NullClientId) {
|
|
|
testLease4NullClientId();
|
|
|
}
|
|
|
|
|
@@ -240,6 +265,15 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSubnetId) {
|
|
|
testGetLease4ClientIdSubnetId();
|
|
|
}
|
|
|
|
|
|
+/// @brief Basic Lease6 Checks
|
|
|
+///
|
|
|
+/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
|
|
|
+/// IPv6 address) works.
|
|
|
+TEST_F(MemfileLeaseMgrTest, basicLease6) {
|
|
|
+ testBasicLease6();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/// @brief Check GetLease6 methods - access by DUID/IAID
|
|
|
///
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
@@ -304,6 +338,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease6) {
|
|
|
testUpdateLease6();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// The following tests are not applicable for memfile. When adding
|
|
|
// new tests to the list here, make sure to provide brief explanation
|
|
|
// why they are not applicable:
|