]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3450] make kea environment available to lfc
authorRazvan Becheriu <razvan@isc.org>
Fri, 14 Jun 2024 14:09:50 +0000 (17:09 +0300)
committerRazvan Becheriu <razvan@isc.org>
Mon, 17 Jun 2024 13:02:09 +0000 (16:02 +0300)
configure.ac
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/tests/.gitignore
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/test_kea_lfc_env.sh.in [new file with mode: 0644]

index c2621f8b2991a5925c8a10111fdc6a5deb1e4af4..071c665963ec02e8c47e2931f8f9066845338264 100644 (file)
@@ -1629,6 +1629,8 @@ AC_CONFIG_FILES([src/lib/dhcp_ddns/tests/Makefile])
 AC_CONFIG_FILES([src/lib/dhcpsrv/Makefile])
 AC_CONFIG_FILES([src/lib/dhcpsrv/tests/Makefile])
 AC_CONFIG_FILES([src/lib/dhcpsrv/tests/test_libraries.h])
+AC_CONFIG_FILES([src/lib/dhcpsrv/tests/test_kea_lfc_env.sh],
+                [chmod +x src/lib/dhcpsrv/tests/test_kea_lfc_env.sh])
 AC_CONFIG_FILES([src/lib/dhcpsrv/testutils/Makefile])
 AC_CONFIG_FILES([src/lib/dns/Makefile])
 AC_CONFIG_FILES([src/lib/dns/tests/Makefile])
index 5cbe808b5c6666e0d433c55330e4832056a2def4..6b079ccd19438bea0da74756cbaed89fe9e8f47a 100644 (file)
@@ -209,7 +209,8 @@ LFCSetup::setup(const uint32_t lfc_interval,
     args.push_back("ignored-path");
 
     // Create the process (do not start it yet).
-    process_.reset(new ProcessSpawn(ProcessSpawn::ASYNC, executable, args));
+    process_.reset(new ProcessSpawn(ProcessSpawn::ASYNC, executable, args,
+                                    ProcessEnvVars(), true));
 
     // If we've been told to run it once now, invoke the callback directly.
     if (run_once_now) {
index 33ac8d9e86599f4966b7c3fb8d5949a6b97a0154..d7940fabc24bacc61c25ddf079c5f33cd68f8eb9 100644 (file)
@@ -1,2 +1,3 @@
 /libdhcpsrv_unittests
 /test_libraries.h
+/test_kea_lfc_env.sh
index 034f1f55bd262dd1c347337f851c2bcf3af97e2d..9edf637dce4568e437c83dece380fa7ee3013a81 100644 (file)
@@ -534,6 +534,32 @@ TEST_F(MemfileLeaseMgrTest, lfcTimer) {
     EXPECT_EQ(2, lease_mgr->getLFCCount());
 }
 
+/// @brief Check that the kea environment is accesible to the Lease
+/// File Cleanup process.
+TEST_F(MemfileLeaseMgrTest, lfcEnv) {
+    DatabaseConnection::ParameterMap pmap;
+    pmap["type"] = "memfile";
+    pmap["universe"] = "4";
+    pmap["name"] = getLeaseFilePath("leasefile4_0.csv");
+    pmap["lfc-interval"] = "1";
+
+    std::ostringstream s;
+    s << DHCP_DATA_DIR << "/test_kea_lfc_env.sh";
+    setenv("KEA_LFC_EXECUTABLE", s.str().c_str(), 1);
+
+    boost::scoped_ptr<NakedMemfileLeaseMgr> lease_mgr(new NakedMemfileLeaseMgr(pmap));
+
+    // Try to run the lease file cleanup.
+    ASSERT_NO_THROW(lease_mgr->lfcCallback());
+
+    // Wait for the LFC process to complete.
+    ASSERT_TRUE(waitForProcess(*lease_mgr, 1));
+
+    // And make sure it has returned an exit status of 0.
+    EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
+        << "environment not available to LFC";
+}
+
 /// @brief This test checks if the LFC timer is disabled (doesn't trigger)
 /// cleanups when the lfc-interval is set to 0.
 TEST_F(MemfileLeaseMgrTest, lfcTimerDisabled) {
diff --git a/src/lib/dhcpsrv/tests/test_kea_lfc_env.sh.in b/src/lib/dhcpsrv/tests/test_kea_lfc_env.sh.in
new file mode 100644 (file)
index 0000000..3eb71d5
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ $(env | grep -c KEA_LFC_EXECUTABLE) != 0 ]; then
+    exit 0
+fi
+exit 1