From: Francis Dupont Date: Tue, 8 Jan 2019 20:29:06 +0000 (+0100) Subject: [208-move-logging-from-global-objects-to-global-params] Some updates - checkpoint... X-Git-Tag: Kea-1.6.0-beta~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b94f6e62f2e1968a6344600465ad5d3baba3ed2;p=thirdparty%2Fkea.git [208-move-logging-from-global-objects-to-global-params] Some updates - checkpoint of the day --- diff --git a/src/bin/d2/tests/get_config_unittest.cc b/src/bin/d2/tests/get_config_unittest.cc index 9133081579..f1f914e754 100644 --- a/src/bin/d2/tests/get_config_unittest.cc +++ b/src/bin/d2/tests/get_config_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -103,6 +103,8 @@ public: D2GetConfigTest() : rcode_(-1) { srv_.reset(new D2CfgMgr()); + // Enforce not verbose mode. + Daemon::setVerbose(false); // Create fresh context. resetConfiguration(); } diff --git a/src/bin/d2/tests/testdata/get_config.json b/src/bin/d2/tests/testdata/get_config.json index d0905d1e27..721a07e0cb 100644 --- a/src/bin/d2/tests/testdata/get_config.json +++ b/src/bin/d2/tests/testdata/get_config.json @@ -32,6 +32,21 @@ ] }, "ip-address": "172.16.1.10", + "loggers": [ + { + "debuglevel": 0, + "name": "kea-dhcp-ddns", + "output_options": [ + { + "flush": true, + "maxsize": 204800, + "maxver": 4, + "output": "stdout" + } + ], + "severity": "INFO" + } + ], "ncr-format": "JSON", "ncr-protocol": "UDP", "port": 53001, diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 8fa7b20db4..bc06990c10 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -343,7 +343,7 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&, Daemon::configureLogger(dhcp4, CfgMgr::instance().getStagingCfg()); // Let's apply the new logging. We do it early, so we'll be able to print - // out what exactly is wrong with the new socnfig in case of problems. + // out what exactly is wrong with the new config in case of problems. CfgMgr::instance().getStagingCfg()->applyLoggingCfg(); // Log deprecated objects. diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 7fd7de4cdd..0d3e3c5e34 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -345,7 +345,7 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&, Daemon::configureLogger(dhcp6, CfgMgr::instance().getStagingCfg()); // Let's apply the new logging. We do it early, so we'll be able to print - // out what exactly is wrong with the new socnfig in case of problems. + // out what exactly is wrong with the new config in case of problems. CfgMgr::instance().getStagingCfg()->applyLoggingCfg(); // Log deprecated objects. diff --git a/src/lib/process/config_base.h b/src/lib/process/config_base.h index 32de6b3f4c..a2380f0e5c 100644 --- a/src/lib/process/config_base.h +++ b/src/lib/process/config_base.h @@ -34,7 +34,7 @@ public: /// @name Modifiers and accesors for the configuration objects. /// /// @warning References to the objects returned by accessors are only - /// valid during the lifetime of the @c SrvConfig object which + /// valid during the lifetime of the @c ConfigBase object which /// returned them. /// //@{ @@ -156,7 +156,7 @@ private: util::Optional server_tag_; }; -/// @brief Non-const pointer to the @c SrvConfig. +/// @brief Non-const pointer to the @c ConfigBase. typedef boost::shared_ptr ConfigPtr; }; diff --git a/src/lib/process/d_cfg_mgr.cc b/src/lib/process/d_cfg_mgr.cc index 21704f0f25..43596f9974 100644 --- a/src/lib/process/d_cfg_mgr.cc +++ b/src/lib/process/d_cfg_mgr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,9 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set, ConstElementPtr answer; try { + // Logging is common so factor it. + Daemon::configureLogger(config_set, context_); + // Let's call the actual implementation answer = parse(config_set, check_only); diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 234214cf58..2a8a185d7b 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -379,29 +379,27 @@ DControllerBase::configFromFile() { // so we can log things during configuration process. // Temporary storage for logging configuration - ConfigPtr storage = process_->getCfgMgr()->getContext(); + ConfigPtr storage(new ConfigBase()); // Get 'Logging' element from the config and use it to set up // logging. If there's no such element, we'll just pass NULL. Daemon::configureLogger(module_config, storage); + // Let's apply the new logging. We do it early, so we'll be able + // to print out what exactly is wrong with the new config in + // case of problems. + storage->applyLoggingCfg(); + // Log deprecated objects. - // Log obsolete objects and return an error. + // Log obsolete objects and raise an error. answer = updateConfig(module_config); - int rcode = 0; - parseAnswer(rcode, answer); - if (!rcode) { - // Configuration successful, so apply the logging configuration - // to log4cplus. - storage->applyLoggingCfg(); - } - + // In all cases the right logging configuration is in the context. + process_->getCfgMgr()->getContext()->applyLoggingCfg(); } catch (const std::exception& ex) { // Rollback logging configuration. - // We don't use CfgMgr to store logging information anymore. - // isc::dhcp::CfgMgr::instance().rollback(); + process_->getCfgMgr()->getContext()->applyLoggingCfg(); // build an error result ConstElementPtr error = createAnswer(COMMAND_ERROR, diff --git a/src/lib/process/process_messages.mes b/src/lib/process/process_messages.mes index 78b16c2e5c..b122cb6a47 100644 --- a/src/lib/process/process_messages.mes +++ b/src/lib/process/process_messages.mes @@ -53,6 +53,10 @@ may be provided. This is an informational message emitted when the Kea server is about to begin retrieving configuration data from one or more configuration backends. +% DCTL_CONFIG_DEPRECATED server configuration includes a deprecated object: %1 +This warning message is issued when the configuration includes a deprecated +object (i.e. a top level element) which will be ignored. + % DCTL_CONFIG_FILE_LOAD_FAIL %1 reason: %2 This fatal error message indicates that the application attempted to load its initial configuration from file and has failed. The service will exit. @@ -62,6 +66,10 @@ This critical error message indicates that the initial application configuration has failed. The service will start, but will not process requests until the configuration has been corrected. +% DCTL_CONFIG_OBSOLETE server configuration includes an obsolete object: %1 +This error message is issued when the configuration includes an obsolete +object (i.e. a top level element). + % DCTL_CONFIG_START parsing new configuration: %1 A debug message indicating that the application process has received an updated configuration and has passed it to its configuration manager diff --git a/src/lib/yang/adaptor_config.cc b/src/lib/yang/adaptor_config.cc index e536e6c36d..5f05d6a03d 100644 --- a/src/lib/yang/adaptor_config.cc +++ b/src/lib/yang/adaptor_config.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -622,6 +622,9 @@ AdaptorConfig::preProcess4(ConstElementPtr config) { if (config->getType() != Element::map) { isc_throw(BadValue, "preProcess4: not map: " << config->str()); } + if (config->contains("Logging")) { + isc_throw(BadValue, "preProcess4: got Logging object"); + } ConstElementPtr dhcp = config->get("Dhcp4"); if (!dhcp) { return; @@ -638,6 +641,9 @@ AdaptorConfig::preProcess6(ConstElementPtr config) { if (config->getType() != Element::map) { isc_throw(BadValue, "preProcess6: not map: " << config->str()); } + if (config->contains("Logging")) { + isc_throw(BadValue, "preProcess6: got Logging object"); + } ConstElementPtr dhcp = config->get("Dhcp6"); if (!dhcp) { return; diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h index 22c23f15ad..d849a611ee 100644 --- a/src/lib/yang/adaptor_config.h +++ b/src/lib/yang/adaptor_config.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -40,7 +40,7 @@ public: /// /// @param config The configuration. /// @throw MissingKey when a required key is missing. - /// @throw BadValue when null or not a map + /// @throw BadValue when null or not a map or deprecated Logging present. /// @note Does nothing if "Dhcp4" is not present in the map. static void preProcess4(isc::data::ConstElementPtr config); @@ -52,7 +52,7 @@ public: /// /// @param config The configuration. /// @throw MissingKey when a required key is missing. - /// @throw BadValue when null or not a map + /// @throw BadValue when null or not a map or deprecated Logging present. /// @note Does nothing if "Dhcp6" is not present in the map. static void preProcess6(isc::data::ConstElementPtr config); diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc index 8f183548a6..7f0c21c415 100644 --- a/src/lib/yang/translator_config.cc +++ b/src/lib/yang/translator_config.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -85,14 +85,6 @@ TranslatorConfig::getConfigKea4() { ElementPtr result = Element::createMap(); ElementPtr dhcp = getServerKeaDhcp4(); result->set("Dhcp4", dhcp); - ConstElementPtr loggers = dhcp->get("loggers"); - if (loggers) { - dhcp->remove("loggers"); - - ElementPtr logging = Element::createMap(); - logging->set("loggers", loggers); - result->set("Logging", logging); - } return (result); } @@ -101,14 +93,6 @@ TranslatorConfig::getConfigKea6() { ElementPtr result = Element::createMap(); ElementPtr dhcp = getServerKeaDhcp6(); result->set("Dhcp6", dhcp); - ConstElementPtr loggers = dhcp->get("loggers"); - if (loggers) { - dhcp->remove("loggers"); - - ElementPtr logging = Element::createMap(); - logging->set("loggers", loggers); - result->set("Logging", logging); - } return (result); } @@ -467,10 +451,6 @@ TranslatorConfig::setConfigKea4(ConstElementPtr elem) { if (dhcp) { setServerKeaDhcp4(dhcp); } - ConstElementPtr logging = elem->get("Logging"); - if (logging) { - setServerKeaLogging(logging); - } } void @@ -479,10 +459,6 @@ TranslatorConfig::setConfigKea6(ConstElementPtr elem) { if (dhcp) { setServerKeaDhcp6(dhcp); } - ConstElementPtr logging = elem->get("Logging"); - if (logging) { - setServerKeaLogging(logging); - } } void @@ -717,6 +693,10 @@ TranslatorConfig::setServerKeaDhcpCommon(const string& xpath, ConstElementPtr repr = Element::create(queue_ctrl->str()); setItem(xpath + "/dhcp-queue-control", repr, SR_STRING_T); } + ConstElementPtr loggers = elem->get("loggers"); + if (loggers) { + setLoggers(xpath, loggers); + } } void @@ -862,14 +842,5 @@ TranslatorConfig::setServerKeaDhcp6(ConstElementPtr elem) { } } -void -TranslatorConfig::setServerKeaLogging(ConstElementPtr elem) { - string xpath = "/" + model_ + ":config"; - ConstElementPtr loggers = elem->get("loggers"); - if (loggers) { - setLoggers(xpath, loggers); - } -} - }; // end of namespace isc::yang }; // end of namespace isc diff --git a/src/lib/yang/translator_config.h b/src/lib/yang/translator_config.h index faaca35bbe..361e51563b 100644 --- a/src/lib/yang/translator_config.h +++ b/src/lib/yang/translator_config.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -59,9 +59,9 @@ namespace yang { /// "reservations": [ ], /// , /// "server-tag": , -/// "dhcp-queue-control": { } +/// "dhcp-queue-control": { }, +/// "loggers": [ ] /// }, -/// "Logging": /// @endcode /// /// YANG syntax for kea-dhcp4-server:config is: @@ -195,9 +195,9 @@ namespace yang { /// "reservations": [ ], /// , /// "server-tag": , -/// "dhcp-queue-control": { } +/// "dhcp-queue-control": { }, +/// "loggers": [ ] /// }, -/// "Logging": /// @endcode /// /// YANG syntax for kea-dhcp6-server:config is: @@ -293,55 +293,6 @@ namespace yang { /// /// @endcode -/// JSON syntax for the logging part of kea servers is: -/// @code -/// "Logging": { -/// "loggers": [ ' -/// } -/// @endcode -/// -/// Example of Logging simple configuration: -/// @code -/// { -/// ... -/// "Logging": -/// { -/// "loggers": -/// [ -/// { -/// "name": "kea-dhcp6", -/// "output_options": -/// [ -/// { -/// "output": "stderr" -/// } -/// ], -/// "severity": "DEBUG", -/// "debuglevel": 99 -/// } -/// ] -/// } -/// } -/// @endcode -/// -/// The same configuration wrote into YANG datastore using @c setConfig() -/// with a kea server model and exported to XML format: -/// @code -/// -/// ... -/// -/// kea-dhcp6 -/// -/// -/// -/// 99 -/// DEBUG -/// -/// -/// @endcode - /// Inheritance graph between translators is: /// /// +-----------------------------------------+ @@ -531,11 +482,6 @@ protected: /// @param elem The JSON element. void setServerKeaDhcp6(isc::data::ConstElementPtr elem); - /// @brief set Logging part for kea-*:config. - /// - /// @param elem The JSON element. - void setServerKeaLogging(isc::data::ConstElementPtr elem); - /// @brief Retrieves an item and stores in the specified storage. /// /// This will attempt to retrieve an item and, if exists, will