]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2741] Fixed getting configured timeout parameters
authorMarcin Siodelski <marcin@isc.org>
Fri, 3 Feb 2023 12:06:51 +0000 (13:06 +0100)
committerAndrei Pavel <andrei@isc.org>
Thu, 13 Jul 2023 10:27:56 +0000 (13:27 +0300)
src/lib/database/database_connection.cc
src/lib/database/db_messages.cc
src/lib/database/db_messages.h
src/lib/database/db_messages.mes
src/lib/database/tests/database_connection_unittest.cc

index 067a1e03d9ae2b3766db081b341939cef24e70f1..50175c6aa88f92afc7022c428b8c5cd4907bf5ec 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 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
@@ -225,6 +225,9 @@ DatabaseConnection::toElement(const ParameterMap& params) {
 
         if ((keyword == "lfc-interval") ||
             (keyword == "connect-timeout") ||
+            (keyword == "read-timeout") ||
+            (keyword == "write-timeout") ||
+            (keyword == "tcp-user-timeout") ||
             (keyword == "reconnect-wait-time") ||
             (keyword == "max-reconnect-tries") ||
             (keyword == "port") ||
@@ -235,8 +238,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
                 int_value = boost::lexical_cast<int64_t>(value);
                 result->set(keyword, isc::data::Element::create(int_value));
             } catch (...) {
-                LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
-                    .arg("integer").arg(keyword).arg(value);
+                LOG_ERROR(database_logger, DATABASE_TO_JSON_INTEGER_ERROR)
+                    .arg(keyword).arg(value);
             }
         } else if ((keyword == "persist") ||
                    (keyword == "readonly")) {
@@ -245,8 +248,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
             } else if (value == "false") {
                 result->set(keyword, isc::data::Element::create(false));
             } else {
-                LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
-                    .arg("boolean").arg(keyword).arg(value);
+                LOG_ERROR(database_logger, DATABASE_TO_JSON_BOOLEAN_ERROR)
+                    .arg(keyword).arg(value);
             }
         } else if ((keyword == "type") ||
                    (keyword == "user") ||
@@ -260,8 +263,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
                    (keyword == "cipher-list")) {
             result->set(keyword, isc::data::Element::create(value));
         } else {
-            LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
-                    .arg("unknown").arg(keyword).arg(value);
+            LOG_ERROR(database_logger, DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR)
+                    .arg(keyword).arg(value);
         }
     }
 
index 6a25cf5b957dbbf311289dc93852518b8228c25d..5012849c3a6616ed99e960d631d84dd97e556e5c 100644 (file)
@@ -19,7 +19,9 @@ extern const isc::log::MessageID DATABASE_PGSQL_FATAL_ERROR = "DATABASE_PGSQL_FA
 extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK = "DATABASE_PGSQL_ROLLBACK";
 extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK_SAVEPOINT = "DATABASE_PGSQL_ROLLBACK_SAVEPOINT";
 extern const isc::log::MessageID DATABASE_PGSQL_START_TRANSACTION = "DATABASE_PGSQL_START_TRANSACTION";
-extern const isc::log::MessageID DATABASE_TO_JSON_ERROR = "DATABASE_TO_JSON_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_BOOLEAN_ERROR = "DATABASE_TO_JSON_BOOLEAN_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_INTEGER_ERROR = "DATABASE_TO_JSON_INTEGER_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR = "DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR";
 
 } // namespace db
 } // namespace isc
@@ -39,7 +41,9 @@ const char* values[] = {
     "DATABASE_PGSQL_ROLLBACK", "rolling back PostgreSQL database",
     "DATABASE_PGSQL_ROLLBACK_SAVEPOINT", "rolling back PostgreSQL database to savepoint: $1",
     "DATABASE_PGSQL_START_TRANSACTION", "starting a new PostgreSQL transaction",
-    "DATABASE_TO_JSON_ERROR", "Internal logic error: unknown %1 element found in state: %2",
+    "DATABASE_TO_JSON_BOOLEAN_ERROR", "Internal logic error: invalid boolean value found in database connection parameters: %1=%2",
+    "DATABASE_TO_JSON_INTEGER_ERROR", "Internal logic error: invalid integer value found in database connection parameters: %1=%2",
+    "DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR", "Internal logic error: unknown element found in database connection parameters: %1=%2",
     NULL
 };
 
index 6cfad3189a26c6778ae5ed19ec2f1d40a73ebe57..3dddafcd2e5a500c9d90f51f7a76bc8dce287afc 100644 (file)
@@ -20,7 +20,9 @@ extern const isc::log::MessageID DATABASE_PGSQL_FATAL_ERROR;
 extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK;
 extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK_SAVEPOINT;
 extern const isc::log::MessageID DATABASE_PGSQL_START_TRANSACTION;
-extern const isc::log::MessageID DATABASE_TO_JSON_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_BOOLEAN_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_INTEGER_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR;
 
 } // namespace db
 } // namespace isc
index d919320948636c30ccd81bdab4e83b1b3c3415bc..4ef3cf949f64ceea4e94a4fbb316c451cdb31191 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2012-2023 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
@@ -80,8 +80,20 @@ inserted into multiple tables with multiple INSERT statements
 and there may be a need to rollback the whole transaction if
 any of these INSERT statements fail.
 
-% DATABASE_TO_JSON_ERROR Internal logic error: unknown %1 element found in state: %2
+% DATABASE_TO_JSON_BOOLEAN_ERROR Internal logic error: invalid boolean value found in database connection parameters: %1=%2
 This error message is printed when conversion to JSON of the internal state is requested,
-but the connection string contains unrecognized parameter. This is a programming error.
+but the connection string contains a boolean parameter with invalid value. It is a programming
+error. The software will continue operation, but the returned JSON data will be syntactically
+valid, but incomplete. The culprit parameter will not be converted.
+
+% DATABASE_TO_JSON_INTEGER_ERROR Internal logic error: invalid integer value found in database connection parameters: %1=%2
+This error message is printed when conversion to JSON of the internal state is requested,
+but the connection string contains the integer parameter with a wrong value. It is a programming
+error. The software will continue operation, but the returned JSON data will be syntactically
+valid, but incomplete. The culprit parameter will not be converted.
+
+% DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR Internal logic error: unknown element found in database connection parameters: %1=%2
+This error message is printed when conversion to JSON of the internal state is requested,
+but the connection string contains unrecognized parameter. It is a programming error.
 The software will continue operation, but the returned JSON data will be syntactically
 valid, but incomplete. The unknown parameter will not be converted.
index 42dda260931084991a1169c5f5bda10cac382c77..dc8c8c30edc5fad6632ece891699c78914144158 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 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
@@ -525,7 +525,7 @@ TEST(DatabaseConnectionTest, redactAccessStringNoPassword) {
 TEST(DatabaseConnection, toElementDbAccessStringValid) {
     const char* configs[] = {
         "{\n"
-        "\"connect-timeout\" : 200, \n"
+        "\"connect-timeout\": 200, \n"
         "\"on-fail\": \"stop-retry-exit\", \n"
         "\"lfc-interval\" : 100, \n"
         "\"host\": \"whatevah\", \n"
@@ -558,6 +558,55 @@ TEST(DatabaseConnection, toElementDbAccessStringValid) {
     ASSERT_TRUE(json_elements->equals(*round_trip));
 }
 
+// Check that the toElementDbAccessString() handles Postgres backend
+// specific paramateres.
+TEST(DatabaseConnection, toElementDbAccessStringValidPostgresql) {
+    const char* configs[] = {
+        "{\n"
+        "\"connect-timeout\": 200, \n"
+        "\"tcp-user-timeout\": 10, \n"
+        "\"type\": \"postgresql\", \n"
+        "\"user\": \"user_str\" \n"
+        "}\n"
+    };
+
+    DbAccessParser parser;
+    std::string access_str;
+    ConstElementPtr json_elements;
+
+    ASSERT_NO_THROW(json_elements = Element::fromJSON(configs[0]));
+    ASSERT_NO_THROW(parser.parse(access_str, json_elements));
+
+    ElementPtr round_trip = DatabaseConnection::toElementDbAccessString(access_str);
+
+    ASSERT_TRUE(json_elements->equals(*round_trip));
+}
+
+// Check that the toElementDbAccessString() handles MySQL backend
+// specific paramateres.
+TEST(DatabaseConnection, toElementDbAccessStringValidMySql) {
+    const char* configs[] = {
+        "{\n"
+        "\"connect-timeout\": 200, \n"
+        "\"read-timeout\": 10, \n"
+        "\"write-timeout\": 10, \n"
+        "\"type\": \"mysql\", \n"
+        "\"user\": \"user_str\" \n"
+        "}\n"
+    };
+
+    DbAccessParser parser;
+    std::string access_str;
+    ConstElementPtr json_elements;
+
+    ASSERT_NO_THROW(json_elements = Element::fromJSON(configs[0]));
+    ASSERT_NO_THROW(parser.parse(access_str, json_elements));
+
+    ElementPtr round_trip = DatabaseConnection::toElementDbAccessString(access_str);
+
+    ASSERT_TRUE(json_elements->equals(*round_trip));
+}
+
 // Check that toElementDbAccessString() catches invalid parameters.
 // Note that because toElementDbAccessString() utilizes
 // toElement() this tests both.