Commit cb8f8ae3 authored by Thomas Markwalder's avatar Thomas Markwalder

[5046] Fixed logger setup on set-config

src/bin/dhcp6/ctrl_dhcp6_srv.cc
    ControlledDhcpv6Srv::commandSetConfigHandler()
    - Add logger config
    - Use processConfig() directly instead of config-reload command

src/bin/dhcp6/kea_controller.cc
    configure(const std::string& file_name)
      - Remove logger config
      - Use set-config command instead of config-reload

src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
    createUnixChannelServer()
    - added call to initLogger() to revert logging to unit test logger

src/bin/dhcp6/tests/dhcp6_test_utils.cc
    BaseServerTest::~BaseServerTest() {
    - added call to initLogger() to revert logging to unit test logger
parent a9a3d0d5
......@@ -80,6 +80,12 @@ ControlledDhcpv6Srv::commandSetConfigHandler(const string&,
// Throw out the preivous staging config that may be present
CfgMgr::instance().rollback();
// Logging is a sibling element and so, has to be explicitly
// configured. We should call configureLogger even if there's no
// Logging element as this will revert it to default logging.
Daemon::configureLogger(args->get("Logging"),
CfgMgr::instance().getStagingCfg());
// Command arguments are expected to be:
// { "Dhcp6": { ... }, "Logging": { ... } }
// The Logging component is technically optional, but very recommended.
......@@ -100,10 +106,8 @@ ControlledDhcpv6Srv::commandSetConfigHandler(const string&,
message);
return (result);
}
// Now that we have extracted the configuration, reuse the reload command
// to configure the server.
return (ControlledDhcpv6Srv::processCommand("config-reload", dhcp6));
// Now we configure the server proper.
return (processConfig(dhcp6));
}
......
......@@ -72,29 +72,14 @@ void configure(const std::string& file_name) {
" Did you forget to add { } around your configuration?");
}
// Let's configure logging before applying the configuration,
// so we can log things during configuration process.
// If there's no logging element, we'll just pass NULL pointer,
// which will be handled by configureLogger().
Daemon::configureLogger(json->get("Logging"),
CfgMgr::instance().getStagingCfg());
// Get Dhcp6 component from the config
dhcp6 = json->get("Dhcp6");
if (!dhcp6) {
isc_throw(isc::BadValue, "no mandatory 'Dhcp6' entry in"
" the configuration");
}
// Use parsed JSON structures to configure the server
result = ControlledDhcpv6Srv::processCommand("config-reload", dhcp6);
result = ControlledDhcpv6Srv::processCommand("set-config", json);
if (!result) {
// Undetermined status of the configuration. This should never
// happen, but as the configureDhcp6Server returns a pointer, it is
// theoretically possible that it will return NULL.
isc_throw(isc::BadValue, "undefined result of "
"processCommand(\"config-reload\", dhcp6)");
"processCommand(\"set-config\", dhcp6)");
}
// Now check is the returned result is successful (rcode=0) or not
......@@ -117,7 +102,6 @@ void configure(const std::string& file_name) {
isc_throw(isc::BadValue, "configuration error using file '"
<< file_name << "': " << ex.what());
}
}
/// @brief Signals handler for DHCPv6 server.
......
......@@ -15,6 +15,7 @@
#include <dhcp6/ctrl_dhcp6_srv.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <hooks/hooks_manager.h>
#include <log/logger_support.h>
#include <stats/stats_mgr.h>
#include <testutils/unix_control_client.h>
......@@ -150,6 +151,11 @@ public:
ConstElementPtr answer = server_->processConfig(config);
ASSERT_TRUE(answer);
// If the configuration doesn't contain logging config, processConfig()
// will revert the logging to default (stdout). We call initLogger()
// to restore unit test logging.
isc::log::initLogger();
int status = 0;
ConstElementPtr txt = isc::config::parseAnswer(status, answer);
// This should succeed. If not, print the error message.
......@@ -385,7 +391,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, set_config) {
" \"severity\": \"INFO\", \n"
" \"debuglevel\": 0, \n"
" \"output_options\": [{ \n"
" \"output\": \"stdout\" \n"
" \"output\": \"/dev/null\" \n"
" }] \n"
" }] \n"
" } \n";
......@@ -403,7 +409,8 @@ TEST_F(CtrlChannelDhcpv6SrvTest, set_config) {
<< control_socket_footer
<< "}\n" // close dhcp6
<< ","
<< logger_txt << "}}";
<< logger_txt
<< "}}";
// Send the set-config command
std::string response;
......@@ -429,15 +436,14 @@ TEST_F(CtrlChannelDhcpv6SrvTest, set_config) {
<< socket_path_
<< control_socket_footer
<< "}\n" // close dhcp6
<< ","
<< logger_txt << "}}";
"}}";
// Send the set-config command
sendUnixCommand(os.str(), response);
// Should fail with a syntax error
EXPECT_EQ("{ \"result\": 1, "
"\"text\": \"unsupported parameter: BOGUS (<string>:12:33)\" }",
"\"text\": \"unsupported parameter: BOGUS (<string>:12:26)\" }",
response);
// Check that the config was not lost
......@@ -455,8 +461,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, set_config) {
<< subnet2
<< subnet_footer
<< "}\n" // close dhcp6
<< ","
<< logger_txt << "}}";
<< "}}";
// Send the set-config command
sendUnixCommand(os.str(), response);
......
......@@ -10,6 +10,7 @@
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <dhcp6/json_config_parser.h>
#include <dhcp/tests/pkt_captures.h>
#include <log/logger_support.h>
#include <util/pointer_util.h>
#include <cc/command_interpreter.h>
#include <stats/stats_mgr.h>
......@@ -46,6 +47,9 @@ BaseServerTest::~BaseServerTest() {
// Revert to original data directory.
CfgMgr::instance().setDataDir(original_datadir_);
// Revert to unit test logging
isc::log::initLogger();
}
Dhcpv6SrvTest::Dhcpv6SrvTest()
......
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