Commit 1c29e58e authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[#25,!14] libprocess code now compiles and unit-tests pass

parent 327aa101
......@@ -54,7 +54,7 @@ public:
/// @brief Compares two configuration.
///
/// @param other the other configuration to compare to
virtual bool equals(const ConfigBase& other) const;
bool equals(const ConfigBase& other) const;
/// @brief Converts to Element representation
///
......@@ -70,7 +70,7 @@ protected:
/// by descendant classes.
///
/// @param new_config this configuration will be copied to new_config
virtual void copy(ConfigBase& new_config) const;
void copy(ConfigBase& new_config) const;
private:
/// @brief Logging specific information.
......
......@@ -60,7 +60,7 @@ typedef boost::shared_ptr<DCfgContextBase> DCfgContextBasePtr;
/// // Restore from backup
/// context_ = backup_copy;
///
class DCfgContextBase : public isc::dhcp::UserContext, public isc::data::CfgToElement {
class DCfgContextBase : public isc::data::UserContext, public isc::data::CfgToElement {
public:
/// @brief Indicator that a configuration parameter is optional.
static const bool OPTIONAL = true;
......
......@@ -100,7 +100,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
try {
createPIDFile();
} catch (const dhcp::DaemonPIDExists& ex) {
} catch (const DaemonPIDExists& ex) {
LOG_FATAL(dctl_logger, DCTL_ALREADY_RUNNING)
.arg(bin_name_).arg(ex.what());
isc_throw (LaunchError, "Launch Failed: " << ex.what());
......
......@@ -9,9 +9,9 @@
#include <asiolink/io_service.h>
#include <cc/data.h>
#include <dhcpsrv/daemon.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
#include <process/daemon.h>
#include <process/d_log.h>
#include <process/d_process.h>
#include <process/io_service_signal.h>
......@@ -101,7 +101,7 @@ typedef boost::shared_ptr<DControllerBase> DControllerBasePtr;
/// NOTE: Derivations must supply their own static singleton instance method(s)
/// for creating and fetching the instance. The base class declares the instance
/// member in order for it to be available for static callback functions.
class DControllerBase : public dhcp::Daemon {
class DControllerBase : public Daemon {
public:
/// @brief Constructor
///
......
// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -6,12 +6,12 @@
#include <config.h>
#include <cc/data.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/daemon.h>
#include <process/daemon.h>
#include <process/log_parser.h>
#include <exceptions/exceptions.h>
#include <log/logger_name.h>
#include <log/logger_support.h>
#include <logging.h>
#include <process/cfg_base.h>
#include <util/filename.h>
#include <boost/bind.hpp>
......@@ -25,11 +25,15 @@
/// This file provides stub implementations that are expected to be redefined
/// in derived classes (e.g. ControlledDhcpv6Srv)
namespace isc {
namespace dhcp {
namespace process {
bool Daemon::verbose_ = false;
std::string Daemon::default_logger_name_("kea");
Daemon::Daemon()
: signal_set_(), signal_handler_(), config_file_(""), proc_name_(""),
pid_file_dir_(DHCP_DATA_DIR), pid_file_(), am_file_author_(false) {
pid_file_dir_(DATA_DIR), pid_file_(), am_file_author_(false) {
// The pid_file_dir can be overridden via environment variable
// This is primarily intended to simplify testing
......@@ -60,25 +64,25 @@ void Daemon::handleSignal() {
}
void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
const SrvConfigPtr& storage) {
const ConfigPtr& storage) {
if (log_config) {
isc::data::ConstElementPtr loggers = log_config->get("loggers");
if (loggers) {
LogConfigParser parser(storage);
parser.parseConfiguration(loggers, CfgMgr::instance().isVerbose());
parser.parseConfiguration(loggers, verbose_);
}
}
}
void
Daemon::setVerbose(bool verbose) {
CfgMgr::instance().setVerbose(verbose);
verbose_ = verbose;
}
bool
Daemon::getVerbose() const {
return (CfgMgr::instance().isVerbose());
Daemon::getVerbose() {
return (verbose_);
}
void Daemon::loggerInit(const char* name, bool verbose) {
......@@ -209,10 +213,6 @@ Daemon::createPIDFile(int pid) {
size_t
Daemon::writeConfigFile(const std::string& config_file,
isc::data::ConstElementPtr cfg) const {
if (!cfg) {
cfg = CfgMgr::instance().getCurrentCfg()->toElement();
}
if (!cfg) {
isc_throw(Unexpected, "Can't write configuration: conversion to JSON failed");
}
......
// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -8,14 +8,14 @@
#define DAEMON_H
#include <cc/data.h>
#include <dhcpsrv/srv_config.h>
#include <process/config_base.h>
#include <util/pid_file.h>
#include <util/signal_set.h>
#include <boost/noncopyable.hpp>
#include <string>
namespace isc {
namespace dhcp {
namespace process {
/// @brief Exception thrown when a the PID file points to a live PID
class DaemonPIDExists : public Exception {
......@@ -96,7 +96,7 @@ public:
/// @param log_config JSON structures that describe logging
/// @param storage configuration will be stored here
static void configureLogger(const isc::data::ConstElementPtr& log_config,
const isc::dhcp::SrvConfigPtr& storage);
const isc::process::ConfigPtr& storage);
/// @brief Sets or clears verbose mode
///
......@@ -105,12 +105,12 @@ public:
/// config file are ignored.
///
/// @param verbose specifies if verbose should be set or not
void setVerbose(const bool verbose);
static void setVerbose(const bool verbose);
/// @brief Returns if running in verbose mode
///
/// @return verbose mode
bool getVerbose() const;
static bool getVerbose();
/// @brief returns Kea version on stdout and exits.
///
......@@ -200,6 +200,19 @@ public:
/// PID of the current process is used.
void createPIDFile(int pid = 0);
/// @brief Returns default logger name.
static std::string getDefaultLoggerName() {
return (default_logger_name_);
}
/// @brief Sets the default logger name.
///
/// This name is used in cases when a user doesn't provide a configuration
/// for logger in the Kea configuration file.
static void setDefaultLoggerName(const std::string& logger) {
default_logger_name_ = logger;
}
protected:
/// @brief Invokes handler for the next received signal.
......@@ -245,6 +258,12 @@ private:
/// @brief Pointer to the PID file for this process
isc::util::PIDFilePtr pid_file_;
/// @brief Indicates whether verbose mode is turned on or not.
static bool verbose_;
/// @brief Stores default logger name
static std::string default_logger_name_;
/// @brief Flag indicating if this instance created the file
bool am_file_author_;
};
......
// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -6,7 +6,7 @@
#include <config.h>
#include <cc/data.h>
#include <dhcpsrv/logging.h>
#include <process/log_parser.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <log/logger_specification.h>
......@@ -18,9 +18,9 @@ using namespace isc::data;
using namespace isc::log;
namespace isc {
namespace dhcp {
namespace process {
LogConfigParser::LogConfigParser(const SrvConfigPtr& storage)
LogConfigParser::LogConfigParser(const ConfigPtr& storage)
:config_(storage), verbose_(false) {
if (!storage) {
isc_throw(BadValue, "LogConfigParser needs a pointer to the "
......
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -8,11 +8,12 @@
#define DHCPSRV_LOGGING_H
#include <cc/data.h>
#include <dhcpsrv/srv_config.h>
#include <process/logging_info.h>
#include <process/config_base.h>
#include <vector>
namespace isc {
namespace dhcp {
namespace process {
/// @brief Configures log4cplus by translating Kea configuration structures
///
......@@ -45,7 +46,7 @@ public:
/// @brief Constructor
///
/// @param storage parsed logging configuration will be stored here
LogConfigParser(const SrvConfigPtr& storage);
LogConfigParser(const ConfigPtr& storage);
/// @brief Parses specified configuration
///
......@@ -77,7 +78,7 @@ private:
/// @brief Configuration is stored here
///
/// LogConfigParser class uses only config_->logging_info_ field.
SrvConfigPtr config_;
ConfigPtr config_;
/// @brief Verbose mode
///
......
// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/logging_info.h>
#include <process/logging_info.h>
#include <process/daemon.h>
#include <log/logger_name.h>
using namespace isc::log;
using namespace isc::data;
namespace isc {
namespace dhcp {
namespace process {
bool
LoggingDestination::equals(const LoggingDestination& other) const {
......@@ -43,16 +43,16 @@ LoggingInfo::LoggingInfo()
: name_("kea"), severity_(isc::log::INFO), debuglevel_(0) {
// If configuration Manager is in the verbose mode, we need to modify the
// default settings.
if (CfgMgr::instance().isVerbose()) {
if (Daemon::getVerbose()) {
severity_ = isc::log::DEBUG;
debuglevel_ = 99;
}
// If the process has set the non-empty name for the default logger,
// let's use this name.
std::string logger_name = CfgMgr::instance().getDefaultLoggerName();
if (!logger_name.empty()) {
name_ = logger_name;
std::string default_logger = Daemon::getDefaultLoggerName();
if (!default_logger.empty()) {
name_ = default_logger;
}
// Add a default logging destination in case use hasn't provided a
......
// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -15,7 +15,7 @@
#include <vector>
namespace isc {
namespace dhcp {
namespace process {
/// @brief Defines single logging destination
///
......@@ -73,7 +73,7 @@ public:
/// "severity": "WARN",
/// "debuglevel": 99
/// },
class LoggingInfo : public UserContext, public isc::data::CfgToElement {
class LoggingInfo : public isc::data::UserContext, public isc::data::CfgToElement {
public:
/// @brief logging name
......@@ -133,7 +133,7 @@ public:
};
/// @brief storage for logging information in log4cplus format
typedef std::vector<isc::dhcp::LoggingInfo> LoggingInfoStorage;
typedef std::vector<isc::process::LoggingInfo> LoggingInfoStorage;
}
}
......
......@@ -3,6 +3,7 @@ SUBDIRS = .
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/process/tests\"
AM_CPPFLAGS += -DDATA_DIR="\"$(dhcp_data_dir)\""
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
AM_CXXFLAGS = $(KEA_CXXFLAGS)
......@@ -24,6 +25,8 @@ libprocess_unittests_SOURCES = d_cfg_mgr_unittests.cc
libprocess_unittests_SOURCES += d_controller_unittests.cc
libprocess_unittests_SOURCES += daemon_unittest.cc
libprocess_unittests_SOURCES += io_service_signal_unittests.cc
libprocess_unittests_SOURCES += log_parser_unittests.cc
libprocess_unittests_SOURCES += logging_info_unittests.cc
libprocess_unittests_SOURCES += run_unittests.cc
libprocess_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
......@@ -35,6 +38,7 @@ libprocess_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
libprocess_unittests_LDADD = $(top_builddir)/src/lib/process/testutils/libprocesstest.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/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
......
......@@ -9,8 +9,9 @@
#include <exceptions/exceptions.h>
#include <cc/data.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/daemon.h>
#include <dhcpsrv/logging.h>
#include <process/daemon.h>
#include <process/config_base.h>
#include <process/log_parser.h>
#include <log/logger_support.h>
#include <gtest/gtest.h>
......@@ -18,11 +19,11 @@
#include <sys/wait.h>
using namespace isc;
using namespace isc::dhcp;
using namespace isc::process;
using namespace isc::data;
namespace isc {
namespace dhcp {
namespace process {
// @brief Derived Daemon class
class DaemonImpl : public Daemon {
......@@ -92,7 +93,7 @@ TEST_F(DaemonTest, constructor) {
EXPECT_TRUE(instance2.getConfigFile().empty());
EXPECT_TRUE(instance2.getProcName().empty());
EXPECT_EQ(CfgMgr::instance().getDataDir(),instance2.getPIDFileDir());
EXPECT_EQ(std::string(DATA_DIR), instance2.getPIDFileDir());
EXPECT_TRUE(instance2.getPIDFileName().empty());
}
......@@ -265,10 +266,10 @@ TEST_F(DaemonTest, PIDFileCleanup) {
// More dedicated tests are available for LogConfigParser class.
// See logger_unittest.cc
TEST_F(DaemonTest, parsingConsoleOutput) {
CfgMgr::instance().setVerbose(false);
Daemon::setVerbose(false);
// Storage - parsed configuration will be stored here
SrvConfigPtr storage(new SrvConfig());
ConfigPtr storage(new ConfigBase());
const char* config_txt =
"{ \"loggers\": ["
......
// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
......@@ -6,16 +6,17 @@
#include <config.h>
#include <cc/data.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/logging.h>
#include <process/log_parser.h>
#include <process/process_messages.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
#include <process/d_log.h>
#include <testutils/io_utils.h>
#include <gtest/gtest.h>
using namespace isc;
using namespace isc::dhcp;
using namespace isc::process;
using namespace isc::data;
namespace {
......@@ -78,10 +79,10 @@ const int LoggingTest::TEST_MAX_VERS = 2; // More than the default of 1
// Checks that the constructor is able to process specified storage properly.
TEST_F(LoggingTest, constructor) {
SrvConfigPtr null_ptr;
ConfigPtr null_ptr;
EXPECT_THROW(LogConfigParser parser(null_ptr), BadValue);
SrvConfigPtr nonnull(new SrvConfig());
ConfigPtr nonnull(new ConfigBase());
EXPECT_NO_THROW(LogConfigParser parser(nonnull));
}
......@@ -106,7 +107,7 @@ TEST_F(LoggingTest, parsingConsoleOutput) {
" }"
"]}";
SrvConfigPtr storage(new SrvConfig());
ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
......@@ -147,7 +148,7 @@ TEST_F(LoggingTest, parsingFile) {
" }"
"]}";
SrvConfigPtr storage(new SrvConfig());
ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
......@@ -201,7 +202,7 @@ TEST_F(LoggingTest, multipleLoggers) {
" }"
"]}";
SrvConfigPtr storage(new SrvConfig());
ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
......@@ -251,7 +252,7 @@ TEST_F(LoggingTest, multipleLoggingDestinations) {
" }"
"]}";
SrvConfigPtr storage(new SrvConfig());
ConfigPtr storage(new ConfigBase());
LogConfigParser parser(storage);
......@@ -305,7 +306,7 @@ TEST_F(LoggingTest, logRotate) {
"]}";
// Create our server config container.
SrvConfigPtr server_cfg(new SrvConfig());
ConfigPtr server_cfg(new ConfigBase());
// LogConfigParser expects a list of loggers, so parse
// the JSON text and extract the "loggers" element from it
......@@ -330,7 +331,7 @@ TEST_F(LoggingTest, logRotate) {
for (int i = 1; i < TEST_MAX_VERS + 1; i++) {
// Output the big log and make sure we get the expected rotation file.
LOG_INFO(logger, DHCPSRV_CFGMGR_ADD_IFACE).arg(big_arg);
LOG_INFO(logger, DCTL_CONFIG_COMPLETE).arg(big_arg);
EXPECT_TRUE(isc::test::fileExists(logName(i).c_str()));
}
......
// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2018 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/logging_info.h>
#include <process/daemon.h>
#include <process/logging_info.h>
#include <testutils/test_to_element.h>
#include <gtest/gtest.h>
using namespace isc::dhcp;
using namespace isc::process;
using namespace isc::test;
using namespace isc::data;
......@@ -53,12 +53,12 @@ public:
/// @brief Setup the test.
virtual void SetUp() {
CfgMgr::instance().setVerbose(false);
Daemon::setVerbose(false);
}
/// @brief Clear after the test.
virtual void TearDown() {
CfgMgr::instance().setVerbose(false);
Daemon::setVerbose(false);
}
};
......@@ -94,7 +94,7 @@ TEST_F(LoggingInfoTest, defaults) {
expected = header + comment + ",\n" + begin + "INFO" + dbglvl + "0" + trailer;
runToElementTest<LoggingInfo>(expected, info_non_verbose);
CfgMgr::instance().setVerbose(true);
Daemon::setVerbose(true);
LoggingInfo info_verbose;
EXPECT_EQ("kea", info_verbose.name_);
EXPECT_EQ(isc::log::DEBUG, info_verbose.severity_);
......
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