From 007bd9fa8676adddab9d6a5d9102fe04ac405732 Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Thu, 6 Sep 2018 12:35:28 +0200 Subject: [PATCH] [#25,!14] libprocess no longer depends on libdhcpsrv - DCfgContextBase is now derived from ConfigBase - Calls to CfgMgr related to loggers are replaced by Deamon calls --- src/lib/process/Makefile.am | 1 - src/lib/process/d_cfg_mgr.h | 3 +- src/lib/process/d_controller.cc | 49 +++++++++++-------- src/lib/process/daemon.cc | 2 +- src/lib/process/tests/Makefile.am | 1 - .../process/tests/logging_info_unittests.cc | 8 +++ src/lib/process/testutils/d_test_stubs.cc | 2 + 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/lib/process/Makefile.am b/src/lib/process/Makefile.am index 5842c37356..5f343eac0a 100644 --- a/src/lib/process/Makefile.am +++ b/src/lib/process/Makefile.am @@ -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 diff --git a/src/lib/process/d_cfg_mgr.h b/src/lib/process/d_cfg_mgr.h index e789643473..ca83b48e9f 100644 --- a/src/lib/process/d_cfg_mgr.h +++ b/src/lib/process/d_cfg_mgr.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ typedef boost::shared_ptr 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; diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index c43c0588bd..d835fd80e6 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -7,12 +7,13 @@ #include #include #include -#include #include #include #include +#include #include #include +#include #ifdef HAVE_MYSQL #include @@ -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)); diff --git a/src/lib/process/daemon.cc b/src/lib/process/daemon.cc index d167530e72..6e76eeb453 100644 --- a/src/lib/process/daemon.cc +++ b/src/lib/process/daemon.cc @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/lib/process/tests/Makefile.am b/src/lib/process/tests/Makefile.am index 5fe2f0227b..f6c11b0468 100644 --- a/src/lib/process/tests/Makefile.am +++ b/src/lib/process/tests/Makefile.am @@ -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 diff --git a/src/lib/process/tests/logging_info_unittests.cc b/src/lib/process/tests/logging_info_unittests.cc index 7768b77c16..c662bdada1 100644 --- a/src/lib/process/tests/logging_info_unittests.cc +++ b/src/lib/process/tests/logging_info_unittests.cc @@ -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_); diff --git a/src/lib/process/testutils/d_test_stubs.cc b/src/lib/process/testutils/d_test_stubs.cc index 8da62fb981..8fe236f2c6 100644 --- a/src/lib/process/testutils/d_test_stubs.cc +++ b/src/lib/process/testutils/d_test_stubs.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include using namespace boost::asio; @@ -74,6 +75,7 @@ DStubProcess::configure(isc::data::ConstElementPtr config_set, bool check_only) } DStubProcess::~DStubProcess() { + Daemon::setVerbose(false); }; //************************** DStubController ************************* -- 2.47.2