]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3223] fixed status-get when no lease manager is available
authorRazvan Becheriu <razvan@isc.org>
Fri, 17 May 2024 11:54:26 +0000 (14:54 +0300)
committerRazvan Becheriu <razvan@isc.org>
Mon, 20 May 2024 18:36:29 +0000 (18:36 +0000)
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/lib/dhcpsrv/lease_mgr_factory.cc

index 15e49b52ad62e385d21d6a7ac68d2dc4349d126f..0b30f94cd79843276f9c1a5dd7018acc6a55a406 100644 (file)
@@ -15,6 +15,7 @@
 #include <dhcp/libdhcp++.h>
 #include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
@@ -1269,6 +1270,27 @@ TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) {
     EXPECT_EQ(3, found_queue_stats->size());
 }
 
+// Check that status is returned even if LeaseMgr and HostMgr are not created.
+TEST_F(CtrlChannelDhcpv4SrvTest, noManagers) {
+    // Send the status-get command.
+    createUnixChannelServer();
+    LeaseMgrFactory::destroy();
+    HostMgr::create();
+    string response_text;
+    sendUnixCommand(R"({ "command": "status-get" })", response_text);
+    ConstElementPtr response;
+    ASSERT_NO_THROW(response = Element::fromJSON(response_text));
+    ASSERT_TRUE(response);
+    ASSERT_EQ(Element::map, response->getType());
+    ConstElementPtr result(response->get("result"));
+    ASSERT_TRUE(result);
+    ASSERT_EQ(Element::integer, result->getType());
+    EXPECT_EQ(0, result->intValue());
+    ConstElementPtr arguments(response->get("arguments"));
+    ASSERT_TRUE(arguments);
+    ASSERT_EQ(Element::map, arguments->getType());
+}
+
 // Checks that socket status exists in status-get responses.
 TEST_F(CtrlChannelDhcpv4SrvTest, statusGetSockets) {
     // Create dummy interfaces to test socket status.
index 95e6de51da60bf01cbf9cda5900b6e59183c1c5b..224b4f32bf9e5f09c78768b5755bfbf0eaa850ec 100644 (file)
@@ -820,8 +820,8 @@ ControlledDhcpv6Srv::commandStatusGetHandler(const string&,
         status->set("multi-threading-enabled", Element::create(false));
     }
 
-    status->set("extended-info-tables",
-                Element::create(LeaseMgrFactory::instance().getExtendedInfoTablesEnabled()));
+    status->set("extended-info-tables", Element::create(
+                    CfgMgr::instance().getCurrentCfg()->getCfgDbAccess()->getExtendedInfoTablesEnabled()));
 
     // Iterate through the interfaces and get all the errors.
     ElementPtr socket_errors(Element::createList());
index 98aed2d7702d081ab42e786d9df5c8ff734ec72d..c8f5c873001b465676914067a10d7d3ce274311b 100644 (file)
@@ -13,6 +13,7 @@
 #include <dhcp/libdhcp++.h>
 #include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/host_mgr.h>
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcp6/ctrl_dhcp6_srv.h>
@@ -1171,6 +1172,27 @@ TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) {
     EXPECT_EQ(3, found_queue_stats->size());
 }
 
+// Check that status is returned even if LeaseMgr and HostMgr are not created.
+TEST_F(CtrlChannelDhcpv6SrvTest, noManagers) {
+    // Send the status-get command.
+    createUnixChannelServer();
+    LeaseMgrFactory::destroy();
+    HostMgr::create();
+    string response_text;
+    sendUnixCommand(R"({ "command": "status-get" })", response_text);
+    ConstElementPtr response;
+    ASSERT_NO_THROW(response = Element::fromJSON(response_text));
+    ASSERT_TRUE(response);
+    ASSERT_EQ(Element::map, response->getType());
+    ConstElementPtr result(response->get("result"));
+    ASSERT_TRUE(result);
+    ASSERT_EQ(Element::integer, result->getType());
+    EXPECT_EQ(0, result->intValue());
+    ConstElementPtr arguments(response->get("arguments"));
+    ASSERT_TRUE(arguments);
+    ASSERT_EQ(Element::map, arguments->getType());
+}
+
 // Checks that socket status exists in status-get responses.
 TEST_F(CtrlChannelDhcpv6SrvTest, statusGetSockets) {
     // Create dummy interfaces to test socket status.
index 548b27cdf41bf96a7ac3ee98d7156f275eda1a05..0cb9d019ad33fa4ebba217d33ddf29549a6790ac 100644 (file)
@@ -52,7 +52,6 @@ LeaseMgrFactory::create(const std::string& dbaccess) {
                   "contain the 'type' keyword");
     }
 
-
     // Yes, check what it is.
     if (parameters[type] == string("mysql")) {
 #ifdef HAVE_MYSQL