2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#3831] More UT fixes

modified:   doc/examples/ddns/all-keys-netconf.json
modified:   doc/examples/ddns/all-keys.json
modified:   doc/examples/ddns/comments.json
modified:   doc/examples/ddns/sample1.json
modified:   doc/examples/ddns/template.json
modified:   src/bin/d2/tests/d2_cfg_mgr_unittests.cc
modified:   src/bin/d2/tests/d2_command_unittest.cc
modified:   src/bin/d2/tests/get_config_unittest.cc
modified:   src/bin/d2/tests/testdata/get_config.json
This commit is contained in:
Thomas Markwalder 2025-05-16 09:09:48 -04:00
parent 3a5f553bd8
commit cc07755a2d
9 changed files with 77 additions and 15 deletions

View File

@ -40,7 +40,7 @@
// Location of the UNIX domain socket file the DHCP-DDNS server uses
// to receive control commands from the Kea Control Agent or the
// local server administrator.
"socket-name": "/tmp/kea-ddns-ctrl-socket",
"socket-name": "kea-ddns-ctrl-socket",
// Control socket type used by the Kea DHCP-DDNS server.
// The 'unix' socket is currently the only supported type.

View File

@ -44,7 +44,7 @@
// Location of the UNIX domain socket file the DHCP-DDNS
// server uses to receive control commands from the
// local server administrator.
"socket-name": "/tmp/kea-ddns-ctrl-socket"
"socket-name": "kea-ddns-ctrl-socket"
},
{
// Control socket type used by the Kea DHCP-DDNS server.

View File

@ -16,7 +16,7 @@
"control-sockets": [
{
"socket-type": "unix",
"socket-name": "/tmp/kea-ddns-ctrl-socket",
"socket-name": "kea-ddns-ctrl-socket",
"user-context": { "comment": "Indirect comment" }
},
{

View File

@ -32,7 +32,7 @@
"control-socket":
{
"socket-type": "unix",
"socket-name": "/tmp/kea-ddns-ctrl-socket"
"socket-name": "kea-ddns-ctrl-socket"
},
// ----------------- Hooks Libraries -----------------

View File

@ -19,7 +19,7 @@
// "control-socket":
// {
// "socket-type": "unix",
// "socket-name": "/tmp/kea-ddns-ctrl-socket"
// "socket-name": "kea-ddns-ctrl-socket"
// },
// ----------------- Forward DDNS ------------------

View File

@ -7,6 +7,7 @@
#include <config.h>
#include <config/http_command_config.h>
#include <config/unix_command_config.h>
#include <d2/parser_context.h>
#include <d2/tests/parser_unittest.h>
#include <d2/tests/test_callout_libraries.h>
@ -18,6 +19,7 @@
#include <process/testutils/d_test_stubs.h>
#include <test_data_files_config.h>
#include <util/encode/encode.h>
#include <util/filesystem.h>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
@ -27,6 +29,8 @@ using namespace isc;
using namespace isc::d2;
using namespace isc::hooks;
using namespace isc::process;
using namespace isc::config;
using namespace isc::util;
namespace {
@ -50,11 +54,13 @@ public:
/// @brief Constructor
D2CfgMgrTest():cfg_mgr_(new D2CfgMgr()), d2_params_() {
resetHooksPath();
resetSocketPath();
}
/// @brief Destructor
~D2CfgMgrTest() {
resetHooksPath();
resetSocketPath();
}
/// @brief Sets the Hooks path from which hooks can be loaded.
@ -70,6 +76,22 @@ public:
HooksLibrariesParser::getHooksPath(true);
}
/// @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 = "") {
UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
explicit_path : TEST_DATA_BUILDDIR));
auto path = UnixCommandConfig::getSocketPath();
UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
}
/// @brief Resets the socket path to the default.
void resetSocketPath() {
UnixCommandConfig::getSocketPath(true);
UnixCommandConfig::setSocketPathPerms();
}
/// @brief Configuration manager instance.
D2CfgMgrPtr cfg_mgr_;
@ -478,6 +500,7 @@ TEST(D2CfgMgr, construction) {
/// event.
TEST_F(D2CfgMgrTest, fullConfig) {
setHooksTestPath();
setSocketTestPath();
// Create a configuration with all of application level parameters, plus
// both the forward and reverse ddns managers. Both managers have two
@ -490,7 +513,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
"\"ncr-format\": \"JSON\", "
"\"control-socket\" : {"
" \"socket-type\" : \"unix\" ,"
" \"socket-name\" : \"/tmp/d2-ctrl-channel\" "
" \"socket-name\" : \"d2-ctrl-channel\" "
"},"
"\"hooks-libraries\": ["
"{"
@ -580,7 +603,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
ASSERT_TRUE(ctrl_sock->get("socket-type"));
EXPECT_EQ("\"unix\"", ctrl_sock->get("socket-type")->str());
ASSERT_TRUE(ctrl_sock->get("socket-name"));
EXPECT_EQ("\"/tmp/d2-ctrl-channel\"", ctrl_sock->get("socket-name")->str());
EXPECT_EQ("\"d2-ctrl-channel\"", ctrl_sock->get("socket-name")->str());
// Verify that the hooks libraries can be retrieved.
const HookLibsCollection libs = context->getHooksConfig().get();
@ -989,6 +1012,7 @@ TEST_F(D2CfgMgrTest, configPermutations) {
/// @brief Tests comments.
TEST_F(D2CfgMgrTest, comments) {
setSocketTestPath();
std::string config = "{ "
"\"comment\": \"D2 config\" , "
"\"ip-address\" : \"192.168.1.33\" , "
@ -996,7 +1020,7 @@ TEST_F(D2CfgMgrTest, comments) {
"\"control-sockets\": ["
"{"
" \"socket-type\": \"unix\","
" \"socket-name\": \"/tmp/d2-ctrl-socket\","
" \"socket-name\": \"d2-ctrl-socket\","
" \"user-context\": { \"comment\":"
" \"Indirect comment\" }"
"},"

View File

@ -17,6 +17,7 @@
#include <d2/d2_controller.h>
#include <d2/d2_process.h>
#include <d2/parser_context.h>
#include <util/filesystem.h>
#include <gtest/gtest.h>
#include <testutils/sandbox.h>
#include <boost/pointer_cast.hpp>
@ -34,6 +35,7 @@ using namespace isc::d2;
using namespace isc::data;
using namespace isc::dhcp::test;
using namespace isc::process;
using namespace isc::util;
using namespace boost::asio;
namespace ph = std::placeholders;
@ -125,12 +127,7 @@ public:
/// Sets socket path to its default value.
CtrlChannelD2Test()
: server_(NakedD2Controller::instance()) {
const char* env = getenv("KEA_SOCKET_TEST_DIR");
if (env) {
socket_path_ = string(env) + "/d2.sock";
} else {
socket_path_ = sandbox.join("d2.sock");
}
setSocketTestPath();
::remove(socket_path_.c_str());
}
@ -146,6 +143,7 @@ public:
// Reset command manager.
CommandMgr::instance().deregisterAll();
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
resetSocketPath();
}
/// @brief Returns pointer to the server's IO service.
@ -156,6 +154,23 @@ public:
return (server_ ? d2Controller()->getIOService() : IOServicePtr());
}
/// @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 = "") {
UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
explicit_path : TEST_DATA_BUILDDIR));
auto path = UnixCommandConfig::getSocketPath();
UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
socket_path_ = path + "/d2.sock";
}
/// @brief Resets the socket path to the default.
void resetSocketPath() {
UnixCommandConfig::getSocketPath(true);
UnixCommandConfig::setSocketPathPerms();
}
/// @brief Runs parser in DHCPDDNS mode
///
/// @param config input configuration

View File

@ -8,12 +8,14 @@
#include <cc/command_interpreter.h>
#include <cc/data.h>
#include <config/unix_command_config.h>
#include <d2/parser_context.h>
#include <d2srv/d2_cfg_mgr.h>
#include <d2srv/d2_config.h>
#include <hooks/hooks_parser.h>
#include <process/testutils/d_test_stubs.h>
#include <testutils/user_context_utils.h>
#include <util/filesystem.h>
#include <gtest/gtest.h>
#include <iostream>
@ -30,6 +32,7 @@ using namespace isc::data;
using namespace isc::process;
using namespace isc::test;
using namespace isc::hooks;
using namespace isc::util;
namespace {
@ -142,6 +145,7 @@ public:
D2GetConfigTest()
: rcode_(-1) {
resetHooksPath();
resetSocketPath();
srv_.reset(new D2CfgMgr());
// Enforce not verbose mode.
Daemon::setVerbose(false);
@ -155,6 +159,7 @@ public:
static_cast<void>(remove(test_file_name.c_str()));
resetConfiguration();
resetHooksPath();
resetSocketPath();
}
/// @brief Sets the Hooks path from which hooks can be loaded.
@ -170,6 +175,23 @@ public:
HooksLibrariesParser::getHooksPath(true);
}
/// @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 = "") {
UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
explicit_path : TEST_DATA_BUILDDIR));
auto path = UnixCommandConfig::getSocketPath();
UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
}
/// @brief Resets the socket path to the default.
void resetSocketPath() {
UnixCommandConfig::getSocketPath(true);
UnixCommandConfig::setSocketPathPerms();
}
/// @brief Parse and Execute configuration
///
/// Parses a configuration and executes a configuration of the server.
@ -279,6 +301,7 @@ public:
/// Test a configuration
TEST_F(D2GetConfigTest, sample1) {
setHooksTestPath();
setSocketTestPath();
// get the sample1 configuration
std::string sample1_file = string(CFG_EXAMPLES) + "/" + "sample1.json";

View File

@ -2,7 +2,7 @@
"DhcpDdns": {
"control-sockets": [
{
"socket-name": "/tmp/kea-ddns-ctrl-socket",
"socket-name": "kea-ddns-ctrl-socket",
"socket-type": "unix"
}
],