mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +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:
parent
3a5f553bd8
commit
cc07755a2d
@ -40,7 +40,7 @@
|
|||||||
// Location of the UNIX domain socket file the DHCP-DDNS server uses
|
// Location of the UNIX domain socket file the DHCP-DDNS server uses
|
||||||
// to receive control commands from the Kea Control Agent or the
|
// to receive control commands from the Kea Control Agent or the
|
||||||
// local server administrator.
|
// 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.
|
// Control socket type used by the Kea DHCP-DDNS server.
|
||||||
// The 'unix' socket is currently the only supported type.
|
// The 'unix' socket is currently the only supported type.
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
// Location of the UNIX domain socket file the DHCP-DDNS
|
// Location of the UNIX domain socket file the DHCP-DDNS
|
||||||
// server uses to receive control commands from the
|
// server uses to receive control commands from the
|
||||||
// local server administrator.
|
// 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.
|
// Control socket type used by the Kea DHCP-DDNS server.
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"control-sockets": [
|
"control-sockets": [
|
||||||
{
|
{
|
||||||
"socket-type": "unix",
|
"socket-type": "unix",
|
||||||
"socket-name": "/tmp/kea-ddns-ctrl-socket",
|
"socket-name": "kea-ddns-ctrl-socket",
|
||||||
"user-context": { "comment": "Indirect comment" }
|
"user-context": { "comment": "Indirect comment" }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
"control-socket":
|
"control-socket":
|
||||||
{
|
{
|
||||||
"socket-type": "unix",
|
"socket-type": "unix",
|
||||||
"socket-name": "/tmp/kea-ddns-ctrl-socket"
|
"socket-name": "kea-ddns-ctrl-socket"
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------- Hooks Libraries -----------------
|
// ----------------- Hooks Libraries -----------------
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
// "control-socket":
|
// "control-socket":
|
||||||
// {
|
// {
|
||||||
// "socket-type": "unix",
|
// "socket-type": "unix",
|
||||||
// "socket-name": "/tmp/kea-ddns-ctrl-socket"
|
// "socket-name": "kea-ddns-ctrl-socket"
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// ----------------- Forward DDNS ------------------
|
// ----------------- Forward DDNS ------------------
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <config/http_command_config.h>
|
#include <config/http_command_config.h>
|
||||||
|
#include <config/unix_command_config.h>
|
||||||
#include <d2/parser_context.h>
|
#include <d2/parser_context.h>
|
||||||
#include <d2/tests/parser_unittest.h>
|
#include <d2/tests/parser_unittest.h>
|
||||||
#include <d2/tests/test_callout_libraries.h>
|
#include <d2/tests/test_callout_libraries.h>
|
||||||
@ -18,6 +19,7 @@
|
|||||||
#include <process/testutils/d_test_stubs.h>
|
#include <process/testutils/d_test_stubs.h>
|
||||||
#include <test_data_files_config.h>
|
#include <test_data_files_config.h>
|
||||||
#include <util/encode/encode.h>
|
#include <util/encode/encode.h>
|
||||||
|
#include <util/filesystem.h>
|
||||||
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@ -27,6 +29,8 @@ using namespace isc;
|
|||||||
using namespace isc::d2;
|
using namespace isc::d2;
|
||||||
using namespace isc::hooks;
|
using namespace isc::hooks;
|
||||||
using namespace isc::process;
|
using namespace isc::process;
|
||||||
|
using namespace isc::config;
|
||||||
|
using namespace isc::util;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -50,11 +54,13 @@ public:
|
|||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
D2CfgMgrTest():cfg_mgr_(new D2CfgMgr()), d2_params_() {
|
D2CfgMgrTest():cfg_mgr_(new D2CfgMgr()), d2_params_() {
|
||||||
resetHooksPath();
|
resetHooksPath();
|
||||||
|
resetSocketPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Destructor
|
/// @brief Destructor
|
||||||
~D2CfgMgrTest() {
|
~D2CfgMgrTest() {
|
||||||
resetHooksPath();
|
resetHooksPath();
|
||||||
|
resetSocketPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Sets the Hooks path from which hooks can be loaded.
|
/// @brief Sets the Hooks path from which hooks can be loaded.
|
||||||
@ -70,6 +76,22 @@ public:
|
|||||||
HooksLibrariesParser::getHooksPath(true);
|
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.
|
/// @brief Configuration manager instance.
|
||||||
D2CfgMgrPtr cfg_mgr_;
|
D2CfgMgrPtr cfg_mgr_;
|
||||||
|
|
||||||
@ -478,6 +500,7 @@ TEST(D2CfgMgr, construction) {
|
|||||||
/// event.
|
/// event.
|
||||||
TEST_F(D2CfgMgrTest, fullConfig) {
|
TEST_F(D2CfgMgrTest, fullConfig) {
|
||||||
setHooksTestPath();
|
setHooksTestPath();
|
||||||
|
setSocketTestPath();
|
||||||
|
|
||||||
// Create a configuration with all of application level parameters, plus
|
// Create a configuration with all of application level parameters, plus
|
||||||
// both the forward and reverse ddns managers. Both managers have two
|
// both the forward and reverse ddns managers. Both managers have two
|
||||||
@ -490,7 +513,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
|
|||||||
"\"ncr-format\": \"JSON\", "
|
"\"ncr-format\": \"JSON\", "
|
||||||
"\"control-socket\" : {"
|
"\"control-socket\" : {"
|
||||||
" \"socket-type\" : \"unix\" ,"
|
" \"socket-type\" : \"unix\" ,"
|
||||||
" \"socket-name\" : \"/tmp/d2-ctrl-channel\" "
|
" \"socket-name\" : \"d2-ctrl-channel\" "
|
||||||
"},"
|
"},"
|
||||||
"\"hooks-libraries\": ["
|
"\"hooks-libraries\": ["
|
||||||
"{"
|
"{"
|
||||||
@ -580,7 +603,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
|
|||||||
ASSERT_TRUE(ctrl_sock->get("socket-type"));
|
ASSERT_TRUE(ctrl_sock->get("socket-type"));
|
||||||
EXPECT_EQ("\"unix\"", ctrl_sock->get("socket-type")->str());
|
EXPECT_EQ("\"unix\"", ctrl_sock->get("socket-type")->str());
|
||||||
ASSERT_TRUE(ctrl_sock->get("socket-name"));
|
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.
|
// Verify that the hooks libraries can be retrieved.
|
||||||
const HookLibsCollection libs = context->getHooksConfig().get();
|
const HookLibsCollection libs = context->getHooksConfig().get();
|
||||||
@ -989,6 +1012,7 @@ TEST_F(D2CfgMgrTest, configPermutations) {
|
|||||||
|
|
||||||
/// @brief Tests comments.
|
/// @brief Tests comments.
|
||||||
TEST_F(D2CfgMgrTest, comments) {
|
TEST_F(D2CfgMgrTest, comments) {
|
||||||
|
setSocketTestPath();
|
||||||
std::string config = "{ "
|
std::string config = "{ "
|
||||||
"\"comment\": \"D2 config\" , "
|
"\"comment\": \"D2 config\" , "
|
||||||
"\"ip-address\" : \"192.168.1.33\" , "
|
"\"ip-address\" : \"192.168.1.33\" , "
|
||||||
@ -996,7 +1020,7 @@ TEST_F(D2CfgMgrTest, comments) {
|
|||||||
"\"control-sockets\": ["
|
"\"control-sockets\": ["
|
||||||
"{"
|
"{"
|
||||||
" \"socket-type\": \"unix\","
|
" \"socket-type\": \"unix\","
|
||||||
" \"socket-name\": \"/tmp/d2-ctrl-socket\","
|
" \"socket-name\": \"d2-ctrl-socket\","
|
||||||
" \"user-context\": { \"comment\":"
|
" \"user-context\": { \"comment\":"
|
||||||
" \"Indirect comment\" }"
|
" \"Indirect comment\" }"
|
||||||
"},"
|
"},"
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <d2/d2_controller.h>
|
#include <d2/d2_controller.h>
|
||||||
#include <d2/d2_process.h>
|
#include <d2/d2_process.h>
|
||||||
#include <d2/parser_context.h>
|
#include <d2/parser_context.h>
|
||||||
|
#include <util/filesystem.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <testutils/sandbox.h>
|
#include <testutils/sandbox.h>
|
||||||
#include <boost/pointer_cast.hpp>
|
#include <boost/pointer_cast.hpp>
|
||||||
@ -34,6 +35,7 @@ using namespace isc::d2;
|
|||||||
using namespace isc::data;
|
using namespace isc::data;
|
||||||
using namespace isc::dhcp::test;
|
using namespace isc::dhcp::test;
|
||||||
using namespace isc::process;
|
using namespace isc::process;
|
||||||
|
using namespace isc::util;
|
||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
namespace ph = std::placeholders;
|
namespace ph = std::placeholders;
|
||||||
|
|
||||||
@ -125,12 +127,7 @@ public:
|
|||||||
/// Sets socket path to its default value.
|
/// Sets socket path to its default value.
|
||||||
CtrlChannelD2Test()
|
CtrlChannelD2Test()
|
||||||
: server_(NakedD2Controller::instance()) {
|
: server_(NakedD2Controller::instance()) {
|
||||||
const char* env = getenv("KEA_SOCKET_TEST_DIR");
|
setSocketTestPath();
|
||||||
if (env) {
|
|
||||||
socket_path_ = string(env) + "/d2.sock";
|
|
||||||
} else {
|
|
||||||
socket_path_ = sandbox.join("d2.sock");
|
|
||||||
}
|
|
||||||
::remove(socket_path_.c_str());
|
::remove(socket_path_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +143,7 @@ public:
|
|||||||
// Reset command manager.
|
// Reset command manager.
|
||||||
CommandMgr::instance().deregisterAll();
|
CommandMgr::instance().deregisterAll();
|
||||||
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
|
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
|
||||||
|
resetSocketPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Returns pointer to the server's IO service.
|
/// @brief Returns pointer to the server's IO service.
|
||||||
@ -156,6 +154,23 @@ public:
|
|||||||
return (server_ ? d2Controller()->getIOService() : IOServicePtr());
|
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
|
/// @brief Runs parser in DHCPDDNS mode
|
||||||
///
|
///
|
||||||
/// @param config input configuration
|
/// @param config input configuration
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
#include <cc/command_interpreter.h>
|
#include <cc/command_interpreter.h>
|
||||||
#include <cc/data.h>
|
#include <cc/data.h>
|
||||||
|
#include <config/unix_command_config.h>
|
||||||
#include <d2/parser_context.h>
|
#include <d2/parser_context.h>
|
||||||
#include <d2srv/d2_cfg_mgr.h>
|
#include <d2srv/d2_cfg_mgr.h>
|
||||||
#include <d2srv/d2_config.h>
|
#include <d2srv/d2_config.h>
|
||||||
#include <hooks/hooks_parser.h>
|
#include <hooks/hooks_parser.h>
|
||||||
#include <process/testutils/d_test_stubs.h>
|
#include <process/testutils/d_test_stubs.h>
|
||||||
#include <testutils/user_context_utils.h>
|
#include <testutils/user_context_utils.h>
|
||||||
|
#include <util/filesystem.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -30,6 +32,7 @@ using namespace isc::data;
|
|||||||
using namespace isc::process;
|
using namespace isc::process;
|
||||||
using namespace isc::test;
|
using namespace isc::test;
|
||||||
using namespace isc::hooks;
|
using namespace isc::hooks;
|
||||||
|
using namespace isc::util;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -142,6 +145,7 @@ public:
|
|||||||
D2GetConfigTest()
|
D2GetConfigTest()
|
||||||
: rcode_(-1) {
|
: rcode_(-1) {
|
||||||
resetHooksPath();
|
resetHooksPath();
|
||||||
|
resetSocketPath();
|
||||||
srv_.reset(new D2CfgMgr());
|
srv_.reset(new D2CfgMgr());
|
||||||
// Enforce not verbose mode.
|
// Enforce not verbose mode.
|
||||||
Daemon::setVerbose(false);
|
Daemon::setVerbose(false);
|
||||||
@ -155,6 +159,7 @@ public:
|
|||||||
static_cast<void>(remove(test_file_name.c_str()));
|
static_cast<void>(remove(test_file_name.c_str()));
|
||||||
resetConfiguration();
|
resetConfiguration();
|
||||||
resetHooksPath();
|
resetHooksPath();
|
||||||
|
resetSocketPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Sets the Hooks path from which hooks can be loaded.
|
/// @brief Sets the Hooks path from which hooks can be loaded.
|
||||||
@ -170,6 +175,23 @@ public:
|
|||||||
HooksLibrariesParser::getHooksPath(true);
|
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
|
/// @brief Parse and Execute configuration
|
||||||
///
|
///
|
||||||
/// Parses a configuration and executes a configuration of the server.
|
/// Parses a configuration and executes a configuration of the server.
|
||||||
@ -279,6 +301,7 @@ public:
|
|||||||
/// Test a configuration
|
/// Test a configuration
|
||||||
TEST_F(D2GetConfigTest, sample1) {
|
TEST_F(D2GetConfigTest, sample1) {
|
||||||
setHooksTestPath();
|
setHooksTestPath();
|
||||||
|
setSocketTestPath();
|
||||||
|
|
||||||
// get the sample1 configuration
|
// get the sample1 configuration
|
||||||
std::string sample1_file = string(CFG_EXAMPLES) + "/" + "sample1.json";
|
std::string sample1_file = string(CFG_EXAMPLES) + "/" + "sample1.json";
|
||||||
|
2
src/bin/d2/tests/testdata/get_config.json
vendored
2
src/bin/d2/tests/testdata/get_config.json
vendored
@ -2,7 +2,7 @@
|
|||||||
"DhcpDdns": {
|
"DhcpDdns": {
|
||||||
"control-sockets": [
|
"control-sockets": [
|
||||||
{
|
{
|
||||||
"socket-name": "/tmp/kea-ddns-ctrl-socket",
|
"socket-name": "kea-ddns-ctrl-socket",
|
||||||
"socket-type": "unix"
|
"socket-type": "unix"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user