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
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
......
......@@ -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;
......
......@@ -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,7 +463,10 @@ 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 (!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");
......@@ -470,6 +475,7 @@ DControllerBase::configWriteHandler(const std::string&,
// If there is some logging information, add it to our config.
cfg->set("Logging", loginfo);
}
}
try {
size = writeConfigFile(filename, cfg);
......@@ -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));
......
......@@ -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>
......
......@@ -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
......
......@@ -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_);
......
......@@ -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 *************************
......
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