|
@@ -50,21 +50,18 @@ public:
|
|
|
// 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() {
|
|
|
+ /// @brief Reopens the connection to the backend.
|
|
|
+ ///
|
|
|
+ /// This function is called by unit tests to force reconnection of the
|
|
|
+ /// backend to check that the leases are stored and can be retrieved
|
|
|
+ /// from the storage.
|
|
|
+ ///
|
|
|
+ /// @param u Universe (V4 or V6)
|
|
|
+ virtual void reopen(Universe u) {
|
|
|
LeaseMgrFactory::destroy();
|
|
|
- LeaseMgrFactory::create(getConfigString());
|
|
|
- lmptr_ = &(LeaseMgrFactory::instance());
|
|
|
+ startBackend(u);
|
|
|
}
|
|
|
|
|
|
/// @brief destructor
|
|
@@ -92,14 +89,32 @@ public:
|
|
|
/// backend and use leasefile4_0.csv and leasefile6_0.csv files as
|
|
|
/// storage for leases.
|
|
|
///
|
|
|
+ /// @param no_universe Indicates whether universe parameter should be
|
|
|
+ /// included (false), or not (true).
|
|
|
+ ///
|
|
|
/// @return Configuration string for @c LeaseMgrFactory.
|
|
|
- static std::string getConfigString() {
|
|
|
+ static std::string getConfigString(Universe u) {
|
|
|
std::ostringstream s;
|
|
|
- s << "type=memfile leasefile4=" << getLeaseFilePath("leasefile4_0.csv")
|
|
|
- << " leasefile6=" << getLeaseFilePath("leasefile6_0.csv");
|
|
|
+ s << "type=memfile " << (u == V4 ? "universe=4 " : "universe=6 ")
|
|
|
+ << "leasefile="
|
|
|
+ << getLeaseFilePath(u == V4 ? "leasefile4_0.csv" : "leasefile6_0.csv");
|
|
|
return (s.str());
|
|
|
}
|
|
|
|
|
|
+ /// @brief Creates instance of the backend.
|
|
|
+ ///
|
|
|
+ /// @param u Universe (v4 or V6).
|
|
|
+ void startBackend(Universe u) {
|
|
|
+ try {
|
|
|
+ LeaseMgrFactory::create(getConfigString(u));
|
|
|
+ } catch (...) {
|
|
|
+ std::cerr << "*** ERROR: unable to create instance of the Memfile\n"
|
|
|
+ " lease database backend.\n";
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ lmptr_ = &(LeaseMgrFactory::instance());
|
|
|
+ }
|
|
|
+
|
|
|
/// @brief Object providing access to v4 lease IO.
|
|
|
LeaseFileIO io4_;
|
|
|
|
|
@@ -111,37 +126,27 @@ public:
|
|
|
// This test checks if the LeaseMgr can be instantiated and that it
|
|
|
// parses parameters string properly.
|
|
|
TEST_F(MemfileLeaseMgrTest, constructor) {
|
|
|
-
|
|
|
LeaseMgr::ParameterMap pmap;
|
|
|
- pmap["persist4"] = "no";
|
|
|
- pmap["persist6"] = "no";
|
|
|
+ pmap["universe"] = "4";
|
|
|
+ pmap["persist"] = "false";
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr;
|
|
|
|
|
|
EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
|
|
|
|
|
|
- pmap["persist4"] = "yes";
|
|
|
- pmap["persist6"] = "yes";
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
+ pmap["persist"] = "true";
|
|
|
+ pmap["leasefile"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
|
|
|
|
|
|
// Expecting that persist parameter is yes or no. Everything other than
|
|
|
// that is wrong.
|
|
|
- pmap["persist4"] = "bogus";
|
|
|
- pmap["persist6"] = "yes";
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
- EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
|
|
|
-
|
|
|
- pmap["persist4"] = "yes";
|
|
|
- pmap["persist6"] = "bogus";
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
+ pmap["persist"] = "bogus";
|
|
|
+ pmap["leasefile"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
|
|
|
}
|
|
|
|
|
|
// Checks if the getType() and getName() methods both return "memfile".
|
|
|
TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
|
|
|
+ startBackend(V4);
|
|
|
EXPECT_EQ(std::string("memfile"), lmptr_->getType());
|
|
|
EXPECT_EQ(std::string("memory"), lmptr_->getName());
|
|
|
}
|
|
@@ -154,24 +159,21 @@ TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) {
|
|
|
LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
|
|
|
|
|
|
LeaseMgr::ParameterMap pmap;
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
+ pmap["universe"] = "4";
|
|
|
+ pmap["leasefile"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
|
|
|
- EXPECT_EQ(pmap["leasefile4"],
|
|
|
+ EXPECT_EQ(pmap["leasefile"],
|
|
|
lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V4));
|
|
|
- EXPECT_EQ(pmap["leasefile6"],
|
|
|
- lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6));
|
|
|
|
|
|
- pmap["persist4"] = "no";
|
|
|
- pmap["persist6"] = "no";
|
|
|
+ pmap["persist"] = "false";
|
|
|
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());
|
|
|
}
|
|
|
|
|
|
// Check if the persitLeases correctly checks that leases should not be written
|
|
|
-// to disk when lease file is set to empty value.
|
|
|
+// to disk when disabled through configuration.
|
|
|
TEST_F(MemfileLeaseMgrTest, persistLeases) {
|
|
|
// Initialize IO objects, so as the test csv files get removed after the
|
|
|
// test (when destructors are called).
|
|
@@ -179,17 +181,23 @@ TEST_F(MemfileLeaseMgrTest, persistLeases) {
|
|
|
LeaseFileIO io6(getLeaseFilePath("leasefile6_1.csv"));
|
|
|
|
|
|
LeaseMgr::ParameterMap pmap;
|
|
|
+ pmap["universe"] = "4";
|
|
|
// Specify the names of the lease files. Leases will be written.
|
|
|
- pmap["leasefile4"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
- pmap["leasefile6"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
+ pmap["leasefile"] = getLeaseFilePath("leasefile4_1.csv");
|
|
|
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr(new Memfile_LeaseMgr(pmap));
|
|
|
|
|
|
lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
|
|
|
+ EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
|
|
|
+
|
|
|
+ pmap["universe"] = "6";
|
|
|
+ pmap["leasefile"] = getLeaseFilePath("leasefile6_1.csv");
|
|
|
+ lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
+ EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
|
|
|
EXPECT_TRUE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
|
|
|
|
|
|
// This should disable writes of leases to disk.
|
|
|
- pmap["persist"] = "no";
|
|
|
+ pmap["persist"] = "false";
|
|
|
lease_mgr.reset(new Memfile_LeaseMgr(pmap));
|
|
|
EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V4));
|
|
|
EXPECT_FALSE(lease_mgr->persistLeases(Memfile_LeaseMgr::V6));
|
|
@@ -198,6 +206,7 @@ TEST_F(MemfileLeaseMgrTest, persistLeases) {
|
|
|
|
|
|
// Checks that adding/getting/deleting a Lease6 object works.
|
|
|
TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
|
|
|
+ startBackend(V6);
|
|
|
testAddGetDelete6(true); // true - check T1,T2 values
|
|
|
// memfile is able to preserve those values, but some other
|
|
|
// backends can't do that.
|
|
@@ -208,6 +217,7 @@ TEST_F(MemfileLeaseMgrTest, addGetDelete6) {
|
|
|
/// Checks that the addLease, getLease4 (by address) and deleteLease (with an
|
|
|
/// IPv4 address) works.
|
|
|
TEST_F(MemfileLeaseMgrTest, basicLease4) {
|
|
|
+ startBackend(V4);
|
|
|
testBasicLease4();
|
|
|
}
|
|
|
|
|
@@ -215,16 +225,19 @@ TEST_F(MemfileLeaseMgrTest, basicLease4) {
|
|
|
|
|
|
// Simple test about lease4 retrieval through client id method
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientId) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4ClientId();
|
|
|
}
|
|
|
|
|
|
// Checks that lease4 retrieval client id is null is working
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4NullClientId();
|
|
|
}
|
|
|
|
|
|
// Checks lease4 retrieval through HWAddr
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4HWAddr1();
|
|
|
}
|
|
|
|
|
@@ -233,11 +246,13 @@ TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) {
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
/// a combination of DUID and IAID.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr2) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4HWAddr2();
|
|
|
}
|
|
|
|
|
|
// Checks lease4 retrieval with clientId, HWAddr and subnet_id
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4ClientIdHWAddrSubnetId();
|
|
|
}
|
|
|
|
|
@@ -247,6 +262,7 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
|
|
|
/// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
|
|
|
/// (client-id is optional and may not be present)
|
|
|
TEST_F(MemfileLeaseMgrTest, lease4NullClientId) {
|
|
|
+ startBackend(V4);
|
|
|
testLease4NullClientId();
|
|
|
}
|
|
|
|
|
@@ -257,6 +273,7 @@ TEST_F(MemfileLeaseMgrTest, lease4NullClientId) {
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_getLease4HwaddrSubnetId) {
|
|
|
|
|
|
/// @todo: fails on memfile. It's probably a memfile bug.
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4HWAddrSubnetId();
|
|
|
}
|
|
|
|
|
@@ -265,6 +282,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_getLease4HwaddrSubnetId) {
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
/// the Client ID.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientId2) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4ClientId2();
|
|
|
}
|
|
|
|
|
@@ -272,6 +290,7 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientId2) {
|
|
|
//
|
|
|
// Check that the system can cope with a client ID of any size.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSize) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4ClientIdSize();
|
|
|
}
|
|
|
|
|
@@ -280,6 +299,7 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSize) {
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
/// a combination of client and subnet IDs.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSubnetId) {
|
|
|
+ startBackend(V4);
|
|
|
testGetLease4ClientIdSubnetId();
|
|
|
}
|
|
|
|
|
@@ -288,6 +308,7 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdSubnetId) {
|
|
|
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
|
|
|
/// IPv6 address) works.
|
|
|
TEST_F(MemfileLeaseMgrTest, basicLease6) {
|
|
|
+ startBackend(V6);
|
|
|
testBasicLease6();
|
|
|
}
|
|
|
|
|
@@ -299,6 +320,7 @@ TEST_F(MemfileLeaseMgrTest, basicLease6) {
|
|
|
/// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
|
|
|
/// const DUID& duid, uint32_t iaid) const is not implemented yet.
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidIaid) {
|
|
|
+ startBackend(V6);
|
|
|
testGetLeases6DuidIaid();
|
|
|
}
|
|
|
|
|
@@ -307,6 +329,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidIaid) {
|
|
|
/// @todo: test disabled, because Memfile_LeaseMgr::getLeases6(Lease::Type,
|
|
|
/// const DUID& duid, uint32_t iaid) const is not implemented yet.
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidSize) {
|
|
|
+ startBackend(V6);
|
|
|
testGetLeases6DuidSize();
|
|
|
}
|
|
|
|
|
@@ -319,6 +342,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_getLeases6DuidSize) {
|
|
|
/// @todo: Disabled, because type parameter in Memfile_LeaseMgr::getLease6
|
|
|
/// (Lease::Type, const isc::asiolink::IOAddress& addr) const is not used.
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_lease6LeaseTypeCheck) {
|
|
|
+ startBackend(V6);
|
|
|
testLease6LeaseTypeCheck();
|
|
|
}
|
|
|
|
|
@@ -327,12 +351,14 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_lease6LeaseTypeCheck) {
|
|
|
/// Adds leases to the database and checks that they can be accessed via
|
|
|
/// a combination of DIUID and IAID.
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease6DuidIaidSubnetId) {
|
|
|
+ startBackend(V6);
|
|
|
testGetLease6DuidIaidSubnetId();
|
|
|
}
|
|
|
|
|
|
/// Checks that getLease6(type, duid, iaid, subnet-id) works with different
|
|
|
/// DUID sizes
|
|
|
TEST_F(MemfileLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
|
|
|
+ startBackend(V6);
|
|
|
testGetLease6DuidIaidSubnetIdSize();
|
|
|
}
|
|
|
|
|
@@ -343,6 +369,7 @@ TEST_F(MemfileLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
|
|
|
/// We should reconsider if lease{4,6} structures should have a limit
|
|
|
/// implemented in them.
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease4) {
|
|
|
+ startBackend(V4);
|
|
|
testUpdateLease4();
|
|
|
}
|
|
|
|
|
@@ -353,6 +380,7 @@ TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease4) {
|
|
|
/// We should reconsider if lease{4,6} structures should have a limit
|
|
|
/// implemented in them.
|
|
|
TEST_F(MemfileLeaseMgrTest, DISABLED_updateLease6) {
|
|
|
+ startBackend(V6);
|
|
|
testUpdateLease6();
|
|
|
}
|
|
|
|