Commit f056c2a7 authored by Marcin Siodelski's avatar Marcin Siodelski

[3360] Memfile db access string uses persist parameter to disable writes.

parent e90a1c9c
......@@ -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 {
......
......@@ -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<CSVLeaseFile6> lease_file6_;
};
}; // end of isc::dhcp namespace
......
......@@ -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
......
......@@ -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());
......
......@@ -113,8 +113,7 @@ public:
TEST_F(MemfileLeaseMgrTest, constructor) {
LeaseMgr::ParameterMap pmap;
pmap["leasefile4"] = "";
pmap["leasefile6"] = "";
pmap["persist"] = "no";
boost::scoped_ptr<Memfile_LeaseMgr> 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));
......
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