Commit 82f58f88 authored by Francis Dupont's avatar Francis Dupont Committed by Marcin Siodelski
Browse files

[#1041] Checkpoint: created status-get returning pid (only)

parent c3fb2c59
......@@ -574,6 +574,16 @@ ControlledDhcpv4Srv::commandConfigBackendPullHandler(const std::string&,
"On demand configuration update successful."));
}
ConstElementPtr
ControlledDhcpv4Srv::commandStatusGetHandler(const string&,
ConstElementPtr /*args*/) {
ElementPtr status = Element::createMap();
status->set("pid", Element::create(static_cast<int>(getpid())));
// TODO...
return (createAnswer(0, status));
}
ConstElementPtr
ControlledDhcpv4Srv::processCommand(const string& command,
ConstElementPtr args) {
......@@ -634,6 +644,8 @@ ControlledDhcpv4Srv::processCommand(const string& command,
} else if (command == "config-backend-pull") {
return (srv->commandConfigBackendPullHandler(command, args));
} else if (command == "status-get") {
return (srv->commandStatusGetHandler(command, args));
}
ConstElementPtr answer = isc::config::createAnswer(1,
"Unrecognized command:" + command);
......@@ -877,6 +889,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P
CommandMgr::instance().registerCommand("shutdown",
boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler, this, _1, _2));
CommandMgr::instance().registerCommand("status-get",
boost::bind(&ControlledDhcpv4Srv::commandStatusGetHandler, this, _1, _2));
CommandMgr::instance().registerCommand("version-get",
boost::bind(&ControlledDhcpv4Srv::commandVersionGetHandler, this, _1, _2));
......@@ -954,6 +969,7 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all");
CommandMgr::instance().deregisterCommand("statistic-sample-count-set");
CommandMgr::instance().deregisterCommand("statistic-sample-count-set-all");
CommandMgr::instance().deregisterCommand("status-get");
CommandMgr::instance().deregisterCommand("version-get");
} catch (...) {
......
......@@ -317,6 +317,18 @@ private:
commandConfigBackendPullHandler(const std::string& command,
isc::data::ConstElementPtr args);
/// @brief handler for processing 'status-get' command
///
/// This handler processes status-get command, which retrieves
/// the server process information i.e. the pid and returns it in response.
///
/// @param command (ignored)
/// @param args (ignored)
/// @return process information wrapped in a response
isc::data::ConstElementPtr
commandStatusGetHandler(const std::string& command,
isc::data::ConstElementPtr args);
/// @brief Reclaims expired IPv4 leases and reschedules timer.
///
/// This is a wrapper method for @c AllocEngine::reclaimExpiredLeases4.
......
......@@ -497,6 +497,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) {
EXPECT_TRUE(command_list.find("\"statistic-sample-age-set-all\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-sample-count-set\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-sample-count-set-all\"") != string::npos);
EXPECT_TRUE(command_list.find("\"status-get\"") != string::npos);
EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
// Ok, and now delete the server. It should deregister its commands.
......@@ -1026,6 +1027,18 @@ TEST_F(CtrlChannelDhcpv4SrvTest, serverTagGet) {
expected = "{ \"arguments\": { \"server-tag\": \"foobar\" }, \"result\": 0 }";
}
// This test verifies that the DHCP server handles status-get commands
TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) {
createUnixChannelServer();
std::string response;
// Send the version-get command
sendUnixCommand("{ \"command\": \"status-get\" }", response);
EXPECT_TRUE(response.find("\"result\": 0") != string::npos);
EXPECT_TRUE(response.find("\"pid\": ") != string::npos);
}
// This test verifies that the DHCP server handles config-backend-pull command
TEST_F(CtrlChannelDhcpv4SrvTest, configBackendPull) {
createUnixChannelServer();
......
......@@ -574,6 +574,16 @@ ControlledDhcpv6Srv::commandConfigBackendPullHandler(const std::string&,
"On demand configuration update successful."));
}
ConstElementPtr
ControlledDhcpv6Srv::commandStatusGetHandler(const string&,
ConstElementPtr /*args*/) {
ElementPtr status = Element::createMap();
status->set("pid", Element::create(static_cast<int>(getpid())));
// TODO...
return (createAnswer(0, status));
}
isc::data::ConstElementPtr
ControlledDhcpv6Srv::processCommand(const std::string& command,
isc::data::ConstElementPtr args) {
......@@ -634,6 +644,8 @@ ControlledDhcpv6Srv::processCommand(const std::string& command,
} else if (command == "config-backend-pull") {
return (srv->commandConfigBackendPullHandler(command, args));
} else if (command == "status-get") {
return (srv->commandStatusGetHandler(command, args));
}
return (isc::config::createAnswer(1, "Unrecognized command:"
......@@ -896,6 +908,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port,
CommandMgr::instance().registerCommand("shutdown",
boost::bind(&ControlledDhcpv6Srv::commandShutdownHandler, this, _1, _2));
CommandMgr::instance().registerCommand("status-get",
boost::bind(&ControlledDhcpv6Srv::commandStatusGetHandler, this, _1, _2));
CommandMgr::instance().registerCommand("version-get",
boost::bind(&ControlledDhcpv6Srv::commandVersionGetHandler, this, _1, _2));
......@@ -973,6 +988,7 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all");
CommandMgr::instance().deregisterCommand("statistic-sample-count-set");
CommandMgr::instance().deregisterCommand("statistic-sample-count-set-all");
CommandMgr::instance().deregisterCommand("status-get");
CommandMgr::instance().deregisterCommand("version-get");
} catch (...) {
......
......@@ -316,6 +316,18 @@ private:
commandConfigBackendPullHandler(const std::string& command,
isc::data::ConstElementPtr args);
/// @brief handler for processing 'status-get' command
///
/// This handler processes status-get command, which retrieves
/// the server process information i.e. the pid and returns it in response.
///
/// @param command (ignored)
/// @param args (ignored)
/// @return process information wrapped in a response
isc::data::ConstElementPtr
commandStatusGetHandler(const std::string& command,
isc::data::ConstElementPtr args);
/// @brief Reclaims expired IPv6 leases and reschedules timer.
///
/// This is a wrapper method for @c AllocEngine::reclaimExpiredLeases6.
......
......@@ -516,6 +516,7 @@ TEST_F(CtrlDhcpv6SrvTest, commandsRegistration) {
EXPECT_TRUE(command_list.find("\"statistic-sample-age-set-all\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-sample-count-set\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-sample-count-set-all\"") != string::npos);
EXPECT_TRUE(command_list.find("\"status-get\"") != string::npos);
EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
// Ok, and now delete the server. It should deregister its commands.
......@@ -918,6 +919,18 @@ TEST_F(CtrlChannelDhcpv6SrvTest, getVersion) {
EXPECT_TRUE(response.find("GTEST_VERSION") != string::npos);
}
// This test verifies that the DHCP server handles status-get commands
TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) {
createUnixChannelServer();
std::string response;
// Send the version-get command
sendUnixCommand("{ \"command\": \"status-get\" }", response);
EXPECT_TRUE(response.find("\"result\": 0") != string::npos);
EXPECT_TRUE(response.find("\"pid\": ") != string::npos);
}
// This test verifies that the DHCP server handles server-tag-get command
TEST_F(CtrlChannelDhcpv6SrvTest, serverTagGet) {
createUnixChannelServer();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment