-// 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
const int MLM_MYSQL_FETCH_SUCCESS = 0;
const int MLM_MYSQL_FETCH_FAILURE = 1;
-const int MYSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds
+const int MYSQL_DEFAULT_CONNECTION_TIMEOUT = 5; // seconds
MySqlTransaction::MySqlTransaction(MySqlConnection& conn)
: conn_(conn), committed_(false) {
}
} catch (const isc::data::TypeError& ex) {
// Append position of the element.
- isc_throw(BadValue, "invalid value type specified for "
+ isc_throw(DhcpConfigError, "invalid value type specified for "
"parameter '" << param.first << "' ("
<< param.second->getPosition() << ")");
}
// a. Check if the "type" keyword exists and thrown an exception if not.
StringPairMap::const_iterator type_ptr = values_copy.find("type");
if (type_ptr == values_copy.end()) {
- isc_throw(TypeKeywordMissing, (type_ == LEASE_DB ? "lease" : "host")
+ isc_throw(DhcpConfigError, (type_ == LEASE_DB ? "lease" : "host")
<< " database access parameters must "
"include the keyword 'type' to determine type of database "
"to be accessed (" << database_config->getPosition() << ")");
}
// b. Check if the 'type' keyword known and throw an exception if not.
+ //
+ // Please note when you add a new database backend you have to add
+ // the new type here and in server grammars.
string dbtype = type_ptr->second;
if ((dbtype != "memfile") &&
(dbtype != "mysql") &&
(dbtype != "postgresql") &&
(dbtype != "cql")) {
- isc_throw(BadValue, "unknown backend database type: " << dbtype
- << " (" << database_config->getPosition() << ")");
+ ConstElementPtr value = database_config->get("type");
+ isc_throw(DhcpConfigError, "unknown backend database type: " << dbtype
+ << " (" << value->getPosition() << ")");
}
// 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
+ ConstElementPtr value = database_config->get("lfc-interval");
+ isc_throw(DhcpConfigError, "lfc-interval value: " << lfc_interval
<< " is out of range, expected value: 0.."
- << std::numeric_limits<uint32_t>::max());
+ << std::numeric_limits<uint32_t>::max()
+ << " (" << value->getPosition() << ")");
}
// 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
+ ConstElementPtr value = database_config->get("connect-timeout");
+ isc_throw(DhcpConfigError, "connect-timeout value: " << timeout
<< " is out of range, expected value: 0.."
- << std::numeric_limits<uint32_t>::max());
+ << std::numeric_limits<uint32_t>::max()
+ << " (" << value->getPosition() << ")");
}
// 4. If all is OK, update the stored keyword/value pairs. We do this by
namespace isc {
namespace dhcp {
-/// @brief Exception thrown when 'type' keyword is missing from string
-///
-/// This condition is checked, but should never occur because 'type' is marked
-/// as mandatory in the .spec file for the server.
-class TypeKeywordMissing : public isc::Exception {
-public:
- TypeKeywordMissing(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
/// @brief Parse Lease Database Parameters
///
/// This class is the parser for the lease database configuration. This is a
#include <cc/command_interpreter.h>
#include <dhcpsrv/lease_mgr_factory.h>
+#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/testutils/mysql_schema.h>
#include <dhcpsrv/host_mgr.h>
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
// This test checks that the parser rejects the too large (greater than
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
// This test checks that the parser accepts the valid value of the
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
// This test checks that the parser rejects a too large (greater than
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
// Check that the parser works with a valid MySQL configuration
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), TypeKeywordMissing);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
// Check reconfiguration. Checks that incremental changes applied to the
json_elements = Element::fromJSON(json_config);
EXPECT_TRUE(json_elements);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
checkAccessString("Incompatible incremental change", parser.getDbAccessParameters(),
config3);
EXPECT_TRUE(json_elements);
TestDbAccessParser parser(DbAccessParser::LEASE_DB);
- EXPECT_THROW(parser.parse(json_elements), BadValue);
+ EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
}
-// 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
// Check that lease manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
- string connection_string = validMySQLConnectionString() + string(" ") +
+ string connection_string = validMySQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
LeaseMgrFactory::create(connection_string);
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-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
// Check that lease manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
- string connection_string = validPgSQLConnectionString() + string(" ") +
+ string connection_string = validPgSQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
LeaseMgrFactory::create(connection_string);
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());