From: Razvan Becheriu Date: Fri, 17 May 2024 11:54:26 +0000 (+0300) Subject: [#3223] fixed status-get when no lease manager is available X-Git-Tag: Kea-2.6.0~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27aaeb08c2ec27c21231fcd71b8f6ccf057d5b19;p=thirdparty%2Fkea.git [#3223] fixed status-get when no lease manager is available --- diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 15e49b52ad..0b30f94cd7 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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. diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 95e6de51da..224b4f32bf 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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()); diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 98aed2d770..c8f5c87300 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -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. diff --git a/src/lib/dhcpsrv/lease_mgr_factory.cc b/src/lib/dhcpsrv/lease_mgr_factory.cc index 548b27cdf4..0cb9d019ad 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.cc +++ b/src/lib/dhcpsrv/lease_mgr_factory.cc @@ -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