]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3969] Set socket path in NETCONF tests
authorAndrei Pavel <andrei@isc.org>
Wed, 5 Nov 2025 11:06:12 +0000 (13:06 +0200)
committerAndrei Pavel <andrei@isc.org>
Wed, 5 Nov 2025 13:01:01 +0000 (15:01 +0200)
src/bin/netconf/tests/control_socket_unittests.cc
src/bin/netconf/tests/get_config_unittest.cc
src/bin/netconf/tests/netconf_controller_unittests.cc
src/bin/netconf/tests/netconf_unittests.cc

index 0d11611a3347f88c770eb8a2f0cfaca3dc0d4d60..b40efcaeb69122d8580156740235be8e9654b5b8 100644 (file)
@@ -38,6 +38,7 @@ using namespace isc::data;
 using namespace isc::http;
 using namespace isc::http::test;
 using namespace isc::test;
+using namespace isc::util::file;
 
 using isc::yang::test::SysrepoSetup;
 
@@ -149,6 +150,7 @@ public:
     void SetUp() override {
         SysrepoSetup::cleanSharedMemory();
         removeUnixSocketFile();
+        setSocketTestPath();
     }
 
     void TearDown() override {
@@ -158,6 +160,7 @@ public:
         }
         removeUnixSocketFile();
         io_service_->stopAndPoll();
+        resetSocketPath();
     }
 
     /// @brief Returns socket file path.
@@ -176,6 +179,21 @@ public:
         return (socket_path);
     }
 
+    /// @brief Sets the path in which the socket can be created.
+    ///
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = string()) {
+        string path(UnixCommandConfig::getSocketPath(
+            true, (!explicit_path.empty() ? explicit_path : TEST_DATA_BUILDDIR)));
+        UnixCommandConfig::setSocketPathPerms(getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     /// @brief Removes unix socket descriptor.
     void removeUnixSocketFile() {
         static_cast<void>(remove(unixSocketFilePath().c_str()));
index f172dfd5a67897bf41716669c0d626e91b757d93..90486564c88a6cdd571853f3fe4c72b7a99d0da7 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <cc/command_interpreter.h>
 #include <cc/data.h>
+#include <config/unix_command_config.h>
 #include <netconf/netconf_cfg_mgr.h>
 #include <netconf/parser_context.h>
 #include <process/testutils/d_test_stubs.h>
@@ -26,6 +27,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::process;
 using namespace isc::test;
+using namespace isc::util::file;
 
 namespace {
 
@@ -123,10 +125,12 @@ public:
         srv_.reset(new NakedNetconfCfgMgr());
         // Create fresh context.
         resetConfiguration();
+        setSocketTestPath();
     }
 
     ~NetconfGetCfgTest() {
         resetConfiguration();
+        resetSocketPath();
     }
 
     /// @brief Parse and Execute configuration
@@ -219,6 +223,21 @@ public:
         EXPECT_TRUE(executeConfiguration(config, "reset config"));
     }
 
+    /// @brief Sets the path in which the socket can be created.
+    ///
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = string()) {
+        string path(UnixCommandConfig::getSocketPath(
+            true, (!explicit_path.empty() ? explicit_path : TEST_DATA_BUILDDIR)));
+        UnixCommandConfig::setSocketPathPerms(getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     unique_ptr<NakedNetconfCfgMgr> srv_;    ///< Netconf server under test
     int rcode_;                             ///< Return code from element parsing
     ConstElementPtr comment_;               ///< Reason for parse fail
index 0c6f6a096bb7759d1679fd0fb34a024157889579..265c9643901598a4e40be97b77a5f4717808e114 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <asiolink/testutils/timed_signal.h>
 #include <cc/data.h>
+#include <config/unix_command_config.h>
 #include <netconf/netconf_controller.h>
 #include <netconf/netconf_process.h>
 #include <process/testutils/d_test_stubs.h>
@@ -17,6 +18,7 @@
 #include <gtest/gtest.h>
 
 using namespace isc::asiolink::test;
+using namespace isc::config;
 using namespace isc::netconf;
 using namespace isc::data;
 using namespace isc::http;
@@ -71,6 +73,11 @@ public:
     /// @brief Constructor.
     NetconfControllerTest()
         : DControllerTest(NetconfController::instance) {
+        setSocketTestPath();
+    }
+
+    void TearDown() override {
+        resetSocketPath();
     }
 
     /// @brief Returns pointer to NetconfProcess instance.
@@ -95,6 +102,21 @@ public:
         }
         return (p);
     }
+
+    /// @brief Sets the path in which the socket can be created.
+    ///
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = string()) {
+        string path(UnixCommandConfig::getSocketPath(
+            true, (!explicit_path.empty() ? explicit_path : TEST_DATA_BUILDDIR)));
+        UnixCommandConfig::setSocketPathPerms(getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
 };  // NetconfControllerTest
 
 // Basic Controller instantiation testing.
index ef6c5730d2c81e17f79d645d0611ebcf41b9f4fc..59f10a7d0d3b481b11cf50f25c6eaa6406af069a 100644 (file)
@@ -113,6 +113,7 @@ public:
         removeUnixSocketFile();
         io_service_.reset(new IOService());
         agent_.reset(new NakedNetconfAgent());
+        setSocketTestPath();
     }
 
     void TearDown() override {
@@ -130,6 +131,7 @@ public:
         removeUnixSocketFile();
         SysrepoSetup::cleanSharedMemory();
         io_service_->stopAndPoll();
+        resetSocketPath();
     }
 
     /// @brief Returns socket file path.
@@ -153,6 +155,21 @@ public:
         static_cast<void>(remove(unixSocketFilePath().c_str()));
     }
 
+    /// @brief Sets the path in which the socket can be created.
+    ///
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = string()) {
+        string path(UnixCommandConfig::getSocketPath(
+            true, (!explicit_path.empty() ? explicit_path : TEST_DATA_BUILDDIR)));
+        UnixCommandConfig::setSocketPathPerms(getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     /// @brief Create configuration of the control socket.
     ///
     /// @return a pointer to a control socket configuration.