]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5096] Use DhcpConfigError only, add locations and a DB backend comment
authorFrancis Dupont <fdupont@isc.org>
Fri, 20 Jan 2017 13:52:54 +0000 (14:52 +0100)
committerFrancis Dupont <fdupont@isc.org>
Fri, 20 Jan 2017 13:52:54 +0000 (14:52 +0100)
src/lib/dhcpsrv/mysql_connection.cc
src/lib/dhcpsrv/parsers/dbaccess_parser.cc
src/lib/dhcpsrv/parsers/dbaccess_parser.h
src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

index 06162bdf1e6ea92de89d811bd5a907a325d29b94..5d5f44ef0bb555700d7731bbc987743fb1a7a7ca 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -28,7 +28,7 @@ const my_bool MLM_TRUE = 1;
 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) {
index 18769f9c108a8abb6063f0a4672e176112921a78..dd51a9c3eb6c90666868d633ae6d5178a990a9f4 100644 (file)
@@ -77,7 +77,7 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
             }
         } 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() << ")");
         }
@@ -88,36 +88,44 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
     // 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
index ed894d32d3610e57b22b9e3003174faadac9e8b6..8cb716d7d2a4f3edc2e04a11db0252ffef97e3ab 100644 (file)
 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
index 674b78cc39d556d8445a5841f8e3cddf9c512010..5fa1081dccc890d680a678e1a165179b50d6103f 100644 (file)
@@ -8,6 +8,7 @@
 
 #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>
@@ -332,7 +333,7 @@ TEST_F(DbAccessParserTest, negativeLFCInterval) {
     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
@@ -348,7 +349,7 @@ TEST_F(DbAccessParserTest, largeLFCInterval) {
     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
@@ -382,7 +383,7 @@ TEST_F(DbAccessParserTest, negativeTimeout) {
     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
@@ -398,7 +399,7 @@ TEST_F(DbAccessParserTest, largeTimeout) {
     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
@@ -432,7 +433,7 @@ TEST_F(DbAccessParserTest, missingTypeKeyword) {
     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
@@ -517,7 +518,7 @@ TEST_F(DbAccessParserTest, incrementalChanges) {
     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);
 
@@ -592,7 +593,7 @@ TEST_F(DbAccessParserTest, invalidReadOnly) {
     EXPECT_TRUE(json_elements);
 
     TestDbAccessParser parser(DbAccessParser::LEASE_DB);
-    EXPECT_THROW(parser.parse(json_elements), BadValue);
+    EXPECT_THROW(parser.parse(json_elements), DhcpConfigError);
 }
 
 
index b5433ab3327bf3645e0f50099fdbc5cc4fa88523..4502bb23c720d1667c7ba1aa8f30589658230a82 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -116,7 +116,7 @@ TEST(MySqlOpenTest, OpenDatabase) {
     // 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());
index 0a629d557901582d484aa848c03251c31987fbe8..d5627cdb805ba0fc182cab972bc67bea95383650 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -108,7 +108,7 @@ TEST(PgSqlOpenTest, OpenDatabase) {
     // 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());