From: Razvan Becheriu Date: Fri, 14 Jun 2024 14:09:50 +0000 (+0300) Subject: [#3450] make kea environment available to lfc X-Git-Tag: Kea-2.7.0~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f477e8ebcc8b8e1f1adaad4d55031084c0ff6f40;p=thirdparty%2Fkea.git [#3450] make kea environment available to lfc --- diff --git a/configure.ac b/configure.ac index c2621f8b29..071c665963 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 5cbe808b5c..6b079ccd19 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -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) { diff --git a/src/lib/dhcpsrv/tests/.gitignore b/src/lib/dhcpsrv/tests/.gitignore index 33ac8d9e86..d7940fabc2 100644 --- a/src/lib/dhcpsrv/tests/.gitignore +++ b/src/lib/dhcpsrv/tests/.gitignore @@ -1,2 +1,3 @@ /libdhcpsrv_unittests /test_libraries.h +/test_kea_lfc_env.sh diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 034f1f55bd..9edf637dce 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -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 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 index 0000000000..3eb71d5adc --- /dev/null +++ b/src/lib/dhcpsrv/tests/test_kea_lfc_env.sh.in @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ $(env | grep -c KEA_LFC_EXECUTABLE) != 0 ]; then + exit 0 +fi +exit 1