From: Thomas Markwalder Date: Thu, 8 Dec 2016 19:56:17 +0000 (-0500) Subject: [5046] Fixed logger setup on set-config X-Git-Tag: trac5030_base~1^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb8f8ae36e8236e8181dac7dee212295d47a5778;p=thirdparty%2Fkea.git [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 --- diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 4649713015..0e493c5ade 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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)); } diff --git a/src/bin/dhcp6/kea_controller.cc b/src/bin/dhcp6/kea_controller.cc index e8d7b8251d..0e7352ca81 100644 --- a/src/bin/dhcp6/kea_controller.cc +++ b/src/bin/dhcp6/kea_controller.cc @@ -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. diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 0d66798b63..0dea9e3280 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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 (:12:33)\" }", + "\"text\": \"unsupported parameter: BOGUS (: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); diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.cc b/src/bin/dhcp6/tests/dhcp6_test_utils.cc index e7f06b7969..5c4b70d30d 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.cc +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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()