diff --git a/doc/examples/ddns/all-keys-netconf.json b/doc/examples/ddns/all-keys-netconf.json index 642258dc35..be481f6851 100644 --- a/doc/examples/ddns/all-keys-netconf.json +++ b/doc/examples/ddns/all-keys-netconf.json @@ -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. diff --git a/doc/examples/ddns/all-keys.json b/doc/examples/ddns/all-keys.json index b9015d8713..f1b8d48b9a 100644 --- a/doc/examples/ddns/all-keys.json +++ b/doc/examples/ddns/all-keys.json @@ -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. diff --git a/doc/examples/ddns/comments.json b/doc/examples/ddns/comments.json index ecd68c4765..08b24e609a 100644 --- a/doc/examples/ddns/comments.json +++ b/doc/examples/ddns/comments.json @@ -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" } }, { diff --git a/doc/examples/ddns/sample1.json b/doc/examples/ddns/sample1.json index 4d8148bc29..2c43ba920a 100644 --- a/doc/examples/ddns/sample1.json +++ b/doc/examples/ddns/sample1.json @@ -32,7 +32,7 @@ "control-socket": { "socket-type": "unix", - "socket-name": "/tmp/kea-ddns-ctrl-socket" + "socket-name": "kea-ddns-ctrl-socket" }, // ----------------- Hooks Libraries ----------------- diff --git a/doc/examples/ddns/template.json b/doc/examples/ddns/template.json index cec9e3234b..67b371b7bc 100644 --- a/doc/examples/ddns/template.json +++ b/doc/examples/ddns/template.json @@ -19,7 +19,7 @@ // "control-socket": // { // "socket-type": "unix", -// "socket-name": "/tmp/kea-ddns-ctrl-socket" +// "socket-name": "kea-ddns-ctrl-socket" // }, // ----------------- Forward DDNS ------------------ diff --git a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc index 42983a607d..f71e6a29ba 100644 --- a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include #include @@ -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\" }" "}," diff --git a/src/bin/d2/tests/d2_command_unittest.cc b/src/bin/d2/tests/d2_command_unittest.cc index f83f5cd88b..52360a22cb 100644 --- a/src/bin/d2/tests/d2_command_unittest.cc +++ b/src/bin/d2/tests/d2_command_unittest.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/src/bin/d2/tests/get_config_unittest.cc b/src/bin/d2/tests/get_config_unittest.cc index 6eee45d066..84a38ab4c9 100644 --- a/src/bin/d2/tests/get_config_unittest.cc +++ b/src/bin/d2/tests/get_config_unittest.cc @@ -8,12 +8,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -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(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"; diff --git a/src/bin/d2/tests/testdata/get_config.json b/src/bin/d2/tests/testdata/get_config.json index d3059dde7f..1a6d9ed098 100644 --- a/src/bin/d2/tests/testdata/get_config.json +++ b/src/bin/d2/tests/testdata/get_config.json @@ -2,7 +2,7 @@ "DhcpDdns": { "control-sockets": [ { - "socket-name": "/tmp/kea-ddns-ctrl-socket", + "socket-name": "kea-ddns-ctrl-socket", "socket-type": "unix" } ],