Commit 007bd9fa authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

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