From: Marcin Siodelski Date: Fri, 9 Jan 2015 20:25:18 +0000 (+0100) Subject: [3671] Memfile loads leases from multiple lease files. X-Git-Tag: trac3504_base~1^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f420169255bf35a8bb873ea3ff064b8ebce71a85;p=thirdparty%2Fkea.git [3671] Memfile loads leases from multiple lease files. --- diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index a2a7956145..31e4dfa982 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -17,8 +17,8 @@ #include #include #include - #include +#include namespace { @@ -479,8 +479,22 @@ void Memfile_LeaseMgr:: loadLeasesFromFiles(const std::string& filename, boost::shared_ptr& lease_file, StorageType& storage) { - lease_file.reset(new LeaseFileType(filename)); - lease_file->open(); storage.clear(); - LeaseFileLoader::load(*lease_file, storage, MAX_LEASE_ERRORS); + + for (int i = 2; i >= 0; --i) { + // Initialize the name of the lease file to parse. For the + // first two loops we're going to append .2 and .1 to the + // lease file name. + std::ostringstream s; + s << filename; + if (i > 0) { + s << "." << i; + } + lease_file.reset(new LeaseFileType(s.str())); + // If the file doesn't exist it will be created as an empty + // file (with no leases). + lease_file->open(); + LeaseFileLoader::load(*lease_file, storage, + MAX_LEASE_ERRORS); + } } diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 76b4cc89a1..2a8471b4e9 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index b04e806432..ba55093572 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -481,4 +481,48 @@ TEST_F(MemfileLeaseMgrTest, versionCheck) { LeaseMgrFactory::destroy(); } +// This test checks that the backend reads lease data from multiple files. +TEST_F(MemfileLeaseMgrTest, loadMultipleLeaseFiles) { + LeaseFileIO io2("leasefile4_0.csv.2"); + io2.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id," + "fqdn_fwd,fqdn_rev,hostname\n" + "192.0.2.2,02:02:02:02:02:02,,200,200,8,1,1,,\n" + "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,200,8,1,1,,\n"); + + LeaseFileIO io1("leasefile4_0.csv.1"); + io1.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id," + "fqdn_fwd,fqdn_rev,hostname\n" + "192.0.2.1,01:01:01:01:01:01,,200,200,8,1,1,,\n" + "192.0.2.11,bb:bb:bb:bb:bb:bb,,200,400,8,1,1,,\n" + "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,200,8,1,1,,\n"); + + LeaseFileIO io("leasefile4_0.csv"); + io.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id," + "fqdn_fwd,fqdn_rev,hostname\n" + "192.0.2.10,0a:0a:0a:0a:0a:0a,,200,200,8,1,1,,\n" + "192.0.2.12,cc:cc:cc:cc:cc:cc,,200,400,8,1,1,,\n"); + + startBackend(V4); + + Lease4Ptr lease = lmptr_->getLease4(IOAddress("192.0.2.1")); + ASSERT_TRUE(lease); + EXPECT_EQ(0, lease->cltt_); + + lease = lmptr_->getLease4(IOAddress("192.0.2.2")); + ASSERT_TRUE(lease); + EXPECT_EQ(0, lease->cltt_); + + lease = lmptr_->getLease4(IOAddress("192.0.2.10")); + ASSERT_TRUE(lease); + EXPECT_EQ(0, lease->cltt_); + + lease = lmptr_->getLease4(IOAddress("192.0.2.11")); + ASSERT_TRUE(lease); + EXPECT_EQ(200, lease->cltt_); + + lease = lmptr_->getLease4(IOAddress("192.0.2.12")); + ASSERT_TRUE(lease); + EXPECT_EQ(200, lease->cltt_); +} + }; // end of anonymous namespace