2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 14:35:29 +00:00

[master] kea-dhcp4/6 support libreload command

Merge branch 'trac3238'
This commit is contained in:
Thomas Markwalder
2016-12-22 14:35:46 -05:00
5 changed files with 46 additions and 36 deletions

View File

@@ -116,7 +116,7 @@ will be sent to Kea and the responses received from Kea printed to standard outp
<section id="command-leases-reclaim"> <section id="command-leases-reclaim">
<title>leases-reclaim</title> <title>leases-reclaim</title>
<para> <para>
<emphasis>leases-reclaim</emphasis> command instructs the server to The <emphasis>leases-reclaim</emphasis> command instructs the server to
reclaim all expired leases immediately. The command has the following reclaim all expired leases immediately. The command has the following
JSON syntax: JSON syntax:
<screen> <screen>
@@ -140,6 +140,29 @@ will be sent to Kea and the responses received from Kea printed to standard outp
about the processing of expired leases (leases reclamation).</para> about the processing of expired leases (leases reclamation).</para>
</section> </section>
<section id="command-libreload">
<title>libreload</title>
<para>
The <emphasis>libreload</emphasis> command will first unload and then
load all currently loaded hook libraries. This is primarily intended
to allow one or more hook libraries to be replaced with newer versions
without requiring Kea servers to be reconfigured or restarted. Note
the hook libraries will be passed the same parameter values (if any)
they were passed when originally loaded.
<screen>
{
"command": "libreload",
"arguments": { }
}
</screen>
</para>
<para>
The server will respond with a result of 0 indicating success, or 1
indicating a failure.
</para>
</section> <!-- end of command-libreload -->
<section id="command-list-commands"> <section id="command-list-commands">
<title>list-commands</title> <title>list-commands</title>

View File

@@ -253,7 +253,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/)
boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler, this, _1, _2)); boost::bind(&ControlledDhcpv4Srv::commandShutdownHandler, this, _1, _2));
/// @todo: register config-reload (see CtrlDhcpv4Srv::commandConfigReloadHandler) /// @todo: register config-reload (see CtrlDhcpv4Srv::commandConfigReloadHandler)
/// @todo: register libreload (see CtrlDhcpv4Srv::commandLibReloadHandler)
CommandMgr::instance().registerCommand("libreload",
boost::bind(&ControlledDhcpv4Srv::commandLibReloadHandler, this, _1, _2));
CommandMgr::instance().registerCommand("leases-reclaim", CommandMgr::instance().registerCommand("leases-reclaim",
boost::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler, this, _1, _2)); boost::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler, this, _1, _2));
@@ -297,6 +299,7 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
// Deregister any registered commands // Deregister any registered commands
CommandMgr::instance().deregisterCommand("shutdown"); CommandMgr::instance().deregisterCommand("shutdown");
CommandMgr::instance().deregisterCommand("libreload");
CommandMgr::instance().deregisterCommand("leases-reclaim"); CommandMgr::instance().deregisterCommand("leases-reclaim");
CommandMgr::instance().deregisterCommand("statistic-get"); CommandMgr::instance().deregisterCommand("statistic-get");
CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset");

View File

@@ -223,12 +223,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
// Check that the "libreload" command will reload libraries // Check that the "libreload" command will reload libraries
TEST_F(CtrlChannelDhcpv4SrvTest, libreload) { TEST_F(CtrlChannelDhcpv4SrvTest, libreload) {
createUnixChannelServer();
// Sending commands for processing now requires a server that can process
// them.
ASSERT_NO_THROW(
server_.reset(new NakedControlledDhcpv4Srv());
);
// Ensure no marker files to start with. // Ensure no marker files to start with.
ASSERT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE)); ASSERT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE));
@@ -254,15 +249,11 @@ TEST_F(CtrlChannelDhcpv4SrvTest, libreload) {
// Now execute the "libreload" command. This should cause the libraries // Now execute the "libreload" command. This should cause the libraries
// to unload and to reload. // to unload and to reload.
std::string response;
// Use empty parameters list sendUnixCommand("{ \"command\": \"libreload\" }", response);
ElementPtr params(new isc::data::MapElement()); EXPECT_EQ("{ \"result\": 0, "
int rcode = -1; "\"text\": \"Hooks libraries successfully reloaded.\" }"
, response);
ConstElementPtr result =
ControlledDhcpv4Srv::processCommand("libreload", params);
ConstElementPtr comment = parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // Expect success
// Check that the libraries have unloaded and reloaded. The libraries are // Check that the libraries have unloaded and reloaded. The libraries are
// unloaded in the reverse order to which they are loaded. When they load, // unloaded in the reverse order to which they are loaded. When they load,

View File

@@ -280,7 +280,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port)
boost::bind(&ControlledDhcpv6Srv::commandShutdownHandler, this, _1, _2)); boost::bind(&ControlledDhcpv6Srv::commandShutdownHandler, this, _1, _2));
/// @todo: register config-reload (see CtrlDhcpv4Srv::commandConfigReloadHandler) /// @todo: register config-reload (see CtrlDhcpv4Srv::commandConfigReloadHandler)
/// @todo: register libreload (see CtrlDhcpv4Srv::commandLibReloadHandler)
CommandMgr::instance().registerCommand("libreload",
boost::bind(&ControlledDhcpv6Srv::commandLibReloadHandler, this, _1, _2));
CommandMgr::instance().registerCommand("leases-reclaim", CommandMgr::instance().registerCommand("leases-reclaim",
boost::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, _1, _2)); boost::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, _1, _2));
@@ -324,6 +326,7 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
// Deregister any registered commands // Deregister any registered commands
CommandMgr::instance().deregisterCommand("shutdown"); CommandMgr::instance().deregisterCommand("shutdown");
CommandMgr::instance().deregisterCommand("libreload");
CommandMgr::instance().deregisterCommand("leases-reclaim"); CommandMgr::instance().deregisterCommand("leases-reclaim");
CommandMgr::instance().deregisterCommand("statistic-get"); CommandMgr::instance().deregisterCommand("statistic-get");
CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset");

View File

@@ -236,14 +236,8 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
} }
// Check that the "libreload" command will reload libraries // Check that the "libreload" command will reload libraries
TEST_F(CtrlDhcpv6SrvTest, libreload) { TEST_F(CtrlChannelDhcpv6SrvTest, libreload) {
createUnixChannelServer();
// Sending commands for processing now requires a server that can process
// them.
boost::scoped_ptr<ControlledDhcpv6Srv> srv;
ASSERT_NO_THROW(
srv.reset(new ControlledDhcpv6Srv(0))
);
// Ensure no marker files to start with. // Ensure no marker files to start with.
ASSERT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE)); ASSERT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE));
@@ -269,15 +263,11 @@ TEST_F(CtrlDhcpv6SrvTest, libreload) {
// Now execute the "libreload" command. This should cause the libraries // Now execute the "libreload" command. This should cause the libraries
// to unload and to reload. // to unload and to reload.
std::string response;
// Use empty parameters list sendUnixCommand("{ \"command\": \"libreload\" }", response);
ElementPtr params(new isc::data::MapElement()); EXPECT_EQ("{ \"result\": 0, "
int rcode = -1; "\"text\": \"Hooks libraries successfully reloaded.\" }"
, response);
ConstElementPtr result =
ControlledDhcpv6Srv::processCommand("libreload", params);
ConstElementPtr comment = isc::config::parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // Expect success
// Check that the libraries have unloaded and reloaded. The libraries are // Check that the libraries have unloaded and reloaded. The libraries are
// unloaded in the reverse order to which they are loaded. When they load, // unloaded in the reverse order to which they are loaded. When they load,
@@ -296,7 +286,7 @@ TEST_F(CtrlDhcpv6SrvTest, configReload) {
srv.reset(new ControlledDhcpv6Srv(0)) srv.reset(new ControlledDhcpv6Srv(0))
); );
// Now execute the "libreload" command. This should cause the libraries // Now execute the "config-reload" command. This should cause the libraries
// to unload and to reload. // to unload and to reload.
// Use empty parameters list // Use empty parameters list