Commit 0be1868f authored by Thomas Markwalder's avatar Thomas Markwalder

[#101, !73] Addresses review comments

parent 210105df
......@@ -11,6 +11,11 @@ This message is printed when DHCPv4 server enabled an interface to be used
to receive DHCPv4 traffic. IPv4 socket on this interface will be opened once
Interface Manager starts up procedure of opening sockets.
% DHCP4_ADDING_CONFIG_DB Opening configuration database: %1
This message is printed when the DHCPv4 server is attempting to open a
configuration database. The database access string with password redacted
is logged.
% DHCP4_ALREADY_RUNNING %1 already running? %2
This is an error message that occurs when the DHCPv4 server encounters
a pre-existing PID file which contains the PID of a running process.
......
......@@ -52,6 +52,7 @@ using namespace isc::data;
using namespace isc::asiolink;
using namespace isc::hooks;
using namespace isc::process;
using namespace isc::config;
namespace {
......@@ -284,7 +285,7 @@ isc::data::ConstElementPtr
configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
bool check_only) {
if (!config_set) {
ConstElementPtr answer = isc::config::createAnswer(1,
ConstElementPtr answer = isc::config::createAnswer(CONTROL_RESULT_ERROR,
string("Can't parse NULL config"));
return (answer);
}
......@@ -547,7 +548,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
} catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
.arg(config_pair.first).arg(ex.what());
answer = isc::config::createAnswer(1, ex.what());
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
// An error occurred, so make sure that we restore original data.
rollback = true;
......@@ -555,7 +556,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
} catch (...) {
// For things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
answer = isc::config::createAnswer(1, "undefined configuration"
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
" processing error");
// An error occurred, so make sure that we restore original data.
......@@ -565,7 +566,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
if (check_only) {
rollback = true;
if (!answer) {
answer = isc::config::createAnswer(0,
answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS,
"Configuration seems sane. Control-socket, hook-libraries, and D2 "
"configuration were sanity checked, but not applied.");
}
......@@ -600,12 +601,12 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
}
catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
answer = isc::config::createAnswer(2, ex.what());
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
rollback = true;
} catch (...) {
// For things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
answer = isc::config::createAnswer(2, "undefined configuration"
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
" parsing error");
rollback = true;
}
......@@ -625,7 +626,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
getConfigSummary(SrvConfig::CFGSEL_ALL4));
// Everything was fine. Configuration is successful.
answer = isc::config::createAnswer(0, "Configuration successful.");
answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration successful.");
return (answer);
}
......@@ -635,23 +636,25 @@ bool databaseConfigConnect(const SrvConfigPtr& srv_cfg) {
ConfigBackendDHCPv4Mgr& mgr = ConfigBackendDHCPv4Mgr::instance();
mgr.delAllBackends();
// SrvConfigPtr staging_cfg = CfgMgr::instance().getStagingCfg();
// Fetch the config-control info.
ConstConfigControlInfoPtr config_ctl = srv_cfg->getConfigControlInfo();
if (!config_ctl || config_ctl->getConfigDatabases().empty()) {
// No config dbs, nothing to do.
return (false);
}
// First step is to create all of the backends.
// Iterate over the configured DBs and instantiate them.
for (auto db : config_ctl->getConfigDatabases()) {
// Good place for a log message?
mgr.addBackend(db.getAccessString());
LOG_INFO(dhcp4_logger, DHCP4_ADDING_CONFIG_DB)
.arg(db.redactedAccessString());
mgr.addBackend(db.getAccessString());
}
// Let the caller know we have opened DBs.
return (true);
}
void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /*global_scope*/) {
void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /* mutable_cfg */) {
// Close any existing CB databasess, then open all in srv_cfg (if any)
if (!databaseConfigConnect(srv_cfg)) {
......@@ -664,10 +667,10 @@ void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /*global_scope*
// Next we have to fetch the pieces we care about it and merge them
// probably in this order?
// globals
// shared networks
// subnets
// option defs
// options
// shared networks
// subnets
}
......
......@@ -59,33 +59,34 @@ configureDhcp4Server(Dhcpv4Srv&,
isc::data::ConstElementPtr config_set,
bool check_only = false);
/// @brief Attempts to the configured CB databases (if any)
/// @brief Attempts to connect to configured CB databases
///
/// This function will close all the existing CB backends. It
/// then attempt to connect to all of the CB databases in the
/// given SrvConfig (if any).
/// First, this function will close all existing CB backends. It
/// will then attempt to connect to all of the CB backends defined
/// in the given SrvConfig (if any).
///
/// It will return true if there are configured CB databases
/// false, otherwise. Any errors encountered along the way
/// It will return true if there are configured CB databases,
/// and false otherwise. Any errors encountered along the way
/// should generate throws.
///
/// @param srv_cfg Server configuration from which to get
/// the config-control information to use.
///
/// @return True if are configured CB databases, false if not.
/// @return True if there are configured CB databases, false if not.
bool
databaseConfigConnect(const SrvConfigPtr& srv_cfg);
/// @brief Fetch configuration from CB databases and merge it into the given configuration
///
/// It will call @c databaseConfigConnect passing in the given server configuration. If
/// results in open CB databases it will proceed to fetch configuration components from
/// those databases and merge them into the given server configuration.
/// It will call @c databaseConfigConnect, passing in the given server configuration. If
/// that call results in open CB databases, the function will then proceed to fetch
/// configuration components from said databases and merge them into the given server
/// configuration.
///
/// @param srv_config Server configuration to merge into
/// @param global_scope global configuration as elements
/// @param srv_cfg Server configuration into which database configuration should be merged
/// @param mutable_cfg parsed configuration from the configuration file plus default values
void
databaseConfigFetch(const SrvConfigPtr& srv_cfg, isc::data::ElementPtr /*global_scope*/);
databaseConfigFetch(const SrvConfigPtr& srv_cfg, isc::data::ElementPtr /*mutable_scope*/);
}; // end of isc::dhcp namespace
}; // end of isc namespace
......
......@@ -6265,7 +6265,7 @@ TEST_F(Dhcp4ParserTest, configControlInfoNoFactory) {
extractConfig(config);
// Should fail because "type=mysql" has no factories.
configure(config, CONTROL_RESULT_COMMAND_UNSUPPORTED,
configure(config, CONTROL_RESULT_ERROR,
"The type of the configuration backend: 'mysql' is not supported");
}
......@@ -6275,7 +6275,7 @@ TEST_F(Dhcp4ParserTest, configControlInfo) {
extractConfig(config);
// Should be able to register a backend factory for "mysql".
ASSERT_TRUE(TestConfigBackendDHCPv4Impl::
ASSERT_TRUE(TestConfigBackendDHCPv4::
registerBackendType(ConfigBackendDHCPv4Mgr::instance(),
"mysql"));
......
......@@ -19,6 +19,7 @@ libdhcpsrvtest_la_SOURCES += memory_host_data_source.cc memory_host_data_source.
libdhcpsrvtest_la_SOURCES += generic_backend_unittest.cc generic_backend_unittest.h
libdhcpsrvtest_la_SOURCES += generic_host_data_source_unittest.cc generic_host_data_source_unittest.h
libdhcpsrvtest_la_SOURCES += lease_file_io.cc lease_file_io.h
libdhcpsrvtest_la_SOURCES += test_config_backend.h
libdhcpsrvtest_la_SOURCES += test_config_backend_dhcp4.cc test_config_backend_dhcp4.h
libdhcpsrvtest_la_CXXFLAGS = $(AM_CXXFLAGS)
......
// Copyright (C) 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/.
#ifndef TEST_CONFIG_BACKEND_H
#define TEST_CONFIG_BACKEND_H
#include <config.h>
#include <database/database_connection.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
namespace isc {
namespace dhcp {
namespace test {
/// @brief Base class for implementing fake backends
template<typename ConfigBackendType>
class TestConfigBackend : public ConfigBackendType {
public:
/// @brief Constructor
///
/// @param params database connection parameters
/// @throw BadValue if parameters do not include "type"
TestConfigBackend(const db::DatabaseConnection::ParameterMap& params)
: connection_(params) {
try {
db_type_ = connection_.getParameter("type");
} catch (...) {
isc_throw(BadValue, "Backend parameters must include \"type\"");
}
try {
db_type_ = connection_.getParameter("host");
} catch (...) {
host_ = "default_host";
}
try {
port_ = boost::lexical_cast<uint16_t>(connection_.getParameter("host"));
} catch (...) {
port_ = 0;
}
}
/// @brief virtual Destructor.
virtual ~TestConfigBackend(){};
/// @brief Returns backend type.
///
/// @return string db_type name
virtual std::string getType() const { return (db_type_);
}
/// @brief Returns backend host.
///
/// @return string host
virtual std::string getHost() const {
return (host_);
}
/// @brief Returns backend port.
///
/// @return uint16_t port
virtual uint16_t getPort() const {
return (port_);
}
/// @brief Fake database connection
db::DatabaseConnection connection_;
/// @brief Back end type
std::string db_type_;
/// @brief Back end host
std::string host_;
/// @brief Back end port
uint16_t port_;
};
} // namespace test
} // namespace dhcp
} // namespace isc
#endif // TEST_CONFIG_BACKEND_H
......@@ -14,240 +14,240 @@ namespace dhcp {
namespace test {
bool
TestConfigBackendDHCPv4Impl::registerBackendType(ConfigBackendDHCPv4Mgr& mgr,
const std::string& db_type) {
TestConfigBackendDHCPv4::registerBackendType(ConfigBackendDHCPv4Mgr& mgr,
const std::string& db_type) {
return(mgr.registerBackendFactory(db_type,
[](const db::DatabaseConnection::ParameterMap& params)
-> dhcp::ConfigBackendDHCPv4Ptr {
return (TestConfigBackendDHCPv4ImplPtr(new TestConfigBackendDHCPv4Impl(params)));
return (TestConfigBackendDHCPv4Ptr(new TestConfigBackendDHCPv4(params)));
})
);
}
void
TestConfigBackendDHCPv4Impl::unregisterBackendType(ConfigBackendDHCPv4Mgr& mgr,
const std::string& db_type) {
TestConfigBackendDHCPv4::unregisterBackendType(ConfigBackendDHCPv4Mgr& mgr,
const std::string& db_type) {
mgr.unregisterBackendFactory(db_type);
}
Subnet4Ptr
TestConfigBackendDHCPv4Impl::getSubnet4(const db::ServerSelector& /* server_selector */,
const std::string& /* subnet_prefix */) const{
TestConfigBackendDHCPv4::getSubnet4(const db::ServerSelector& /* server_selector */,
const std::string& /* subnet_prefix */) const{
return (Subnet4Ptr());
}
Subnet4Ptr
TestConfigBackendDHCPv4Impl::getSubnet4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */) const {
TestConfigBackendDHCPv4::getSubnet4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */) const {
return (Subnet4Ptr());
}
Subnet4Collection
TestConfigBackendDHCPv4Impl::getAllSubnets4(const db::ServerSelector& /* server_selector */) const {
TestConfigBackendDHCPv4::getAllSubnets4(const db::ServerSelector& /* server_selector */) const {
return(subnets_);
}
Subnet4Collection
TestConfigBackendDHCPv4Impl::getModifiedSubnets4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
TestConfigBackendDHCPv4::getModifiedSubnets4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
return(subnets_);
}
SharedNetwork4Ptr
TestConfigBackendDHCPv4Impl::getSharedNetwork4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) const {
TestConfigBackendDHCPv4::getSharedNetwork4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) const {
return(SharedNetwork4Ptr());
}
SharedNetwork4Collection
TestConfigBackendDHCPv4Impl::getAllSharedNetworks4(const db::ServerSelector& /* server_selector */) const{
TestConfigBackendDHCPv4::getAllSharedNetworks4(const db::ServerSelector& /* server_selector */) const{
return(shared_networks_);
}
SharedNetwork4Collection
TestConfigBackendDHCPv4Impl::getModifiedSharedNetworks4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
TestConfigBackendDHCPv4::getModifiedSharedNetworks4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
return(shared_networks_);
}
OptionDefinitionPtr
TestConfigBackendDHCPv4Impl::getOptionDef4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) const {
TestConfigBackendDHCPv4::getOptionDef4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) const {
return (OptionDefinitionPtr());
}
OptionDefContainer
TestConfigBackendDHCPv4Impl::getAllOptionDefs4(const db::ServerSelector& /* server_selector */) const {
TestConfigBackendDHCPv4::getAllOptionDefs4(const db::ServerSelector& /* server_selector */) const {
return (option_defs_);
}
OptionDefContainer
TestConfigBackendDHCPv4Impl::getModifiedOptionDefs4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
TestConfigBackendDHCPv4::getModifiedOptionDefs4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
return (option_defs_);
}
OptionDescriptorPtr
TestConfigBackendDHCPv4Impl::getOption4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) const {
TestConfigBackendDHCPv4::getOption4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) const {
return (OptionDescriptorPtr());
}
OptionContainer
TestConfigBackendDHCPv4Impl::getAllOptions4(const db::ServerSelector& /* server_selector */) const {
TestConfigBackendDHCPv4::getAllOptions4(const db::ServerSelector& /* server_selector */) const {
return (options_);
}
OptionContainer
TestConfigBackendDHCPv4Impl::getModifiedOptions4(const db::ServerSelector& /* selector */,
const boost::posix_time::ptime& /* modification_time */) const {
TestConfigBackendDHCPv4::getModifiedOptions4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
return (options_);
}
data::StampedValuePtr
TestConfigBackendDHCPv4Impl::getGlobalParameter4(const db::ServerSelector& /* selector */,
const std::string& /* name */) const {
TestConfigBackendDHCPv4::getGlobalParameter4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) const {
return(data::StampedValuePtr());
}
data::StampedValueCollection
TestConfigBackendDHCPv4Impl::getAllGlobalParameters4(const db::ServerSelector& /* selector */) const {
TestConfigBackendDHCPv4::getAllGlobalParameters4(const db::ServerSelector& /* server_selector */) const {
return (globals_);
}
data::StampedValueCollection
TestConfigBackendDHCPv4Impl::getModifiedGlobalParameters4(const db::ServerSelector& /* selector */,
const boost::posix_time::ptime& /* modification_time */) const {
TestConfigBackendDHCPv4::getModifiedGlobalParameters4(const db::ServerSelector& /* server_selector */,
const boost::posix_time::ptime& /* modification_time */) const {
return (globals_);
}
void
TestConfigBackendDHCPv4Impl::createUpdateSubnet4(const db::ServerSelector& /* server_selector */,
const Subnet4Ptr& /* subnet */) {
TestConfigBackendDHCPv4::createUpdateSubnet4(const db::ServerSelector& /* server_selector */,
const Subnet4Ptr& /* subnet */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateSharedNetwork4(const db::ServerSelector& /* server_selector */,
const SharedNetwork4Ptr& /* shared_network */) {
TestConfigBackendDHCPv4::createUpdateSharedNetwork4(const db::ServerSelector& /* server_selector */,
const SharedNetwork4Ptr& /* shared_network */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateOptionDef4(const db::ServerSelector& /* server_selector */,
const OptionDefinitionPtr& /* option_def */) {
TestConfigBackendDHCPv4::createUpdateOptionDef4(const db::ServerSelector& /* server_selector */,
const OptionDefinitionPtr& /* option_def */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const OptionDescriptorPtr& /* option */) {
TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const OptionDescriptorPtr& /* option */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* selector */,
const std::string& /* shared_network_name */,
const OptionDescriptorPtr& /* option */) {
TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const std::string& /* shared_network_name */,
const OptionDescriptorPtr& /* option */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */,
const OptionDescriptorPtr& /* option */) {
TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */,
const OptionDescriptorPtr& /* option */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const asiolink::IOAddress& /* pool_start_address */,
const asiolink::IOAddress& /* pool_end_address */,
const OptionDescriptorPtr& /* option */) {
TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
const asiolink::IOAddress& /* pool_start_address */,
const asiolink::IOAddress& /* pool_end_address */,
const OptionDescriptorPtr& /* option */) {
}
void
TestConfigBackendDHCPv4Impl::createUpdateGlobalParameter4(const db::ServerSelector& /* server_selector */,
const data::StampedValuePtr& /* value */) {
TestConfigBackendDHCPv4::createUpdateGlobalParameter4(const db::ServerSelector& /* server_selector */,
const data::StampedValuePtr& /* value */) {
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteSubnet4(const db::ServerSelector& /* server_selector */,
const std::string& /* subnet_prefix */) {
TestConfigBackendDHCPv4::deleteSubnet4(const db::ServerSelector& /* server_selector */,
const std::string& /* subnet_prefix */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteSubnet4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */) {
TestConfigBackendDHCPv4::deleteSubnet4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteAllSubnets4(const db::ServerSelector& /* server_selector */) {
TestConfigBackendDHCPv4::deleteAllSubnets4(const db::ServerSelector& /* server_selector */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteSharedNetwork4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) {
TestConfigBackendDHCPv4::deleteSharedNetwork4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteAllSharedNetworks4(const db::ServerSelector& /* server_selector */) {
TestConfigBackendDHCPv4::deleteAllSharedNetworks4(const db::ServerSelector& /* server_selector */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteOptionDef4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) {
TestConfigBackendDHCPv4::deleteOptionDef4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteAllOptionDefs4(const db::ServerSelector& /* server_selector */) {
TestConfigBackendDHCPv4::deleteAllOptionDefs4(const db::ServerSelector& /* server_selector */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) {
TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
const uint16_t /* code */,
const std::string& /* space */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
const std::string& /* shared_network_name */,
const uint16_t /* code */,
const std::string& /* space */) {
TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
const std::string& /* shared_network_name */,
const uint16_t /* code */,
const std::string& /* space */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */,
const uint16_t /* code */,
const std::string& /* space */) {
TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
const SubnetID& /* subnet_id */,
const uint16_t /* code */,
const std::string& /* space */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
const asiolink::IOAddress& /* pool_start_address */,
const asiolink::IOAddress& /* pool_end_address */,
const uint16_t /* code */,
const std::string& /* space */) {
TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
const asiolink::IOAddress& /* pool_start_address */,
const asiolink::IOAddress& /* pool_end_address */,
const uint16_t /* code */,
const std::string& /* space */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteGlobalParameter4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) {
TestConfigBackendDHCPv4::deleteGlobalParameter4(const db::ServerSelector& /* server_selector */,
const std::string& /* name */) {
return (0);
}
uint64_t
TestConfigBackendDHCPv4Impl::deleteAllGlobalParameters4(const db::ServerSelector& /* server_selector */) {
TestConfigBackendDHCPv4::deleteAllGlobalParameters4(const db::ServerSelector& /* server_selector */) {
return (0);
}
......
......@@ -4,10 +4,15 @@
// 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/.
#ifndef TEST_CONFIG_BACKEND_DHCP4
#define TEST_CONFIG_BACKEND_DHCP4
#include <config.h>
#include <database/database_connection.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
#include <dhcpsrv/testutils/test_config_backend.h>
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
......@@ -15,71 +20,6 @@ namespace isc {
namespace dhcp {
namespace test {
/// @brief Base class for implementing fake backends
class TestConfigBackendDHCPv4 : public ConfigBackendDHCPv4 {
public:
/// @brief Constructor
///
/// @param params database connection parameters
/// @throw BadValue if parameters do not include "type"
TestConfigBackendDHCPv4(const db::DatabaseConnection::ParameterMap& params)
: connection_(params) {
try {
db_type_ = connection_.getParameter("type");
} catch (...) {
isc_throw(BadValue, "Backend parameters must include \"type\"");
}
try {
db_type_ = connection_.getParameter("host");
} catch (...) {
host_ = "default_host";
}
try {
port_ = boost::lexical_cast<uint16_t>(connection_.getParameter("host"));
} catch (...) {
port_ = 0;
}