]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#103,!277] Added support for config-fetch-wait-time parameter.
authorMarcin Siodelski <marcin@isc.org>
Tue, 19 Mar 2019 16:33:38 +0000 (17:33 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 26 Mar 2019 07:08:56 +0000 (03:08 -0400)
src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp4/tests/config_parser_unittest.cc
src/lib/process/config_ctl_info.cc
src/lib/process/config_ctl_info.h
src/lib/process/config_ctl_parser.cc
src/lib/process/tests/config_ctl_info_unittests.cc
src/lib/process/tests/config_ctl_parser_unittests.cc

index 5c684e3467007805c95122f3f119fda84bed2c88..bbdbe99082fb895f3d3dd46d18a9766f56a4b45d 100644 (file)
@@ -341,6 +341,15 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
     }
 }
 
+\"config-fetch-wait-time\" {
+    switch(driver.ctx_) {
+    case isc::dhcp::Parser4Context::CONFIG_CONTROL:
+        return isc::dhcp::Dhcp4Parser::make_CONFIG_FETCH_WAIT_TIME(driver.loc_);
+    default:
+        return isc::dhcp::Dhcp4Parser::make_STRING("config-fetch-wait-time", driver.loc_);
+    }
+}
+
 \"readonly\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser4Context::HOSTS_DATABASE:
index 7efdeb93d3f5ecc8cd881aae326a5be4edf8811f..9c63d868388bc66fc3971da9eee81065ead8266e 100644 (file)
@@ -50,8 +50,11 @@ using namespace std;
   NULL_TYPE "null"
 
   DHCP4 "Dhcp4"
+
   CONFIG_CONTROL "config-control"
   CONFIG_DATABASES "config-databases"
+  CONFIG_FETCH_WAIT_TIME "config-fetch-wait-time"
+
   INTERFACES_CONFIG "interfaces-config"
   INTERFACES "interfaces"
   DHCP_SOCKET_TYPE "dhcp-socket-type"
@@ -2144,6 +2147,7 @@ config_control_params: config_control_param
 
 // This defines a list of allowed parameters for each subnet.
 config_control_param: config_databases
+                    | config_fetch_wait_time
                     ;
 
 config_databases: CONFIG_DATABASES {
@@ -2156,6 +2160,11 @@ config_databases: CONFIG_DATABASES {
     ctx.leave();
 };
 
+config_fetch_wait_time: CONFIG_FETCH_WAIT_TIME COLON INTEGER {
+    ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
+    ctx.stack_.back()->set("config-fetch-wait-time", value);
+};
+
 // --- logging entry -----------------------------------------
 
 // This defines the top level "Logging" object. It parses
index b847f7879287c93b8e7f9187ef8afc3af728236f..1ee586fa2dc7b59afff929ae0668c03e0048a14f 100644 (file)
@@ -242,6 +242,7 @@ const char* PARSER_CONFIGS[] = {
     "    \"rebind-timer\": 2000, \n"
     "    \"renew-timer\": 1000, \n"
     "    \"config-control\": { \n"
+    "       \"config-fetch-wait-time\": 10, \n"
     "       \"config-databases\": [ { \n"
     "               \"type\": \"mysql\", \n"
     "               \"name\": \"keatest1\", \n"
@@ -6434,6 +6435,10 @@ TEST_F(Dhcp4ParserTest, configControlInfo) {
               dblist.front().getAccessString());
     EXPECT_EQ("name=keatest2 password=keatest type=mysql user=keatest",
               dblist.back().getAccessString());
+
+    // Verify that the config-fetch-wait-time is correct.
+    EXPECT_FALSE(info->getConfigFetchWaitTime().unspecified());
+    EXPECT_EQ(10, info->getConfigFetchWaitTime().get());
 }
 
 // Check whether it is possible to configure server-tag
index 4fb37d26c8c8572debf799e442ddd20994bc33c6..33edb91c50795d2064a2ab4f69c9a5d3450c7a6e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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,6 +8,7 @@
 #include <process/config_ctl_info.h>
 
 using namespace isc::data;
+using namespace isc::util;
 
 namespace isc {
 namespace process {
@@ -42,7 +43,8 @@ ConfigDbInfo::getParameterValue(const std::string& name, std::string& value) con
 
 //********* ConfiControlInfo ************//
 
-ConfigControlInfo::ConfigControlInfo(const ConfigControlInfo& other) {
+ConfigControlInfo::ConfigControlInfo(const ConfigControlInfo& other)
+    : config_fetch_wait_time_(other.config_fetch_wait_time_) {
     for (auto db : other.db_infos_) {
         addConfigDatabase(db.getAccessString());
     }
@@ -88,6 +90,7 @@ ConfigControlInfo::EMPTY_DB() {
 void
 ConfigControlInfo::clear() {
     db_infos_.clear();
+    config_fetch_wait_time_ = Optional<uint16_t>(30, true);
 }
 
 void
@@ -106,12 +109,19 @@ ConfigControlInfo::toElement() const {
     }
 
     result->set("config-databases", db_list);
+
+    if (!config_fetch_wait_time_.unspecified()) {
+        result->set("config-fetch-wait-time",
+                    Element::create(static_cast<int>(config_fetch_wait_time_)));
+    }
+
     return(result);
 }
 
 bool
 ConfigControlInfo::equals(const ConfigControlInfo& other) const {
-   return (db_infos_ == other.db_infos_);
+   return ((db_infos_ == other.db_infos_) &&
+           (config_fetch_wait_time_ == other.config_fetch_wait_time_));
 }
 
 } // end of namespace isc::process
index 19fd63f1291ef000b4f800e4315b93b30996f7ea..96f961641ad3500e96c11b966879182ecc146e97 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -9,6 +9,7 @@
 
 #include <cc/cfg_to_element.h>
 #include <database/database_connection.h>
+#include <util/optional.h>
 
 #include <boost/shared_ptr.hpp>
 #include <stdint.h>
@@ -139,11 +140,36 @@ class ConfigControlInfo : public isc::data::CfgToElement {
 public:
 
     /// @brief Constructor.
-    ConfigControlInfo() {};
+    ConfigControlInfo()
+        : config_fetch_wait_time_(30, true) {};
 
     /// @brief Copy Constructor.
     ConfigControlInfo(const ConfigControlInfo& other);
 
+    /// @brief Sets new value of the config-fetch-wait-time.
+    ///
+    /// @param config_fetch_wait_time New value of the parameter which
+    /// specifies a time period in seconds between the attempts to
+    /// fetch the server configuration updates. The value of 0 disables
+    /// the periodic attempts to fetch the updates.
+    void setConfigFetchWaitTime(const util::Optional<uint16_t>& config_fetch_wait_time) {
+        config_fetch_wait_time_ = config_fetch_wait_time;
+    }
+
+    /// @brief Returns configured config-fetch-wait-time value.
+    ///
+    /// This value specifies the time period in seconds between the
+    /// attempts to fetch the server configuration updates via the
+    /// configuration backends. The value of 0 means that the
+    /// mechanism to periodically fetch the configuration updates
+    /// is disabled.
+    ///
+    /// @return Time period between the subsequent attempts to
+    /// fetch server configuration updates in seconds.
+    const util::Optional<uint16_t>& getConfigFetchWaitTime() const {
+        return (config_fetch_wait_time_);
+    }
+
     /// @brief Sets configuration database access string.
     ///
     /// @param access_str database access string.
@@ -200,6 +226,9 @@ public:
 
 private:
 
+    /// @brief Configured value of the config-fetch-wait-time.
+    util::Optional<uint16_t> config_fetch_wait_time_;
+
     /// @brief List of configuration databases
     ConfigDbInfoList db_infos_;
 };
index 4474876e8ed8b2351a2da84d577be866cff845e2..38f7ac06fe4b1fe471a80679998b653ed5b79912 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -9,6 +9,7 @@
 #include <cc/dhcp_config_error.h>
 #include <process/config_ctl_parser.h>
 #include <database/dbaccess_parser.h>
+#include <cstdint>
 #include <string>
 
 using namespace isc;
@@ -41,6 +42,14 @@ ConfigControlParser::parse(const data::ConstElementPtr& config_control) {
                 ctl_info->addConfigDatabase(access_string);
             }
         }
+
+        if (config_control->contains("config-fetch-wait-time")) {
+            auto config_fetch_wait_time = getInteger(config_control,
+                                                     "config-fetch-wait-time",
+                                                     0, 65535);
+            ctl_info->setConfigFetchWaitTime(static_cast<uint16_t>(config_fetch_wait_time));
+        }
+
     } catch (const isc::ConfigError&) {
         // Position was already added
         throw;
index 5f0c50f5d6f0a6ed4b487d2c084bb0238e29b44b..8c8d6c980c28e775b37cb5edc327a3e61585ef39 100644 (file)
@@ -15,6 +15,7 @@
 
 using namespace isc::process;
 using namespace isc::data;
+using namespace isc::util;
 
 // Verifies initializing via an access string and unparsing into elements
 // We just test basic unparsing, as more rigorous testing is done in
@@ -108,6 +109,13 @@ TEST(ConfigControlInfo, basicOperation) {
     ConfigControlInfo ctl;
     // We should have no dbs in the list.
     EXPECT_EQ(0, ctl.getConfigDatabases().size());
+    // The default fetch time is 30 and it is unspecified.
+    EXPECT_TRUE(ctl.getConfigFetchWaitTime().unspecified());
+    EXPECT_EQ(30, ctl.getConfigFetchWaitTime().get());
+
+    // Override the default fetch time.
+    ctl.setConfigFetchWaitTime(Optional<uint16_t>(123));
+    EXPECT_EQ(123, ctl.getConfigFetchWaitTime().get());
 
     // We should be able to add two distinct, valid dbs
     std::string access_str1 = "type=mysql host=machine1.org";
@@ -140,9 +148,11 @@ TEST(ConfigControlInfo, basicOperation) {
     const ConfigDbInfo& db_info3 = ctl.findConfigDb("type", "bogus");
     EXPECT_TRUE(db_info3 == ConfigControlInfo::EMPTY_DB());
 
-    // Verify we can clear the list of dbs.
+    // Verify we can clear the list of dbs and the fetch time.
     ctl.clear();
     EXPECT_EQ(0, ctl.getConfigDatabases().size());
+    EXPECT_TRUE(ctl.getConfigFetchWaitTime().unspecified());
+    EXPECT_EQ(30, ctl.getConfigFetchWaitTime().get());
 }
 
 // Verifies the copy ctor and equality functions ConfigControlInfo
@@ -152,6 +162,7 @@ TEST(ConfigControlInfo, copyAndEquality) {
     ConfigControlInfo ctl1;
     ASSERT_NO_THROW(ctl1.addConfigDatabase("type=mysql host=mach1.org"));
     ASSERT_NO_THROW(ctl1.addConfigDatabase("type=postgresql host=mach2.org"));
+    ctl1.setConfigFetchWaitTime(Optional<uint16_t>(123));
 
     // Clone that instance.
     ConfigControlInfo ctl2(ctl1);
@@ -166,3 +177,4 @@ TEST(ConfigControlInfo, copyAndEquality) {
     // They should not equal.
     EXPECT_FALSE(ctl3.equals(ctl1));
 }
+
index bf1be4d1ac619bf0a639303b3b979a28524318f6..8e5b328fdf976a346dcf319cd23ee0f5f9556144 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -24,7 +24,9 @@ TEST(ConfigCtlInfoParser, validConfigs) {
     std::string configs[] = {
        "{}",
 
-       "{ \"config-databases\": [] }",
+       "{ \"config-databases\": [], \n"
+       "  \"config-fetch-wait-time\": 20 \n"
+       "}",
 
        "{ \"config-databases\": [ \n"
        "    { \n"
@@ -79,7 +81,10 @@ TEST(ConfigCtlInfoParser, invalidConfigs) {
        "    { \n"
        "        \"bogus\": \"param\" \n"
        "    } \n"
-       "] } \n"
+       "] } \n",
+       "{ \"config-fetch-wait-time\": -1 }",
+       "{ \"config-fetch-wait-time\": 65537 }",
+       "{ \"config-fetch-wait-time\": \"a-string\" }",
     };
 
     for (auto config : configs) {