Commit 36c0a44a authored by Francis Dupont's avatar Francis Dupont

[5096] Migrated to Simple (but cql is missing)

parent 121b5403
......@@ -426,10 +426,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
} else if ((config_id.compare("next-server") == 0)) {
parser = new StringParser(config_id,
globalContext()->string_values_);
} else if (config_id.compare("lease-database") == 0) {
parser = new DbAccessParser(config_id, DbAccessParser::LEASE_DB);
} else if (config_id.compare("hosts-database") == 0) {
parser = new DbAccessParser(config_id, DbAccessParser::HOSTS_DB);
// lease-database and hosts-database have been converted to SimpleParser already.
} else if (config_id.compare("hooks-libraries") == 0) {
parser = new HooksLibrariesParser(config_id);
} else if (config_id.compare("echo-client-id") == 0) {
......@@ -572,7 +569,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
ParserCollection independent_parsers;
ParserPtr subnet_parser;
ParserPtr iface_parser;
ParserPtr leases_parser;
ParserPtr client_classes_parser;
// Some of the parsers alter the state of the system in a way that can't
......@@ -620,6 +616,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
const std::map<std::string, ConstElementPtr>& values_map =
mutable_cfg->mapValue();
BOOST_FOREACH(config_pair, values_map) {
SrvConfigPtr srv_cfg = CfgMgr::instance().getStagingCfg();
if (config_pair.first == "option-def") {
// This is converted to SimpleParser and is handled already above.
......@@ -628,14 +625,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
if (config_pair.first == "option-data") {
OptionDataListParser parser(AF_INET);
CfgOptionPtr cfg_option = CfgMgr::instance().getStagingCfg()->getCfgOption();
CfgOptionPtr cfg_option = srv_cfg->getCfgOption();
parser.parse(cfg_option, config_pair.second);
continue;
}
if (config_pair.first == "control-socket") {
ControlSocketParser parser;
SrvConfigPtr srv_cfg = CfgMgr::instance().getStagingCfg();
parser.parse(*srv_cfg, config_pair.second);
continue;
}
......@@ -646,14 +642,27 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
continue;
}
// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
DbAccessParser parser(DbAccessParser::LEASE_DB);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
if (config_pair.first == "host-database") {
DbAccessParser parser(DbAccessParser::HOSTS_DB);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
config_pair.second));
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
.arg(config_pair.first);
if (config_pair.first == "subnet4") {
subnet_parser = parser;
} else if (config_pair.first == "lease-database") {
leases_parser = parser;
} else if (config_pair.first == "interfaces-config") {
// The interface parser is independent from any other
// parser and can be run here before any other parsers.
......@@ -699,15 +708,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
// Setup the command channel.
configureCommandChannel();
// the leases database parser is the last to be run.
std::map<std::string, ConstElementPtr>::const_iterator leases_config =
values_map.find("lease-database");
if (leases_config != values_map.end()) {
config_pair.first = "lease-database";
leases_parser->build(leases_config->second);
leases_parser->commit();
}
} catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
.arg(config_pair.first).arg(ex.what());
......
......@@ -708,10 +708,7 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id,
} else if (config_id.compare("version") == 0) {
parser = new StringParser(config_id,
globalContext()->string_values_);
} else if (config_id.compare("lease-database") == 0) {
parser = new DbAccessParser(config_id, DbAccessParser::LEASE_DB);
} else if (config_id.compare("hosts-database") == 0) {
parser = new DbAccessParser(config_id, DbAccessParser::HOSTS_DB);
// lease-database and hosts-database have been converted to SimpleParser already.
} else if (config_id.compare("hooks-libraries") == 0) {
parser = new HooksLibrariesParser(config_id);
} else if (config_id.compare("dhcp-ddns") == 0) {
......@@ -843,7 +840,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
ParserCollection independent_parsers;
ParserPtr subnet_parser;
ParserPtr iface_parser;
ParserPtr leases_parser;
ParserPtr client_classes_parser;
// Some of the parsers alter state of the system that can't easily
......@@ -891,6 +887,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
}
BOOST_FOREACH(config_pair, values_map) {
SrvConfigPtr srv_config = CfgMgr::instance().getStagingCfg();
if (config_pair.first == "option-def") {
// This is converted to SimpleParser and is handled already above.
......@@ -899,21 +896,20 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
if (config_pair.first == "option-data") {
OptionDataListParser parser(AF_INET6);
CfgOptionPtr cfg_option = CfgMgr::instance().getStagingCfg()->getCfgOption();
CfgOptionPtr cfg_option = srv_config->getCfgOption();
parser.parse(cfg_option, config_pair.second);
continue;
}
if (config_pair.first == "mac-sources") {
MACSourcesListConfigParser parser;
CfgMACSource& mac_source = CfgMgr::instance().getStagingCfg()->getMACSources();
CfgMACSource& mac_source = srv_config->getMACSources();
parser.parse(mac_source, config_pair.second);
continue;
}
if (config_pair.first == "control-socket") {
ControlSocketParser parser;
SrvConfigPtr srv_config = CfgMgr::instance().getStagingCfg();
parser.parse(*srv_config, config_pair.second);
continue;
}
......@@ -926,19 +922,32 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
if (config_pair.first == "server-id") {
DUIDConfigParser parser;
const CfgDUIDPtr& cfg = CfgMgr::instance().getStagingCfg()->getCfgDUID();
const CfgDUIDPtr& cfg = srv_config->getCfgDUID();
parser.parse(cfg, config_pair.second);
continue;
}
// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
DbAccessParser parser(DbAccessParser::LEASE_DB);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
if (config_pair.first == "host-database") {
DbAccessParser parser(DbAccessParser::HOSTS_DB);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
parser.parse(cfg_db_access, config_pair.second);
continue;
}
ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first,
config_pair.second));
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED)
.arg(config_pair.first);
if (config_pair.first == "subnet6") {
subnet_parser = parser;
} else if (config_pair.first == "lease-database") {
leases_parser = parser;
} else if (config_pair.first == "hooks-libraries") {
// Executing the commit will alter currently loaded hooks
// libraries. Check if the supplied libraries are valid,
......@@ -985,15 +994,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
// Setup the command channel.
configureCommandChannel();
// The lease database parser is the last to be run.
std::map<std::string, ConstElementPtr>::const_iterator leases_config =
values_map.find("lease-database");
if (leases_config != values_map.end()) {
config_pair.first = "lease-database";
leases_parser->build(leases_config->second);
leases_parser->commit();
}
} catch (const isc::Exception& ex) {
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
.arg(config_pair.first).arg(ex.what());
......
// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 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
......@@ -13,6 +13,7 @@
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
......@@ -29,13 +30,14 @@ namespace dhcp {
// Factory function to build the parser
DbAccessParser::DbAccessParser(const std::string&, DBType db_type)
DbAccessParser::DbAccessParser(DBType db_type)
: values_(), type_(db_type) {
}
// Parse the configuration and check that the various keywords are consistent.
void
DbAccessParser::build(isc::data::ConstElementPtr config_value) {
DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
ConstElementPtr database_config) {
// To cope with incremental updates, the strategy is:
// 1. Take a copy of the stored keyword/value pairs.
......@@ -45,13 +47,16 @@ DbAccessParser::build(isc::data::ConstElementPtr config_value) {
// 5. Save resulting database access string in the Configuration
// Manager.
// Note only range checks can fail with a database_config from
// a flex/bison parser.
// 1. Take a copy of the stored keyword/value pairs.
std::map<string, string> values_copy = values_;
int64_t lfc_interval = 0;
int64_t timeout = 0;
// 2. Update the copy with the passed keywords.
BOOST_FOREACH(ConfigPair param, config_value->mapValue()) {
BOOST_FOREACH(ConfigPair param, database_config->mapValue()) {
try {
if ((param.first == "persist") || (param.first == "readonly")) {
values_copy[param.first] = (param.second->boolValue() ?
......@@ -86,27 +91,30 @@ DbAccessParser::build(isc::data::ConstElementPtr config_value) {
isc_throw(TypeKeywordMissing, (type_ == LEASE_DB ? "lease" : "host")
<< " database access parameters must "
"include the keyword 'type' to determine type of database "
"to be accessed (" << config_value->getPosition() << ")");
"to be accessed (" << database_config->getPosition() << ")");
}
// b. Check if the 'type' keyword known and throw an exception if not.
string dbtype = type_ptr->second;
if ((dbtype != "memfile") && (dbtype != "mysql") && (dbtype != "postgresql") && (dbtype != "cql")) {
if ((dbtype != "memfile") &&
(dbtype != "mysql") &&
(dbtype != "postgresql") &&
(dbtype != "cql")) {
isc_throw(BadValue, "unknown backend database type: " << dbtype
<< " (" << config_value->getPosition() << ")");
<< " (" << database_config->getPosition() << ")");
}
// c. Check that the lfc-interval is a number and it is within a resonable
// range.
if ((lfc_interval < 0) || (lfc_interval > std::numeric_limits<uint32_t>::max())) {
// c. Check that the lfc-interval is within a reasonable range.
if ((lfc_interval < 0) ||
(lfc_interval > std::numeric_limits<uint32_t>::max())) {
isc_throw(BadValue, "lfc-interval value: " << lfc_interval
<< " is out of range, expected value: 0.."
<< std::numeric_limits<uint32_t>::max());
}
// d. Check that the timeout is a number and it is within a resonable
// range.
if ((timeout < 0) || (timeout > std::numeric_limits<uint32_t>::max())) {
// d. Check that the timeout is within a reasonable range.
if ((timeout < 0) ||
(timeout > std::numeric_limits<uint32_t>::max())) {
isc_throw(BadValue, "timeout value: " << timeout
<< " is out of range, expected value: 0.."
<< std::numeric_limits<uint32_t>::max());
......@@ -119,7 +127,6 @@ DbAccessParser::build(isc::data::ConstElementPtr config_value) {
values_.swap(values_copy);
// 5. Save the database access string in the Configuration Manager.
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
if (type_ == LEASE_DB) {
cfg_db->setLeaseDbAccessString(getDbAccessString());
......@@ -152,11 +159,5 @@ DbAccessParser::getDbAccessString() const {
return (dbaccess);
}
// Commit the changes - reopen the database with the new parameters
void
DbAccessParser::commit() {
}
}; // namespace dhcp
}; // namespace isc
// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 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,8 +8,8 @@
#define DBACCESS_PARSER_H
#include <cc/data.h>
#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <cc/simple_parser.h>
#include <dhcpsrv/cfg_db_access.h>
#include <exceptions/exceptions.h>
#include <string>
......@@ -35,7 +35,7 @@ public:
///
/// Only the "type" sub-element is mandatory: the remaining sub-elements
/// depend on the database chosen.
class DbAccessParser: public DhcpConfigParser {
class DbAccessParser: public isc::data::SimpleParser {
public:
/// @brief Specifies the database type
......@@ -52,58 +52,36 @@ public:
/// @brief Constructor
///
/// @param param_name Name of the parameter under which the database
/// access details are held.
/// @param db_type Specifies database type (lease or hosts)
DbAccessParser(const std::string& param_name, DBType db_type);
DbAccessParser(DBType db_type);
/// The destructor.
virtual ~DbAccessParser()
{}
/// @brief Prepare configuration value.
/// @brief Parse configuration value.
///
/// Parses the set of strings forming the database access specification and
/// checks that all are OK. In particular it checks:
///
/// - "type" is "memfile", "mysql" or "postgresql"
/// - "lfc-interval" is a number from the range of 0 to 4294967295.
/// - "timeout" is a number from the range of 0 to 4294967295.
/// - "connect-timeout" is a number from the range of 0 to 4294967295.
///
/// Once all has been validated, constructs the database access string
/// expected by the lease manager.
///
/// @param config_value The configuration value for the "lease-database"
/// @param cfg_db The configuration where the access string will be set
/// @param database_config The configuration value for the "*-database"
/// identifier.
///
/// @throw isc::BadValue The 'type' keyword contains an unknown database
/// type.
/// @throw isc::dhcp::MissingTypeKeyword The 'type' keyword is missing from
/// the list of database access keywords.
virtual void build(isc::data::ConstElementPtr config_value);
void parse(isc::dhcp::CfgDbAccessPtr& cfg_db,
isc::data::ConstElementPtr database_config);
/// @brief This method is no-op.
virtual void commit();
/// @brief Factory method to create parser
///
/// Creates an instance of this parser.
///
/// @param param_name Name of the parameter used to access the
/// configuration.
///
/// @return Pointer to a DbAccessParser. The caller is responsible for
/// destroying the parser after use.
static DhcpConfigParser* factory(const std::string& param_name) {
if (param_name == "lease-database") {
return (new DbAccessParser(param_name, DbAccessParser::LEASE_DB));
} else if (param_name == "hosts-database") {
return (new DbAccessParser(param_name, DbAccessParser::HOSTS_DB));
} else {
isc_throw(BadValue, "Unexpected parameter name (" << param_name
<< ") passed to DbAccessParser::factory");
}
}
protected:
/// @brief Get database access parameters
......@@ -118,6 +96,7 @@ protected:
return (values_);
}
/// @brief Construct database access string
///
/// Constructs the database access string from the stored parameters.
......@@ -125,6 +104,7 @@ protected:
/// @return Database access string
std::string getDbAccessString() const;
private:
std::map<std::string, std::string> values_; ///< Stored parameter values
......
// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2017 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
......@@ -43,7 +43,7 @@ public:
/// (the last in particular).
///
/// As some of the tests have the side-effect of altering the logging
/// settings (when the parser's "build" method is called), ensure that
/// settings (when the parser's "parse" method is called), ensure that
/// the logging is reset to the default after each test completes.
~DbAccessParserTest() {
LeaseMgrFactory::destroy();
......@@ -194,14 +194,20 @@ public:
/// @brief Constructor
///
/// @brief Keyword/value collection of database access parameters
TestDbAccessParser(const std::string& param_name, DbAccessParser::DBType type)
: DbAccessParser(param_name, type)
TestDbAccessParser(DbAccessParser::DBType type)
: DbAccessParser(type)
{}
/// @brief Destructor
virtual ~TestDbAccessParser()
{}
/// @brief Parse configuration value
void parse(ConstElementPtr database_config) {
CfgDbAccessPtr cfg_db(new CfgDbAccess());
DbAccessParser::parse(cfg_db, database_config);
}
/// Allow use of superclass's protected functions.
using DbAccessParser::getDbAccessParameters;
using DbAccessParser::getDbAccessString;
......@@ -236,8 +242,8 @@ TEST_F(DbAccessParserTest, validTypeMemfile) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
}
......@@ -252,8 +258,8 @@ TEST_F(DbAccessParserTest, emptyKeyword) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(), config);
}
......@@ -269,8 +275,8 @@ TEST_F(DbAccessParserTest, persistV4Memfile) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
config);
......@@ -288,8 +294,8 @@ TEST_F(DbAccessParserTest, persistV6Memfile) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid memfile", parser.getDbAccessParameters(),
config);
......@@ -307,8 +313,8 @@ TEST_F(DbAccessParserTest, validLFCInterval) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid LFC Interval", parser.getDbAccessParameters(),
config);
}
......@@ -325,8 +331,8 @@ TEST_F(DbAccessParserTest, negativeLFCInterval) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.build(json_elements), BadValue);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), BadValue);
}
// This test checks that the parser rejects the too large (greater than
......@@ -341,8 +347,8 @@ TEST_F(DbAccessParserTest, largeLFCInterval) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.build(json_elements), BadValue);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), BadValue);
}
// This test checks that the parser accepts the valid value of the
......@@ -357,8 +363,8 @@ TEST_F(DbAccessParserTest, validTimeout) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid timeout", parser.getDbAccessParameters(),
config);
}
......@@ -375,8 +381,8 @@ TEST_F(DbAccessParserTest, negativeTimeout) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.build(json_elements), BadValue);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), BadValue);
}
// This test checks that the parser rejects a too large (greater than
......@@ -391,8 +397,8 @@ TEST_F(DbAccessParserTest, largeTimeout) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.build(json_elements), BadValue);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), BadValue);
}
// Check that the parser works with a valid MySQL configuration
......@@ -408,8 +414,8 @@ TEST_F(DbAccessParserTest, validTypeMysql) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Valid mysql", parser.getDbAccessParameters(), config);
}
......@@ -425,20 +431,8 @@ TEST_F(DbAccessParserTest, missingTypeKeyword) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.build(json_elements), TypeKeywordMissing);
}
// Check that the factory function works.
TEST_F(DbAccessParserTest, factory) {
// Check that the parser is built through the factory.
boost::scoped_ptr<DhcpConfigParser> parser(
DbAccessParser::factory("lease-database")
);
EXPECT_TRUE(parser);
DbAccessParser* dbap = dynamic_cast<DbAccessParser*>(parser.get());
EXPECT_NE(static_cast<DbAccessParser*>(NULL), dbap);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_THROW(parser.parse(json_elements), TypeKeywordMissing);
}
// Check reconfiguration. Checks that incremental changes applied to the
......@@ -485,7 +479,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
"name", "keatest",
NULL};
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
// First configuration string should cause a representation of that string
// to be held.
......@@ -493,7 +487,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
EXPECT_NO_THROW(parser.build(json_elements));
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Initial configuration", parser.getDbAccessParameters(),
config1);
......@@ -503,7 +497,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
EXPECT_NO_THROW(parser.build(json_elements));
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Subsequent configuration", parser.getDbAccessParameters(),
config2);
......@@ -513,7 +507,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
EXPECT_NO_THROW(parser.build(json_elements));
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Incremental configuration", parser.getDbAccessParameters(),
config3);
......@@ -523,7 +517,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
EXPECT_THROW(parser.build(json_elements), BadValue);
EXPECT_THROW(parser.parse(json_elements), BadValue);
checkAccessString("Incompatible incremental change", parser.getDbAccessParameters(),
config3);
......@@ -533,7 +527,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
EXPECT_NO_THROW(parser.build(json_elements));
EXPECT_NO_THROW(parser.parse(json_elements));
checkAccessString("Compatible incremental change", parser.getDbAccessParameters(),
config4);
}
......@@ -549,8 +543,8 @@ TEST_F(DbAccessParserTest, getDbAccessString) {
ConstElementPtr json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser("lease-database", DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.build(json_elements));
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
EXPECT_NO_THROW(parser.parse(json_elements));