#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp4/json_config_parser.h>
+#include <dhcpsrv/db_type.h>
#include <dhcpsrv/parsers/client_class_def_parser.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
- DbAccessParser parser(CfgDbAccess::LEASE_DB);
+ DbAccessParser parser(DBType::LEASE_DB);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
if (config_pair.first == "hosts-database") {
- DbAccessParser parser(CfgDbAccess::HOSTS_DB);
+ DbAccessParser parser(DBType::HOSTS_DB);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
if (config_pair.first == "hosts-databases") {
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
- for (size_t i = 0; i < config_pair.second->size(); ++i) {
- DbAccessParser parser(CfgDbAccess::HOSTS_DB + i);
- parser.parse(cfg_db_access, config_pair.second->get(i));
+ DbAccessParser parser(DBType::HOSTS_DB);
+ auto list = config_pair.second->listValue();
+ for (auto it : list) {
+ parser.parse(cfg_db_access, it);
}
continue;
}
ConstCfgDbAccessPtr cfgdb =
CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
ASSERT_TRUE(cfgdb);
- const std::vector<std::string>& hal = cfgdb->getHostDbAccessStringList();
+ const std::list<std::string>& hal = cfgdb->getHostDbAccessStringList();
ASSERT_EQ(2, hal.size());
// Keywords are in alphabetical order
- EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest", hal[0]);
- EXPECT_EQ("name=keatest2 password=keatest type=mysql user=keatest", hal[1]);
+ EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest", hal.front());
+ EXPECT_EQ("name=keatest2 password=keatest type=mysql user=keatest", hal.back());
}
// This test checks comments. Please keep it last.
#include <dhcp/iface_mgr.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/db_type.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/timer_mgr.h>
// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
- DbAccessParser parser(CfgDbAccess::LEASE_DB);
+ DbAccessParser parser(DBType::LEASE_DB);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
if (config_pair.first == "hosts-database") {
- DbAccessParser parser(CfgDbAccess::HOSTS_DB);
+ DbAccessParser parser(DBType::HOSTS_DB);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
- // For now only support empty or singleton, ignoring extra entries.
if (config_pair.first == "hosts-databases") {
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
- for (size_t i = 0; i < config_pair.second->size(); ++i) {
- DbAccessParser parser(CfgDbAccess::HOSTS_DB + i);
- parser.parse(cfg_db_access, config_pair.second->get(i));
+ DbAccessParser parser(DBType::HOSTS_DB);
+ auto list = config_pair.second->listValue();
+ for (auto it : list) {
+ parser.parse(cfg_db_access, it);
}
continue;
}
ConstCfgDbAccessPtr cfgdb =
CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
ASSERT_TRUE(cfgdb);
- const std::vector<std::string>& hal = cfgdb->getHostDbAccessStringList();
+ const std::list<std::string>& hal = cfgdb->getHostDbAccessStringList();
ASSERT_EQ(2, hal.size());
// Keywords are in alphabetical order
- EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest", hal[0]);
- EXPECT_EQ("name=keatest2 password=keatest type=mysql user=keatest", hal[1]);
+ EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest", hal.front());
+ EXPECT_EQ("name=keatest2 password=keatest type=mysql user=keatest", hal.back());
}
// This test checks comments. Please keep it last.
libkea_dhcpsrv_la_SOURCES += database_connection.cc database_connection.h
libkea_dhcpsrv_la_SOURCES += db_exceptions.h
libkea_dhcpsrv_la_SOURCES += db_log.cc db_log.h
+libkea_dhcpsrv_la_SOURCES += db_type.h
libkea_dhcpsrv_la_SOURCES += dhcp4o6_ipc.cc dhcp4o6_ipc.h
libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
libkea_dhcpsrv_la_SOURCES += dhcpsrv_db_log.cc dhcpsrv_db_log.h
daemon.h \
database_connection.h \
db_exceptions.h \
+ db_type.h \
dhcp4o6_ipc.h \
dhcpsrv_log.h \
host.h \
#include <config.h>
#include <dhcpsrv/cfg_db_access.h>
+#include <dhcpsrv/db_type.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
namespace dhcp {
CfgDbAccess::CfgDbAccess()
- : appended_parameters_(), db_access_(2) {
- db_access_[LEASE_DB] = "type=memfile";
+ : appended_parameters_(), lease_db_access_("type=memfile"),
+ host_db_access_() {
}
std::string
CfgDbAccess::getLeaseDbAccessString() const {
- return (getAccessString(db_access_[LEASE_DB]));
+ return (getAccessString(lease_db_access_));
}
std::string
CfgDbAccess::getHostDbAccessString() const {
- return (getAccessString(db_access_[HOSTS_DB]));
+ if (host_db_access_.empty()) {
+ return ("");
+ } else {
+ return (getAccessString(host_db_access_.front()));
+ }
}
-std::vector<std::string>
+std::list<std::string>
CfgDbAccess::getHostDbAccessStringList() const {
- std::vector<std::string> ret;
- for (size_t idx = HOSTS_DB; idx < db_access_.size(); ++idx) {
- if (!db_access_[idx].empty()) {
- ret.push_back(getAccessString(db_access_[idx]));
+ std::list<std::string> ret;
+ for (const std::string& dbaccess : host_db_access_) {
+ if (!dbaccess.empty()) {
+ ret.push_back(getAccessString(dbaccess));
}
}
return (ret);
// Recreate host data source.
HostMgr::create();
- auto host_db_access_list = getHostDbAccessStringList();
- for (auto it = host_db_access_list.begin();
- it != host_db_access_list.end(); ++it) {
- HostMgr::addSource(*it);
+ std::list<std::string> host_db_access_list = getHostDbAccessStringList();
+ for (std::string& hds : host_db_access_list) {
+ HostMgr::addBackend(hds);
}
// Check for a host cache.
- HostMgr::checkCacheSource(true);
+ HostMgr::checkCacheBackend(true);
}
std::string
#include <cc/cfg_to_element.h>
#include <boost/shared_ptr.hpp>
#include <string>
-#include <vector>
+#include <list>
namespace isc {
namespace dhcp {
/// passed to the @ref isc::dhcp::LeaseMgrFactory::create function.
class CfgDbAccess {
public:
- /// @brief Specifies the database types
- static const size_t LEASE_DB = 0;
- static const size_t HOSTS_DB = 1;
-
/// @brief Constructor.
CfgDbAccess();
///
/// @param lease_db_access New lease database access string.
void setLeaseDbAccessString(const std::string& lease_db_access) {
- db_access_[LEASE_DB] = lease_db_access;
+ lease_db_access_ = lease_db_access;
}
/// @brief Retrieves host database access string.
/// @brief Sets host database access string.
///
/// @param host_db_access New host database access string.
- void setHostDbAccessString(const std::string& host_db_access) {
- db_access_[HOSTS_DB] = host_db_access;
+ /// @param front Add at front if true, at back if false (default).
+ void setHostDbAccessString(const std::string& host_db_access,
+ bool front = false) {
+ if (front) {
+ host_db_access_.push_front(host_db_access);
+ } else {
+ host_db_access_.push_back(host_db_access);
+ }
}
/// @brief Retrieves host database access string.
///
/// @return Database access strings with additional parameters
/// specified with @ref CfgDbAccess::setAppendedParameters
- std::vector<std::string> getHostDbAccessStringList() const;
-
- /// @brief Pushes host database access string.
- ///
- /// @param db_access New host database access string.
- void pushHostDbAccessString(const std::string& db_access) {
- db_access_.push_back(db_access);
- }
+ std::list<std::string> getHostDbAccessStringList() const;
/// @brief Creates instance of lease manager and host data sources
/// according to the configuration specified.
/// strings.
std::string appended_parameters_;
- /// @brief Holds database access strings.
- std::vector<std::string> db_access_;
+ /// @brief Holds lease database access string.
+ std::string lease_db_access_;
+
+ /// @brief Holds host database access strings.
+ std::list<std::string> host_db_access_;
};
///
/// @result a pointer to a configuration
virtual isc::data::ElementPtr toElement() const {
- return (CfgDbAccess::toElementDbAccessString(db_access_[LEASE_DB]));
+ return (CfgDbAccess::toElementDbAccessString(lease_db_access_));
}
};
/// @result a pointer to a configuration
virtual isc::data::ElementPtr toElement() const {
isc::data::ElementPtr result = isc::data::Element::createList();
- for (size_t idx = HOSTS_DB; idx < db_access_.size(); ++idx) {
+ for (const std::string& dbaccess : host_db_access_) {
isc::data::ElementPtr entry =
- CfgDbAccess::toElementDbAccessString(db_access_[idx]);
+ CfgDbAccess::toElementDbAccessString(dbaccess);
if (entry->size() > 0) {
result->add(entry);
}
For details, see @ref isc::dhcp::CqlConnection::openDatabase().
+ @section dhcpdb-host Host Backends.
+
+ Host backends (known also as host data sources) are similar to lease
+ backends with a few differences:
+
+ - host backends are optional (so it is allowed to have none) because
+ the first source of host reservations is the server configuration,
+ others are alternate backends.
+
+ - there may be more than one host backend. In such a case for lookups
+ returning a collection all results are appended, for lookups returning
+ at most one entry the first found is returned. Add operation is submitted
+ to all alternate backends which can ignore it, add the entry or throw
+ if the new entry conflicts with an already existing one. Delete
+ operations are submitted in sequence to all alternate backends until
+ one finds the entry, deletes it and returns true.
+
+ - the first alternate backend can be a cache (host cache hook library
+ is a premium feature) which avoids to lookup slow databases.
+ For subnet ID and identifier negative caching is optionally supported.
+
*/
--- /dev/null
+// 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 DB_TYPE_H
+#define DB_TYPE_H
+
+namespace isc {
+namespace dhcp {
+
+/// @brief Specifies the database type.
+enum class DBType {
+ LEASE_DB = 1,
+ HOSTS_DB = 2
+};
+
+} // namespace isc
+} // namespace dhcp
+
+#endif
/// @brief Sets the negative cached flag.
///
- /// @param negative sets whether this is a negative cached host.
+ /// @param negative sets whether this is a negative cached host,
+ /// i.e. a fake host in the cache which indicates non-existence
+ /// and avoids to lookup in a slow backend.
void setNegative(bool negative) {
negative_ = negative;
}
/// @brief Return the negative cache flag value.
+ /// When true standard lookup methods return null host pointer instead.
bool getNegative() const {
return (negative_);
}
return (false);
}
map_.insert(pair<string, Factory>(db_type, factory));
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
+ .arg(db_type);
return (true);
}
auto index = map_.find(db_type);
if (index != map_.end()) {
map_.erase(index);
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER)
+ .arg(db_type);
return (true);
} else {
return (false);
}
void
-HostMgr::addSource(const std::string& access) {
+HostMgr::addBackend(const std::string& access) {
HostDataSourceFactory::add(getHostMgrPtr()->alternate_sources_, access);
}
bool
-HostMgr::delSource(const std::string& db_type) {
+HostMgr::delBackend(const std::string& db_type) {
return (HostDataSourceFactory::del(getHostMgrPtr()->alternate_sources_, db_type));
}
void
-HostMgr::delAllSources() {
+HostMgr::delAllBackends() {
getHostMgrPtr()->alternate_sources_.clear();
}
}
bool
-HostMgr::checkCacheSource(bool logging) {
+HostMgr::checkCacheBackend(bool logging) {
if (getHostMgrPtr()->cache_ptr_) {
return (true);
}
ConstHostCollection
HostMgr::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
ConstHostCollection hosts = getCfgHosts()->getAll(hwaddr, duid);
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- ConstHostCollection hosts_plus = (*it)->getAll(hwaddr, duid);
+ for (auto source : alternate_sources_) {
+ ConstHostCollection hosts_plus = source->getAll(hwaddr, duid);
hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
}
return (hosts);
ConstHostCollection hosts = getCfgHosts()->getAll(identifier_type,
identifier_begin,
identifier_len);
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
+ for (auto source : alternate_sources_) {
ConstHostCollection hosts_plus =
- (*it)->getAll(identifier_type, identifier_begin, identifier_len);
+ source->getAll(identifier_type, identifier_begin, identifier_len);
hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
}
return (hosts);
ConstHostCollection
HostMgr::getAll4(const IOAddress& address) const {
ConstHostCollection hosts = getCfgHosts()->getAll4(address);
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- ConstHostCollection hosts_plus = (*it)->getAll4(address);
+ for (auto source : alternate_sources_) {
+ ConstHostCollection hosts_plus = source->getAll4(address);
hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
}
return (hosts);
.arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
.arg(duid ? duid->toText() : "(duid)");
for (auto it = alternate_sources_.begin();
- !host && it != alternate_sources_.end(); ++it) {
+ !host && // stop at first found
+ it != alternate_sources_.end(); ++it) {
if (hwaddr) {
host = (*it)->get4(subnet_id, hwaddr, DuidPtr());
}
.arg(subnet_id)
.arg(Host::getIdentifierAsText(identifier_type, identifier_begin,
identifier_len));
- // @todo: remove this
- if (negative_caching_) {
- cacheNegative(subnet_id, SubnetID(0),
- identifier_type, identifier_begin, identifier_len);
- }
- return (host);
+ return (ConstHostPtr());
}
ConstHostPtr
identifier_begin, identifier_len);
if (host && host->getNegative()) {
return (ConstHostPtr());
+ } else if (!host && negative_caching_) {
+ cacheNegative(subnet_id, SubnetID(0),
+ identifier_type, identifier_begin, identifier_len);
}
return (host);
}
.arg(subnet_id)
.arg(address.toText());
for (auto it = alternate_sources_.begin();
- !host && it != alternate_sources_.end(); ++it) {
+ !host && // stop at first found
+ it != alternate_sources_.end(); ++it) {
host = (*it)->get4(subnet_id, address);
if (host && cache_ptr_ && (it != alternate_sources_.begin())) {
cache(host);
.arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)");
for (auto it = alternate_sources_.begin();
- !host && it != alternate_sources_.end(); ++it) {
+ !host && // stop at first found
+ it != alternate_sources_.end(); ++it) {
if (duid) {
host = (*it)->get6(subnet_id, duid, HWAddrPtr());
}
.arg(prefix.toText())
.arg(static_cast<int>(prefix_len));
for (auto it = alternate_sources_.begin();
- !host && it != alternate_sources_.end(); ++it) {
+ !host && // stop at first found
+ it != alternate_sources_.end(); ++it) {
host = (*it)->get6(prefix, prefix_len);
if (host && cache_ptr_ && (it != alternate_sources_.begin())) {
cache(host);
.arg(Host::getIdentifierAsText(identifier_type, identifier_begin,
identifier_len));
- // @todo: remove this
- if (negative_caching_) {
- cacheNegative(SubnetID(0), subnet_id,
- identifier_type, identifier_begin, identifier_len);
- }
-
- return (host);
+ return (ConstHostPtr());
}
ConstHostPtr
identifier_begin, identifier_len);
if (host && host->getNegative()) {
return (ConstHostPtr());
+ } else if (!host && negative_caching_) {
+ cacheNegative(SubnetID(0), subnet_id,
+ identifier_type, identifier_begin, identifier_len);
}
return (host);
}
.arg(subnet_id)
.arg(addr.toText());
for (auto it = alternate_sources_.begin();
- !host && it != alternate_sources_.end(); ++it) {
+ !host && // stop at first found
+ it != alternate_sources_.end(); ++it) {
host = (*it)->get6(subnet_id, addr);
if (host && cache_ptr_ && (it != alternate_sources_.begin())) {
cache(host);
isc_throw(NoHostDataSourceManager, "Unable to add new host because there is "
"no hosts-database configured.");
}
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- (*it)->add(host);
+ for (auto source : alternate_sources_) {
+ source->add(host);
}
- // If no backend throws it should be cached.
+ // If no backend throws the host should be cached.
if (cache_ptr_) {
cache(host);
}
"no hosts-database configured.");
}
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- if ((*it)->del(subnet_id, addr)) {
+ for (auto source : alternate_sources_) {
+ if (source->del(subnet_id, addr)) {
return (true);
}
}
"no hosts-database configured.");
}
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- if ((*it)->del4(subnet_id, identifier_type,
- identifier_begin, identifier_len)) {
+ for (auto source : alternate_sources_) {
+ if (source->del4(subnet_id, identifier_type,
+ identifier_begin, identifier_len)) {
return (true);
}
}
"no alternate host data source present");
}
- for (auto it = alternate_sources_.begin();
- it != alternate_sources_.end(); ++it) {
- if ((*it)->del6(subnet_id, identifier_type,
- identifier_begin, identifier_len)) {
+ for (auto source : alternate_sources_) {
+ if (source->del6(subnet_id, identifier_type,
+ identifier_begin, identifier_len)) {
return (true);
}
}
///
static void create();
- /// @brief Add an alternate host data source.
+ /// @brief Add an alternate host backend (aka host data source).
///
- /// @param access Host data source access parameters for the alternate
- /// host data source. It holds "keyword=value" pairs, separated by spaces.
- /// The supported values are specific to the alternate data source in use.
+ /// @param access Host backend access parameters for the alternate
+ /// host backend. It holds "keyword=value" pairs, separated by spaces.
+ /// The supported values are specific to the alternate backend in use.
/// However, the "type" parameter will be common and it will specify which
- /// data source is to be used. Currently, no parameters are supported
+ /// backend is to be used. Currently, no parameters are supported
/// and the parameter is ignored.
- static void addSource(const std::string& access);
+ static void addBackend(const std::string& access);
- /// @brief Delete an alternate host data source.
+ /// @brief Delete an alternate host backend (aka host data source).
///
/// @param db_type_type database backend type.
/// @return true when found and removed, false when not found.
- static bool delSource(const std::string& db_type);
+ static bool delBackend(const std::string& db_type);
- /// @brief Delete all alternate host data source.
- static void delAllSources();
+ /// @brief Delete all alternate backends.
+ static void delAllBackends();
- /// @brief Check for the cache host data source.
+ /// @brief Check for the cache host backend.
///
- /// Checks if the first host data source implements
+ /// Checks if the first host backend implements
/// the cache abstract class and sets cache_ptr_.
///
/// @param logging When true (not the default) emit an informational log.
- /// @return true if the first host data source is a cache.
- static bool checkCacheSource(bool logging = false);
+ /// @return true if the first host backend is a cache.
+ static bool checkCacheBackend(bool logging = false);
/// @brief Returns a sole instance of the @c HostMgr.
///
/// This method returns a single reservation for a particular host as
/// documented in the @c BaseHostDataSource::get4 even when the
/// reservation is marked as from negative caching. This allows to
- /// overload negative caching with extra information in the user
- /// context.
+ /// monitor negative caching.
///
/// @param subnet_id Subnet identifier.
/// @param identifier_type Identifier type.
/// This method returns a host connected to the IPv6 subnet as described
/// in the @c BaseHostDataSource::get6 even when the
/// reservation is marked as from negative caching. This allows to
- /// overload negative caching with extra information in the user
- /// context.
+ /// monitor negative caching.
///
/// @param subnet_id Subnet identifier.
/// @param identifier_type Identifier type.
$NAMESPACE isc::dhcp
+% HOSTS_BACKEND_DEREGISTER deregistered backend type: %1
+This debug message is issued when a backend factory was deregistered.
+It is no longer possible to use host backend of this type.
+
+% HOSTS_BACKEND_REGISTER registered backend type: %1
+This debug message is issued when a backend factory was successfully
+registered. It is now possible to use host backend of this type.
+
% HOSTS_CFG_ADD_HOST add the host for reservations: %1
This debug message is issued when new host (with reservations) is added to
the server's configuration. The argument describes the host and its
method creating an instance of a base host data source object must be
registered (at global object initialization for built-in backends,
dynamically for backends loaded at run-time). See host_data_source_factory.cc
-for example code that registers MySQL and PostgreSQL. Note, that this instance is
-created as "alternate host data source" as opposed to the primary data
+for example code that registers MySQL and PostgreSQL. Note, that this instance
+is created as "alternate host data source" as opposed to the primary data
source which returns host reservations specified in the configuration file.
The primary data source is implemented internally in the
\ref isc::dhcp::HostMgr and uses the configuration data structures held by
#include <dhcp/option.h>
#include <dhcpsrv/cfg_db_access.h>
#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/db_type.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/host_mgr.h>
// Factory function to build the parser
-DbAccessParser::DbAccessParser(size_t db_type)
+DbAccessParser::DbAccessParser(DBType db_type)
: values_(), type_(db_type) {
}
StringPairMap::const_iterator type_ptr = values_copy.find("type");
if (type_ptr == values_copy.end()) {
isc_throw(DhcpConfigError,
- (type_ == CfgDbAccess::LEASE_DB ? "lease" : "host")
+ (type_ == DBType::LEASE_DB ? "lease" : "host")
<< " database access parameters must "
"include the keyword 'type' to determine type of database "
"to be accessed (" << database_config->getPosition() << ")");
values_.swap(values_copy);
// 5. Save the database access string in the Configuration Manager.
- if (type_ == CfgDbAccess::LEASE_DB) {
+ if (type_ == DBType::LEASE_DB) {
cfg_db->setLeaseDbAccessString(getDbAccessString());
- } else if (type_ == CfgDbAccess::HOSTS_DB) {
- cfg_db->setHostDbAccessString(getDbAccessString());
- } else if (type_ > CfgDbAccess::HOSTS_DB) {
- cfg_db->pushHostDbAccessString(getDbAccessString());
+ } else if (type_ == DBType::HOSTS_DB) {
+ cfg_db->setHostDbAccessString(getDbAccessString(), false);
}
}
/// @brief Constructor
///
/// @param db_type Specifies database type (lease or hosts)
- explicit DbAccessParser(size_t db_type);
+ explicit DbAccessParser(DBType db_type);
/// The destructor.
virtual ~DbAccessParser()
std::map<std::string, std::string> values_; ///< Stored parameter values
- size_t type_; ///< Database type (leases or hosts)
+ DBType type_; ///< Database type (leases or hosts)
};
}; // namespace dhcp
runToElementTest<CfgHostDbAccess>(expected, CfgHostDbAccess(cfg));
// If access string is empty, no parameters will be appended.
- ASSERT_NO_THROW(cfg.setHostDbAccessString(""));
- EXPECT_TRUE(cfg.getHostDbAccessString().empty());
+ CfgDbAccess cfg1;
+ ASSERT_NO_THROW(cfg1.setHostDbAccessString(""));
+ EXPECT_TRUE(cfg1.getHostDbAccessString().empty());
}
// This test verifies that it is possible to set multiple host
// database string.
TEST(CfgDbAccessTest, pushHostDbAccessString) {
+ // Push a string.
CfgDbAccess cfg;
- ASSERT_NO_THROW(cfg.setHostDbAccessString("type=mysql"));
+ ASSERT_NO_THROW(cfg.setHostDbAccessString("type=foo"));
+
+ // Push another in front.
+ ASSERT_NO_THROW(cfg.setHostDbAccessString("type=mysql", true));
EXPECT_EQ("type=mysql", cfg.getHostDbAccessString());
- // Push two other strings
- ASSERT_NO_THROW(cfg.pushHostDbAccessString("type=foo"));
- ASSERT_NO_THROW(cfg.pushHostDbAccessString("type=bar"));
+ // Push a third string.
+ ASSERT_NO_THROW(cfg.setHostDbAccessString("type=bar"));
// Check unparse
std::string expected = "[ { \"type\": \"mysql\" }, ";
runToElementTest<CfgHostDbAccess>(expected, CfgHostDbAccess(cfg));
// Check access strings
- std::vector<std::string> hal = cfg.getHostDbAccessStringList();
+ std::list<std::string> hal = cfg.getHostDbAccessStringList();
ASSERT_EQ(3, hal.size());
- EXPECT_EQ("type=mysql", hal[0]);
- EXPECT_EQ("type=foo", hal[1]);
- EXPECT_EQ("type=bar", hal[2]);
-
- // Reset the first string so it will be ignored.
- ASSERT_NO_THROW(cfg.setHostDbAccessString(""));
+ std::list<std::string>::const_iterator it = hal.cbegin();
+ ASSERT_NE(hal.cend(), it);
+ EXPECT_EQ("type=mysql", *it);
+ ASSERT_NE(hal.cend(), ++it);
+ EXPECT_EQ("type=foo", *it);
+ ASSERT_NE(hal.cend(), ++it);
+ EXPECT_EQ("type=bar", *it);
+
+ // Build a similar list with the first string empty so it will be ignored.
+ CfgDbAccess cfg1;
+ ASSERT_NO_THROW(cfg1.setHostDbAccessString(""));
+ ASSERT_NO_THROW(cfg1.setHostDbAccessString("type=foo"));
+ ASSERT_NO_THROW(cfg1.setHostDbAccessString("type=bar"));
expected = "[ { \"type\": \"foo\" }, { \"type\": \"bar\" } ]";
- runToElementTest<CfgHostDbAccess>(expected, CfgHostDbAccess(cfg));
- hal = cfg.getHostDbAccessStringList();
+ runToElementTest<CfgHostDbAccess>(expected, CfgHostDbAccess(cfg1));
+ hal = cfg1.getHostDbAccessStringList();
ASSERT_EQ(2, hal.size());
- EXPECT_EQ("type=foo", hal[0]);
- EXPECT_EQ("type=bar", hal[1]);
+ EXPECT_EQ("type=foo", hal.front());
+ EXPECT_EQ("type=bar", hal.back());
}
// Tests that lease manager can be created from a specified configuration.
// Connect to the database
try {
HostMgr::create();
- HostMgr::addSource(validCqlConnectionString());
+ HostMgr::addBackend(validCqlConnectionString());
} catch (...) {
std::cerr << "*** ERROR: unable to open database. The test"
"*** environment is broken and must be fixed before"
// Rollback should never fail, as Cassandra doesn't support transactions
// (commit and rollback are both no-op).
}
- HostMgr::delAllSources();
+ HostMgr::delAllBackends();
hdsptr_.reset();
destroyCqlSchema(false, true);
}
/// the same database.
void reopen(Universe) {
HostMgr::create();
- HostMgr::addSource(validCqlConnectionString());
+ HostMgr::addBackend(validCqlConnectionString());
hdsptr_ = HostMgr::instance().getHostDataSource();
}
};
// If it fails, print the error message.
try {
HostMgr::create();
- EXPECT_NO_THROW(HostMgr::addSource(validCqlConnectionString()));
- HostMgr::delSource("cql");
+ EXPECT_NO_THROW(HostMgr::addBackend(validCqlConnectionString()));
+ HostMgr::delBackend("cql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
std::string connection_string = validCqlConnectionString() + std::string(" ") +
std::string(VALID_TIMEOUT);
HostMgr::create();
- EXPECT_NO_THROW(HostMgr::addSource(connection_string));
- HostMgr::delSource("cql");
+ EXPECT_NO_THROW(HostMgr::addBackend(connection_string));
+ HostMgr::delBackend("cql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
// Check that wrong specification of backend throws an exception.
// (This is really a check on HostDataSourceFactory, but is convenient to
// perform here.)
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
InvalidParameter);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
// Check that invalid login data does not cause an exception, CQL should use
// default values.
- EXPECT_NO_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_NO_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)));
- EXPECT_NO_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_NO_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)));
- EXPECT_NO_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_NO_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)));
- EXPECT_NO_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_NO_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)));
// Check that invalid timeouts throw DbOperationError.
- EXPECT_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
DbOperationError);
- EXPECT_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
DbOperationError);
// Check that CQL allows the hostname to not be specified.
- EXPECT_NO_THROW(HostMgr::addSource(connectionString(CQL_VALID_TYPE,
+ EXPECT_NO_THROW(HostMgr::addBackend(connectionString(CQL_VALID_TYPE,
NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)));
// Tidy up after the test
#include <config.h>
#include <cc/command_interpreter.h>
+#include <dhcpsrv/db_type.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/testutils/mysql_schema.h>
/// @brief Constructor
///
/// @brief Keyword/value collection of database access parameters
- TestDbAccessParser(size_t type)
+ TestDbAccessParser(DBType type)
: DbAccessParser(type)
{}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::HOSTS_DB);
+ TestDbAccessParser parser(DBType::HOSTS_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid LFC Interval", parser.getDbAccessParameters(),
config);
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid timeout", parser.getDbAccessParameters(),
config);
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid port", parser.getDbAccessParameters(),
config);
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid mysql", parser.getDbAccessParameters(), config);
}
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
"name", "keatest",
NULL};
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
// First configuration string should cause a representation of that string
// to be held.
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
// Get the database access string
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid readonly parameter",
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- TestDbAccessParser parser(CfgDbAccess::LEASE_DB);
+ TestDbAccessParser parser(DBType::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
ConstElementPtr json_elements1 = Element::fromJSON(json_config1);
ConstElementPtr json_elements2 = Element::fromJSON(json_config2);
- TestDbAccessParser parser1(2);
- TestDbAccessParser parser2(3);
+ TestDbAccessParser parser1(DBType::HOSTS_DB);
+ TestDbAccessParser parser2(DBType::HOSTS_DB);
EXPECT_NO_THROW(parser1.parse(json_elements1));
EXPECT_NO_THROW(parser2.parse(json_elements2));
return (hcptr_);
};
HostDataSourceFactory::registerFactory("cache", cacheFactory);
- HostMgr::addSource("type=cache");
+ HostMgr::addBackend("type=cache");
// Host data source.
memptr_.reset(new TestHostDataSource());
return (memptr_);
};
HostDataSourceFactory::registerFactory("test", testFactory);
- HostMgr::addSource("type=test");
+ HostMgr::addBackend("type=test");
}
/// @brief Destructor.
TEST_F(HostCacheTest, identifier4) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->inserts_);
ASSERT_TRUE(memptr_);
TEST_F(HostCacheTest, identifier6) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->inserts_);
ASSERT_TRUE(memptr_);
TEST_F(HostCacheTest, address4) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->inserts_);
ASSERT_TRUE(memptr_);
TEST_F(HostCacheTest, address6) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->inserts_);
ASSERT_TRUE(memptr_);
TEST_F(HostCacheTest, negativeIdentifier4) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->adds_);
ASSERT_TRUE(memptr_);
HostPtr host = HostDataSourceUtils::initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
ASSERT_TRUE(host);
-
// Try to get it cached.
ConstHostPtr got = HostMgr::instance().get4(host->getIPv4SubnetID(),
host->getIdentifierType(),
// Try it again. There is no such host, but this time negative cache is enabled,
// so this negative response will be added to the cache.
- got = HostMgr::instance().get4Any(host->getIPv4SubnetID(),
- host->getIdentifierType(),
- &host->getIdentifier()[0],
- host->getIdentifier().size());
+ got = HostMgr::instance().get4(host->getIPv4SubnetID(),
+ host->getIdentifierType(),
+ &host->getIdentifier()[0],
+ host->getIdentifier().size());
ASSERT_FALSE(got);
EXPECT_EQ(1, hcptr_->size());
EXPECT_EQ(1, hcptr_->adds_);
EXPECT_EQ(1, hcptr_->size());
EXPECT_EQ(1, hcptr_->adds_);
EXPECT_EQ(0, hcptr_->inserts_);
+
+ // We can verify other overloads of get4() but the hwaddr/duid is
+ // not implemented by the memory test backend and the negative cache
+ // entry has no IP reservation simply because it was not known when
+ // it is created. And there is no by address negative cache because
+ // it is not allowed to create a host object, even a fake one, without
+ // an identifier. Now for performance the by identifier negative cache
+ // is critical, for by address it is better to optimize the out-of-
+ // pools case...
}
// Check negative cache feature for IPv6.
TEST_F(HostCacheTest, negativeIdentifier6) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->adds_);
ASSERT_TRUE(memptr_);
HostMgr::instance().setNegativeCaching(true);
ASSERT_TRUE(HostMgr::instance().getNegativeCaching());
- // Try it but it will be cached only the second time.
+ // Try it but it will be cached only when get6 (vs get6Any) is called.
got = HostMgr::instance().get6Any(host->getIPv6SubnetID(),
host->getIdentifierType(),
&host->getIdentifier()[0],
host->getIdentifier().size());
ASSERT_FALSE(got);
+ EXPECT_EQ(0, hcptr_->size());
+ EXPECT_EQ(0, hcptr_->adds_);
+
+ got = HostMgr::instance().get6(host->getIPv6SubnetID(),
+ host->getIdentifierType(),
+ &host->getIdentifier()[0],
+ host->getIdentifier().size());
+ ASSERT_FALSE(got);
+
+ // There is a negative cached value now.
EXPECT_EQ(1, hcptr_->size());
EXPECT_EQ(1, hcptr_->adds_);
got = HostMgr::instance().get6Any(host->getIPv6SubnetID(),
EXPECT_EQ(1, hcptr_->size());
EXPECT_EQ(1, hcptr_->adds_);
EXPECT_EQ(0, hcptr_->inserts_);
+
+ // No other tests, cf negativeIdentifier4 end comment.
}
// Check that negative caching by address is not done for IPv4.
TEST_F(HostCacheTest, negativeAddress4) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->adds_);
ASSERT_TRUE(memptr_);
TEST_F(HostCacheTest, negativeAddress6) {
// Check we have what we need.
ASSERT_TRUE(hcptr_);
- EXPECT_TRUE(HostMgr::checkCacheSource());
+ EXPECT_TRUE(HostMgr::checkCacheBackend());
EXPECT_EQ(0, hcptr_->size());
EXPECT_EQ(0, hcptr_->adds_);
ASSERT_TRUE(memptr_);
EXPECT_EQ(1, host->getIPv4SubnetID());
EXPECT_EQ("192.0.2.5", host->getIPv4Reservation().toText());
EXPECT_TRUE(host->getNegative());
+
+ // To be sure. Note we use the CfgHosts source so only this
+ // get4 overload works.
+ host = HostMgr::instance().get4(SubnetID(1), Host::IDENT_DUID,
+ &duids_[0]->getDuid()[0],
+ duids_[0]->getDuid().size());
+ EXPECT_FALSE(host);
}
void
EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
IOAddress("2001:db8:1::1"))));
EXPECT_TRUE(host->getNegative());
+
+ // To be sure. Note we use the CfgHosts source so only this
+ // get6 overload works.
+ host = HostMgr::instance().get6(SubnetID(2), Host::IDENT_HWADDR,
+ &hwaddrs_[0]->hwaddr_[0],
+ hwaddrs_[0]->hwaddr_.size());
+ EXPECT_FALSE(host);
}
void
// Connect to the database
try {
- HostMgr::addSource(test::validMySQLConnectionString());
+ HostMgr::addBackend(test::validMySQLConnectionString());
} catch (...) {
std::cerr << "*** ERROR: unable to open database. The test\n"
"*** environment is broken and must be fixed before\n"
void
MySQLHostMgrTest::TearDown() {
HostMgr::instance().getHostDataSource()->rollback();
- HostMgr::delSource("mysql");
+ HostMgr::delBackend("mysql");
test::destroyMySQLSchema();
}
// Connect to the database
try {
- HostMgr::addSource(test::validPgSQLConnectionString());
+ HostMgr::addBackend(test::validPgSQLConnectionString());
} catch (...) {
std::cerr << "*** ERROR: unable to open database. The test\n"
"*** environment is broken and must be fixed before\n"
void
PostgreSQLHostMgrTest::TearDown() {
HostMgr::instance().getHostDataSource()->rollback();
- HostMgr::delSource("postgresql");
+ HostMgr::delBackend("postgresql");
test::destroyPgSQLSchema();
}
// Connect to the database
try {
HostMgr::create();
- HostMgr::addSource(validMySQLConnectionString());
+ HostMgr::addBackend(validMySQLConnectionString());
} catch (...) {
std::cerr << "*** ERROR: unable to open database. The test\n"
"*** environment is broken and must be fixed before\n"
} catch (...) {
// Rollback may fail if backend is in read only mode. That's ok.
}
- HostMgr::delAllSources();
+ HostMgr::delAllBackends();
hdsptr_.reset();
destroyMySQLSchema();
}
/// the same database.
void reopen(Universe) {
HostMgr::create();
- HostMgr::addSource(validMySQLConnectionString());
+ HostMgr::addBackend(validMySQLConnectionString());
hdsptr_ = HostMgr::instance().getHostDataSource();
}
// If it fails, print the error message.
try {
HostMgr::create();
- EXPECT_NO_THROW(HostMgr::addSource(validMySQLConnectionString()));
- HostMgr::delSource("mysql");
+ EXPECT_NO_THROW(HostMgr::addBackend(validMySQLConnectionString()));
+ HostMgr::delBackend("mysql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
string connection_string = validMySQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
HostMgr::create();
- EXPECT_NO_THROW(HostMgr::addSource(connection_string));
- HostMgr::delSource("mysql");
+ EXPECT_NO_THROW(HostMgr::addBackend(connection_string));
+ HostMgr::delBackend("mysql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
// Check that wrong specification of backend throws an exception.
// (This is really a check on LeaseMgrFactory, but is convenient to
// perform here.)
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
InvalidParameter);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
// Check that invalid login data causes an exception.
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
DbInvalidTimeout);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
DbInvalidTimeout);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD,
VALID_TIMEOUT, INVALID_READONLY_DB)), DbInvalidReadOnly);
// Check for missing parameters
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
MYSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
NoDatabaseName);
// Connect to the database
try {
HostMgr::create();
- HostMgr::addSource(validPgSQLConnectionString());
+ HostMgr::addBackend(validPgSQLConnectionString());
} catch (...) {
std::cerr << "*** ERROR: unable to open database. The test\n"
"*** environment is broken and must be fixed before\n"
} catch (...) {
// Rollback may fail if backend is in read only mode. That's ok.
}
- HostMgr::delAllSources();
+ HostMgr::delAllBackends();
hdsptr_.reset();
destroyPgSQLSchema();
}
/// share the same database.
void reopen(Universe) {
HostMgr::create();
- HostMgr::addSource(validPgSQLConnectionString());
+ HostMgr::addBackend(validPgSQLConnectionString());
hdsptr_ = HostMgr::instance().getHostDataSource();
}
// If it fails, print the error message.
try {
HostMgr::create();
- EXPECT_NO_THROW(HostMgr::addSource(validPgSQLConnectionString()));
- HostMgr::delSource("postgresql");
+ EXPECT_NO_THROW(HostMgr::addBackend(validPgSQLConnectionString()));
+ HostMgr::delBackend("postgresql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
try {
string connection_string = validPgSQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
- EXPECT_NO_THROW(HostMgr::addSource(connection_string));
- HostMgr::delSource("postgresql");
+ EXPECT_NO_THROW(HostMgr::addBackend(connection_string));
+ HostMgr::delBackend("postgresql");
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
// Check that wrong specification of backend throws an exception.
// (This is really a check on LeaseMgrFactory, but is convenient to
// perform here.)
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
InvalidParameter);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
// Check that invalid login data causes an exception.
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
DbOpenError);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
DbInvalidTimeout);
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
DbInvalidTimeout);
// Check for missing parameters
- EXPECT_THROW(HostMgr::addSource(connectionString(
+ EXPECT_THROW(HostMgr::addBackend(connectionString(
PGSQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
NoDatabaseName);
// Close the database connection and reopen in "read-only" mode as
// specified by the "VALID_READONLY_DB" parameter.
HostMgr::create();
- HostMgr::addSource(connectionString(
+ HostMgr::addBackend(connectionString(
valid_db_type, VALID_NAME, VALID_HOST, VALID_READONLY_USER,
VALID_PASSWORD, VALID_READONLY_DB));
/// @brief Returns a host using the specified IPv6 prefix.
///
+ /// Currently not implemented.
+ ///
/// @param prefix IPv6 prefix for which the @c Host object is searched.
/// @param prefix_len IPv6 prefix length.
/// @return Const @c Host object using a specified HW address or DUID.
return (std::make_pair(0,0));
}
+ /// Specific methods.
+
/// @brief Returns store size.
+ ///
/// @return number of hosts in the store.
virtual size_t size() const;