]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1041] Checkpoint: created status-get returning pid (only)
authorFrancis Dupont <fdupont@isc.org>
Thu, 5 Dec 2019 14:48:02 +0000 (15:48 +0100)
committerMarcin Siodelski <marcin@isc.org>
Fri, 13 Dec 2019 15:54:14 +0000 (16:54 +0100)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.h
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc

index 5618e231fffa8c09b52aeeef8de58a871b126939..65bd796470d693974f524ca37b5b869c3c480cb3 100644 (file)
@@ -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 (...) {
index d67501da50f2d8a8b958be621a6665ec98f60676..49ffdff55199aebe9c2559125a3ffb76cd6dcf9d 100644 (file)
@@ -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.
index 029055ac3d80a8a5fbc45dc675435ef944959917..0196d9725a7990a29b2a7c94bec98e3fd7f43105 100644 (file)
@@ -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();
index 51464430612d0cff0281299a534c6dc7e1f8a165..fc8a3176b2deb0acfd7ed904bf2264d784132dba 100644 (file)
@@ -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 (...) {
index fbe72523374a2424e7685c6deab8f2e54f9fefed..12983d1875d8bcf30fad743c5ad0415208f72047 100644 (file)
@@ -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.
index 44890b1b2ca378122e417486a3b84860f647db3d..4587b556de302d4a92faddba1c978042d7c5a44e 100644 (file)
@@ -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();