diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index e070f649b9a2bff82822aeaf977893be57c5a962..03fa124410fb66c043ae3d76b74af65a259dc424 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -415,6 +415,19 @@ Memfile_LeaseMgr::persistLeases(Universe u) const { std::string Memfile_LeaseMgr::initLeaseFilePath(Universe u) { + bool persist = true; + try { + std::string persist_str = getParameter("persist"); + if (persist_str == "no") { + persist = false; + } + } catch (const Exception& ex) { + persist = true; + } + if (!persist) { + return (""); + } + std::string param_name = (u == V4 ? "leasefile4" : "leasefile6"); std::string lease_file; try { diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 497172fa162fb5b2e99ef5da73b1512b6e6698c1..5a512d83cd352f847d57b25b2fe6db6c53787f9e 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -329,8 +329,9 @@ protected: /// initialize the location of the lease file. If the lease file is not /// specified, the method will use the default location for the universe /// (v4 or v6) selected. If the location is specified in the map as empty - /// it will set the empty location, which implies that leases belonging to - /// the specified universe will not be written to disk. + /// or the "persist" parameter is set to "no" it will set the empty + /// location, which implies that leases belonging to the specified universe + /// will not be written to disk. /// /// @param u Universe (v4 or v6) /// @param parameters Map holding parameters of the Lease Manager, passed to @@ -454,6 +455,7 @@ protected: /// @brief Holds the pointer to the DHCPv6 lease file IO. boost::shared_ptr lease_file6_; + }; }; // end of isc::dhcp namespace diff --git a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc index fda31c419d5d0701069282f8e64d801835fadade..47cbec39c1fefe5fd151ddd249c5990a937ba60d 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc @@ -101,7 +101,7 @@ public: initFqdn("", false, false); - factory_.create("type=memfile leasefile4= leasefile6="); + factory_.create("type=memfile persist=no"); } /// @brief Configures a subnet and adds one pool to it. @@ -424,7 +424,7 @@ public: subnet_->addPool(pool_); cfg_mgr.addSubnet4(subnet_); - factory_.create("type=memfile leasefile4= leasefile6="); + factory_.create("type=memfile persist=no"); } /// @brief checks if Lease4 matches expected configuration diff --git a/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc b/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc index b7d1f05a34c31d2678f49ee69106dfea8c53c811..7d1620bef4423252eab32e7c7cbcb33dcd5764bd 100644 --- a/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc @@ -410,9 +410,9 @@ TEST_F(DbAccessParserTest, commit) { }, isc::dhcp::NoLeaseManager); // Set up the parser to open the memfile database. - const char* config[] = {"type", "memfile", "leasefile4", "", - "leasefile6", "", NULL}; + const char* config[] = {"type", "memfile", "persist", "no", NULL}; string json_config = toJson(config); + ConstElementPtr json_elements = Element::fromJSON(json_config); EXPECT_TRUE(json_elements); @@ -420,7 +420,7 @@ TEST_F(DbAccessParserTest, commit) { EXPECT_NO_THROW(parser.build(json_elements)); // Ensure that the access string is as expected. - EXPECT_EQ(std::string("type=memfile"), parser.getDbAccessString()); + EXPECT_EQ(std::string("persist=no type=memfile"), parser.getDbAccessString()); // Committal of the parser changes should open the database. EXPECT_NO_THROW(parser.commit()); diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 3ba8b0af8a6b3c861e18eebcaa58c3b56e06c94d..9e1c02ce44f1cd96274d6876d4b1cf82fdad096b 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -113,8 +113,7 @@ public: TEST_F(MemfileLeaseMgrTest, constructor) { LeaseMgr::ParameterMap pmap; - pmap["leasefile4"] = ""; - pmap["leasefile6"] = ""; + pmap["persist"] = "no"; boost::scoped_ptr lease_mgr; ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); @@ -143,8 +142,7 @@ TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) { EXPECT_EQ(pmap["leasefile6"], lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6)); - pmap["leasefile4"] = ""; - pmap["leasefile6"] = ""; + pmap["persist"] = "no"; lease_mgr.reset(new Memfile_LeaseMgr(pmap)); EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4).empty()); EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6).empty()); @@ -168,10 +166,8 @@ TEST_F(MemfileLeaseMgrTest, persistLeases) { EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4)); EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6)); - // Specify empty names of the lease files. This should disable writes - // of leases to disk. - pmap["leasefile4"] = ""; - pmap["leasefile6"] = ""; + // This should disable writes of leases to disk. + pmap["persist"] = "no"; lease_mgr.reset(new Memfile_LeaseMgr(pmap)); EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4)); EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));