]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[208-move-logging-from-global-objects-to-global-params] Some updates - checkpoint...
authorFrancis Dupont <fdupont@isc.org>
Tue, 8 Jan 2019 20:29:06 +0000 (21:29 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 22 May 2019 22:10:24 +0000 (18:10 -0400)
12 files changed:
src/bin/d2/tests/get_config_unittest.cc
src/bin/d2/tests/testdata/get_config.json
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/process/config_base.h
src/lib/process/d_cfg_mgr.cc
src/lib/process/d_controller.cc
src/lib/process/process_messages.mes
src/lib/yang/adaptor_config.cc
src/lib/yang/adaptor_config.h
src/lib/yang/translator_config.cc
src/lib/yang/translator_config.h

index 913308157919e5018d055b5bc033793408d87d33..f1f914e754e88187a216812b21301a47ecb317d1 100644 (file)
@@ -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();
     }
index d0905d1e27d7cc07c6c1d60c74dbf757be63c399..721a07e0cbf0e4c1d2c1b13d424d776bb5b43a6b 100644 (file)
             ]
         },
         "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,
index 8fa7b20db4e82215e9dabdbd08902b000fd10cdd..bc06990c10d5eab7c9618c1f5269e156e445115d 100644 (file)
@@ -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.
index 7fd7de4cddd54bd729c3a816064760062e8aed26..0d3e3c5e34a33e0121a4fd1a4f64d525aefc0bb7 100644 (file)
@@ -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.
index 32de6b3f4cba5708627d5f1f3fcbaeee516119db..a2380f0e5c17bf0e1b348d8172d8d0ae762bbfe6 100644 (file)
@@ -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<std::string> server_tag_;
 };
 
-/// @brief Non-const pointer to the @c SrvConfig.
+/// @brief Non-const pointer to the @c ConfigBase.
 typedef boost::shared_ptr<ConfigBase> ConfigPtr;
 
 };
index 21704f0f25b02958dc27d5d87070f7a22b2eda56..43596f99743ae9b0ca18ce362b4586dd15ac2c1f 100644 (file)
@@ -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 <dhcp/libdhcp++.h>
 #include <process/d_log.h>
 #include <process/d_cfg_mgr.h>
+#include <process/daemon.h>
 #include <util/encode/hex.h>
 #include <util/strutil.h>
 
@@ -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);
 
index 234214cf589bbb2f48e4db7bb17c6c889b27b655..2a8a185d7bbf73e04b41226a65f8960c287272db 100644 (file)
@@ -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,
index 78b16c2e5c54fb2537627f8fde95de4f1c18c199..b122cb6a47700dfd58995d61a473628741319f4c 100644 (file)
@@ -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
index e536e6c36d1e5239dd0bb64f3285039f07ef6840..5f05d6a03d1728d7409d79246761c664d9a70077 100644 (file)
@@ -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;
index 22c23f15ad0673fe0fb7d2541845ed34ab06c836..d849a611ee981391be47c7b10b349b826b7e5f1c 100644 (file)
@@ -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);
 
index 8f183548a637e9df01aef50d1d4466a765b4e099..7f0c21c41567ee92d870ecef04e80fb391fec3c3 100644 (file)
@@ -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
index faaca35bbe1d69c37c41d434b782c6757ccc6a58..361e51563b3825e282de5abb54c86549bee1ffa5 100644 (file)
@@ -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": [ <list of host reservations> ],
 ///     <config-control>,
 ///     "server-tag": <server tag>,
-///     "dhcp-queue-control": { <DHCP queue control> }
+///     "dhcp-queue-control": { <DHCP queue control> },
+///     "loggers": [ <list of loggers> ]
 /// },
-/// "Logging": <logging>
 /// @endcode
 ///
 /// YANG syntax for kea-dhcp4-server:config is:
@@ -195,9 +195,9 @@ namespace yang {
 ///     "reservations": [ <list of host reservations> ],
 ///     <config-control>,
 ///     "server-tag": <server tag>,
-///     "dhcp-queue-control": { <DHCP queue control> }
+///     "dhcp-queue-control": { <DHCP queue control> },
+///     "loggers": [ <list of loggers> ]
 /// },
-/// "Logging": <logging>
 /// @endcode
 ///
 /// YANG syntax for kea-dhcp6-server:config is:
@@ -293,55 +293,6 @@ namespace yang {
 /// </config>
 /// @endcode
 
-/// JSON syntax for the logging part of kea servers is:
-/// @code
-/// "Logging": {
-///     "loggers": [ <list of 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
-/// <config xmlns="urn:ietf:params:xml:ns:yang:kea-dhcp4-server">
-///   ...
-///   <logger>
-///     <name>kea-dhcp6</name>
-///     <output-options>
-///       <option>
-///         <output>stderr</output>
-///       </option>
-///     </output-options>
-///     <debuglevel>99</debuglevel>
-///     <severity>DEBUG</severity>
-///   </logger>
-/// </config>
-/// @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