|
@@ -260,91 +260,4 @@ TEST_F(CtrlDhcpv4SrvTest, commandsRegistration) {
|
|
|
EXPECT_EQ("[ \"list-commands\" ]", answer->get("arguments")->str());
|
|
|
}
|
|
|
|
|
|
-// Checks if the server is able to parse control socket configuration and
|
|
|
-// configures the command socket properly.
|
|
|
-
|
|
|
-/// @todo: This unit-test is disabled, because it causes weird issues, when
|
|
|
-/// IfaceMgr::receive4() is called in a separate process. That's a side effect
|
|
|
-/// of how we run the test. We should either investigate why IfaceMgr doesn't
|
|
|
-/// work correctly after fork or develop a small tool that will send data
|
|
|
-/// from stdin to specified UNIX socket, print out the responses on stdout
|
|
|
-/// and develop shell tests for this.
|
|
|
-///
|
|
|
-/// Note that the test passes when run on its own, but not when run along with
|
|
|
-/// other unit-tests.
|
|
|
-TEST_F(CtrlDhcpv4SrvTest, DISABLED_commandSocketBasic) {
|
|
|
-
|
|
|
- string socket_path = string(TEST_DATA_BUILDDIR) + "/kea4.sock";
|
|
|
- ::remove(socket_path.c_str());
|
|
|
-
|
|
|
- // Just a simple config. The important part here is the socket
|
|
|
- // location information.
|
|
|
- std::string config_txt =
|
|
|
- "{"
|
|
|
- " \"interfaces-config\": {"
|
|
|
- " \"interfaces\": [ \"*\" ]"
|
|
|
- " },"
|
|
|
- " \"rebind-timer\": 2000, "
|
|
|
- " \"renew-timer\": 1000, "
|
|
|
- " \"subnet4\": [ ],"
|
|
|
- " \"valid-lifetime\": 4000,"
|
|
|
- " \"control-socket\": {"
|
|
|
- " \"socket-type\": \"unix\","
|
|
|
- " \"socket-name\": \"" + socket_path + "\""
|
|
|
- " },"
|
|
|
- " \"lease-database\": { \"type\": \"memfile\", \"persist\": false }"
|
|
|
- "}";
|
|
|
-
|
|
|
- pid_t pid = fork();
|
|
|
- if (pid > 0) {
|
|
|
- cout << "Created child process: " << pid << endl;
|
|
|
-
|
|
|
- string command("{ \"command\": \"shutdown\" }");
|
|
|
- string response;
|
|
|
-
|
|
|
- sleep(3);
|
|
|
-
|
|
|
- EXPECT_TRUE(sendCommandUnixSocket(command, response, socket_path));
|
|
|
-
|
|
|
- kill(pid, SIGTERM);
|
|
|
- int status;
|
|
|
- waitpid(pid, &status, 0);
|
|
|
-
|
|
|
- ASSERT_NE(0, response.length());
|
|
|
-
|
|
|
- ConstElementPtr rsp;
|
|
|
- EXPECT_NO_THROW(rsp = Element::fromJSON(response));
|
|
|
- ASSERT_TRUE(rsp);
|
|
|
-
|
|
|
- int status_code;
|
|
|
- ConstElementPtr comment = parseAnswer(status_code, rsp);
|
|
|
- EXPECT_EQ(0, status_code);
|
|
|
- } else {
|
|
|
-
|
|
|
- IfaceMgr::instance().deleteAllExternalSockets();
|
|
|
-
|
|
|
- boost::scoped_ptr<ControlledDhcpv4Srv> srv;
|
|
|
- ASSERT_NO_THROW(
|
|
|
- srv.reset(new ControlledDhcpv4Srv(0));
|
|
|
- );
|
|
|
-
|
|
|
- ConstElementPtr config = Element::fromJSON(config_txt);
|
|
|
-
|
|
|
- ConstElementPtr answer = srv->processConfig(config);
|
|
|
- ASSERT_TRUE(answer);
|
|
|
-
|
|
|
- int status = 0;
|
|
|
- isc::config::parseAnswer(status, answer);
|
|
|
- EXPECT_EQ(0, status);
|
|
|
-
|
|
|
- // Now check that the socket was indeed open.
|
|
|
- ASSERT_TRUE(isc::config::CommandMgr::instance().getControlSocketFD() > -1);
|
|
|
-
|
|
|
- cout << "Child process: pid=" << pid << ", running server." << endl;
|
|
|
- srv->run();
|
|
|
-
|
|
|
- exit(EXIT_SUCCESS);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
} // End of anonymous namespace
|