From c1fcb430e131239c911e2367d300dbe582515fa0 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Wed, 5 Nov 2025 13:06:12 +0200 Subject: [PATCH] [#3969] Set socket path in NETCONF tests --- .../netconf/tests/control_socket_unittests.cc | 18 +++++++++++++++ src/bin/netconf/tests/get_config_unittest.cc | 19 ++++++++++++++++ .../tests/netconf_controller_unittests.cc | 22 +++++++++++++++++++ src/bin/netconf/tests/netconf_unittests.cc | 17 ++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/src/bin/netconf/tests/control_socket_unittests.cc b/src/bin/netconf/tests/control_socket_unittests.cc index 0d11611a33..b40efcaeb6 100644 --- a/src/bin/netconf/tests/control_socket_unittests.cc +++ b/src/bin/netconf/tests/control_socket_unittests.cc @@ -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(remove(unixSocketFilePath().c_str())); diff --git a/src/bin/netconf/tests/get_config_unittest.cc b/src/bin/netconf/tests/get_config_unittest.cc index f172dfd5a6..90486564c8 100644 --- a/src/bin/netconf/tests/get_config_unittest.cc +++ b/src/bin/netconf/tests/get_config_unittest.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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 srv_; ///< Netconf server under test int rcode_; ///< Return code from element parsing ConstElementPtr comment_; ///< Reason for parse fail diff --git a/src/bin/netconf/tests/netconf_controller_unittests.cc b/src/bin/netconf/tests/netconf_controller_unittests.cc index 0c6f6a096b..265c964390 100644 --- a/src/bin/netconf/tests/netconf_controller_unittests.cc +++ b/src/bin/netconf/tests/netconf_controller_unittests.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include 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. diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index ef6c5730d2..59f10a7d0d 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -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(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. -- 2.47.3