]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#25,!14] libprocess no longer depends on libdhcpsrv
authorTomek Mrugalski <tomasz@isc.org>
Thu, 6 Sep 2018 10:35:28 +0000 (12:35 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 7 Sep 2018 14:42:08 +0000 (16:42 +0200)
 - DCfgContextBase is now derived from ConfigBase
 - Calls to CfgMgr related to loggers are replaced by Deamon calls

src/lib/process/Makefile.am
src/lib/process/d_cfg_mgr.h
src/lib/process/d_controller.cc
src/lib/process/daemon.cc
src/lib/process/tests/Makefile.am
src/lib/process/tests/logging_info_unittests.cc
src/lib/process/testutils/d_test_stubs.cc

index 5842c373564e4b9e804dbdf1ef71627313520b05..5f343eac0ac8b1d9ea1468bdb2373bfaa8af47bd 100644 (file)
@@ -57,7 +57,6 @@ libkea_process_la_LDFLAGS += -no-undefined -version-info 2:1:0
 
 libkea_process_la_LIBADD  =
 libkea_process_la_LIBADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
-libkea_process_la_LIBADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 libkea_process_la_LIBADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 libkea_process_la_LIBADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 
index e7896434732ce38f4209f6aa08eca53a8bab44da..ca83b48e9f22b5b535d553b1426110dcc7a0abd1 100644 (file)
@@ -10,6 +10,7 @@
 #include <cc/data.h>
 #include <cc/cfg_to_element.h>
 #include <cc/user_context.h>
+#include <process/config_base.h>
 #include <exceptions/exceptions.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <functional>
@@ -60,7 +61,7 @@ typedef boost::shared_ptr<DCfgContextBase> DCfgContextBasePtr;
 ///    // Restore from backup
 ///    context_ = backup_copy;
 ///
-class DCfgContextBase : public isc::data::UserContext, public isc::data::CfgToElement {
+class DCfgContextBase : public ConfigBase {
 public:
     /// @brief Indicator that a configuration parameter is optional.
     static const bool OPTIONAL = true;
index c43c0588bdc47ad69d1c93ce3e5e8eae5ffa295a..d835fd80e61e10301a1b330227fe8d578e2ae1a0 100644 (file)
@@ -7,12 +7,13 @@
 #include <config.h>
 #include <cc/command_interpreter.h>
 #include <cfgrpt/config_report.h>
-#include <dhcpsrv/cfgmgr.h>
 #include <exceptions/exceptions.h>
 #include <log/logger.h>
 #include <log/logger_support.h>
+#include <process/daemon.h>
 #include <process/d_log.h>
 #include <process/d_controller.h>
+#include <process/config_base.h>
 
 #ifdef HAVE_MYSQL
 #include <dhcpsrv/mysql_lease_mgr.h>
@@ -84,12 +85,12 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
     // It is important that we set a default logger name because this name
     // will be used when the user doesn't provide the logging configuration
     // in the Kea configuration file.
-    isc::dhcp::CfgMgr::instance().setDefaultLoggerName(bin_name_);
+    Daemon::setDefaultLoggerName(bin_name_);
 
     // Logger's default configuration depends on whether we are in the
     // verbose mode or not. CfgMgr manages the logger configuration so
     // the verbose mode is set for CfgMgr.
-    isc::dhcp::CfgMgr::instance().setVerbose(verbose_);
+    Daemon::setVerbose(verbose_);
 
     // Do not initialize logger here if we are running unit tests. It would
     // replace an instance of unit test specific logger.
@@ -161,8 +162,8 @@ DControllerBase::checkConfigOnly() {
         // messages are to be printed.
         // This is just a test, so we don't care about lockfile.
         setenv("KEA_LOCKFILE_DIR", "none", 0);
-        isc::dhcp::CfgMgr::instance().setDefaultLoggerName(bin_name_);
-        isc::dhcp::CfgMgr::instance().setVerbose(verbose_);
+        Daemon::setDefaultLoggerName(bin_name_);
+        Daemon::setVerbose(verbose_);
         Daemon::loggerInit(bin_name_.c_str(), verbose_);
 
         // Check the syntax first.
@@ -318,7 +319,9 @@ ConstElementPtr
 DControllerBase::configFromFile() {
     // Rollback any previous staging configuration. For D2, only a
     // logger configuration is used here.
-    isc::dhcp::CfgMgr::instance().rollback();
+    // We're not using cfgmgr to store logging configuration anymore.
+    // isc::dhcp::CfgMgr::instance().rollback();
+
     // Will hold configuration.
     ConstElementPtr module_config;
     // Will receive configuration result.
@@ -343,8 +346,7 @@ DControllerBase::configFromFile() {
         // so we can log things during configuration process.
 
         // Temporary storage for logging configuration
-        isc::dhcp::SrvConfigPtr storage =
-            isc::dhcp::CfgMgr::instance().getStagingCfg();
+        ConfigPtr storage = process_->getCfgMgr()->getContext();
 
         // Get 'Logging' element from the config and use it to set up
         // logging. If there's no such element, we'll just pass NULL.
@@ -364,13 +366,14 @@ DControllerBase::configFromFile() {
         if (!rcode) {
             // Configuration successful, so apply the logging configuration
             // to log4cplus.
-            isc::dhcp::CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
-            isc::dhcp::CfgMgr::instance().commit();
+            storage->applyLoggingCfg();
         }
 
     } catch (const std::exception& ex) {
         // Rollback logging configuration.
-        isc::dhcp::CfgMgr::instance().rollback();
+        // We don't use CfgMgr to store logging information anymore.
+        // isc::dhcp::CfgMgr::instance().rollback();
+
         // build an error result
         ConstElementPtr error = createAnswer(COMMAND_ERROR,
                  std::string("Configuration parsing failed: ") + ex.what());
@@ -380,7 +383,6 @@ DControllerBase::configFromFile() {
     return (answer);
 }
 
-
 void
 DControllerBase::runProcess() {
     LOG_DEBUG(dctl_logger, isc::log::DBGLVL_START_SHUT, DCTL_RUN_PROCESS)
@@ -461,14 +463,18 @@ DControllerBase::configWriteHandler(const std::string&,
     //
     // As a result, we need to extract the CA configuration from one
     // place and logging from another.
-    ConstElementPtr loginfo = isc::dhcp::CfgMgr::instance().getCurrentCfg()->toElement();
-    if (loginfo) {
-        // If there was a config stored in dhcp::CfgMgr, try to get Logging info from it.
-        loginfo = loginfo->get("Logging");
-    }
-    if (loginfo) {
-        // If there is some logging information, add it to our config.
-        cfg->set("Logging", loginfo);
+    if (!cfg->contains("Logging")) {
+        ConfigPtr base_cfg = process_->getCfgMgr()->getContext();
+
+        ConstElementPtr loginfo = base_cfg->toElement();
+        if (loginfo) {
+            // If there was a config stored in dhcp::CfgMgr, try to get Logging info from it.
+            loginfo = loginfo->get("Logging");
+        }
+        if (loginfo) {
+            // If there is some logging information, add it to our config.
+            cfg->set("Logging", loginfo);
+        }
     }
 
     try {
@@ -524,7 +530,8 @@ DControllerBase::configTestHandler(const std::string&, ConstElementPtr args) {
     // We are starting the configuration process so we should remove any
     // staging configuration that has been created during previous
     // configuration attempts.
-    isc::dhcp::CfgMgr::instance().rollback();
+    // We're not using cfgmgr to store logging information anymore.
+    // isc::dhcp::CfgMgr::instance().rollback();
 
     // Now we check the server proper.
     return (checkConfig(module_config));
index d167530e721a42f1825717b817a34e427f1cb8d5..6e76eeb45393297f5fd2e04e8b8267c6bb277fa2 100644 (file)
@@ -11,7 +11,7 @@
 #include <exceptions/exceptions.h>
 #include <log/logger_name.h>
 #include <log/logger_support.h>
-#include <process/cfg_base.h>
+#include <process/config_base.h>
 #include <util/filename.h>
 
 #include <boost/bind.hpp>
index 5fe2f0227bb655a6f273cb379170add7c9472f91..f6c11b0468c54cd690a7c6650e5cdf25106b55cd 100644 (file)
@@ -39,7 +39,6 @@ libprocess_unittests_LDADD  = $(top_builddir)/src/lib/process/testutils/libproce
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
-libprocess_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 libprocess_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
index 7768b77c16d55137325a8507c6c6a49122ee3e3d..c662bdada1f37666bfeaaa2d7a5f7372dd89a854 100644 (file)
@@ -64,7 +64,15 @@ public:
 
 // Checks if default logging configuration is correct.
 TEST_F(LoggingInfoTest, defaults) {
+
+    // We now need to set the default logger explicitly.
+    // Otherwise leftovers from pervious tests that use DController
+    // would leave the default logger set to TestBin.
+    Daemon::setDefaultLoggerName("kea");
+
     LoggingInfo info_non_verbose;
+
+    // The DStubTest framework sets up the default binary name to TestBin
     EXPECT_EQ("kea", info_non_verbose.name_);
     EXPECT_EQ(isc::log::INFO, info_non_verbose.severity_);
     EXPECT_EQ(0, info_non_verbose.debuglevel_);
index 8da62fb98101d2bf821f0c485993f26a78e34d95..8fe236f2c6c41c13ee561db0e970f387b715ecd0 100644 (file)
@@ -8,6 +8,7 @@
 #include <asiolink/io_service.h>
 #include <process/d_log.h>
 #include <process/testutils/d_test_stubs.h>
+#include <process/daemon.h>
 #include <cc/command_interpreter.h>
 
 using namespace boost::asio;
@@ -74,6 +75,7 @@ DStubProcess::configure(isc::data::ConstElementPtr config_set, bool check_only)
 }
 
 DStubProcess::~DStubProcess() {
+    Daemon::setVerbose(false);
 };
 
 //************************** DStubController *************************