From: Francis Dupont Date: Tue, 2 Sep 2025 09:37:00 +0000 (+0200) Subject: [#2305] Added UT and ChangeLog entry X-Git-Tag: Kea-3.1.2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1af19c9e501da52375b5a004bcb57172075e1854;p=thirdparty%2Fkea.git [#2305] Added UT and ChangeLog entry --- diff --git a/changelog_unreleased/2305-status-get-return-csv-lease-file-location-when-used b/changelog_unreleased/2305-status-get-return-csv-lease-file-location-when-used new file mode 100644 index 0000000000..296105f2f9 --- /dev/null +++ b/changelog_unreleased/2305-status-get-return-csv-lease-file-location-when-used @@ -0,0 +1,5 @@ +[func] fdupont + When Kea is configured to use a CSV backup file for leases, + the "status-get" command returns its location is the + "csv-lease-file" entry. + (Gitlab #2305) diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 3ba5ea47fa..c387b118ca 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -2268,6 +2268,25 @@ Memfile_LeaseMgr::isLFCProcessRunning(const std::string file_name, Universe u) { return (!pid_lock.isLocked() || pid_file.check()); } +ElementPtr +Memfile_LeaseMgr::getStatus() const { + std::string file_name; + if (lease_file4_) { + file_name = lease_file4_->getFilename(); + } else if (lease_file6_) { + file_name = lease_file6_->getFilename(); + } else { + return (ElementPtr()); + } + if (file_name.empty()) { + // Should not happen. + return (ElementPtr()); + } + ElementPtr status = Element::createMap(); + status->set("csv-lease-file", Element::create(file_name)); + return (status); +} + std::string Memfile_LeaseMgr::appendSuffix(const std::string& file_name, const LFCFileType& file_type) { diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 6a2ae69616..bb02dd248d 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -968,6 +968,12 @@ public: /// @return True if LFC is running, false otherwise (memfile only). static bool isLFCProcessRunning(const std::string file_name, Universe u); + /// @brief Return status information. + /// + /// @return Null or a map with the lease file name to add to + /// status-get command output. + virtual data::ElementPtr getStatus() const override; + //@} /// @name Public type and method used to determine file names for LFC. diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index cb6018874f..868c68b216 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -445,6 +445,9 @@ TEST_F(MemfileLeaseMgrTest, constructor) { EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); EXPECT_TRUE(lease_mgr->getExtendedInfoTablesEnabled()); + // Persist is false so no csv file. + EXPECT_FALSE(lease_mgr->getStatus()); + // Expecting that persist parameter is yes or no. Everything other than // that is wrong. pmap["lfc-interval"] = "10"; @@ -514,6 +517,10 @@ TEST_F(MemfileLeaseMgrTest, dataDirEnvVarOverride) { ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); EXPECT_EQ(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6), "/tmp/leasefile6_1.csv"); + ConstElementPtr status = lease_mgr->getStatus(); + ASSERT_TRUE(status); + EXPECT_EQ(status->str(), + "{ \"csv-lease-file\": \"/tmp/leasefile6_1.csv\" }"); } /// @brief Verifies that the supported path may be overridden with @@ -533,6 +540,10 @@ TEST_F(MemfileLeaseMgrTest, dataDirExplicitOveride) { ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap))); EXPECT_EQ(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6), "/tmp/leasefile6_1.csv"); + ConstElementPtr status = lease_mgr->getStatus(); + ASSERT_TRUE(status); + EXPECT_EQ(status->str(), + "{ \"csv-lease-file\": \"/tmp/leasefile6_1.csv\" }"); } /// @brief Checks if there is no lease manager NoLeaseManager is thrown. @@ -567,6 +578,7 @@ TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) { 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()); + EXPECT_FALSE(lease_mgr->getStatus()); } /// @brief Check if the persistLeases correctly checks that leases should not be written