From: Marcin Siodelski Date: Tue, 19 Mar 2019 16:33:38 +0000 (+0100) Subject: [#103,!277] Added support for config-fetch-wait-time parameter. X-Git-Tag: Kea-1.6.0-beta~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6f01c0e81437e654c7335e2a7ffeb5e17cab8a1;p=thirdparty%2Fkea.git [#103,!277] Added support for config-fetch-wait-time parameter. --- diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index 5c684e3467..bbdbe99082 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -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: diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index 7efdeb93d3..9c63d86838 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -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 diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index b847f78792..1ee586fa2d 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -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 diff --git a/src/lib/process/config_ctl_info.cc b/src/lib/process/config_ctl_info.cc index 4fb37d26c8..33edb91c50 100644 --- a/src/lib/process/config_ctl_info.cc +++ b/src/lib/process/config_ctl_info.cc @@ -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 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(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(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 diff --git a/src/lib/process/config_ctl_info.h b/src/lib/process/config_ctl_info.h index 19fd63f129..96f961641a 100644 --- a/src/lib/process/config_ctl_info.h +++ b/src/lib/process/config_ctl_info.h @@ -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 #include +#include #include #include @@ -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& 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& 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 config_fetch_wait_time_; + /// @brief List of configuration databases ConfigDbInfoList db_infos_; }; diff --git a/src/lib/process/config_ctl_parser.cc b/src/lib/process/config_ctl_parser.cc index 4474876e8e..38f7ac06fe 100644 --- a/src/lib/process/config_ctl_parser.cc +++ b/src/lib/process/config_ctl_parser.cc @@ -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 #include #include +#include #include 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(config_fetch_wait_time)); + } + } catch (const isc::ConfigError&) { // Position was already added throw; diff --git a/src/lib/process/tests/config_ctl_info_unittests.cc b/src/lib/process/tests/config_ctl_info_unittests.cc index 5f0c50f5d6..8c8d6c980c 100644 --- a/src/lib/process/tests/config_ctl_info_unittests.cc +++ b/src/lib/process/tests/config_ctl_info_unittests.cc @@ -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(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(123)); // Clone that instance. ConfigControlInfo ctl2(ctl1); @@ -166,3 +177,4 @@ TEST(ConfigControlInfo, copyAndEquality) { // They should not equal. EXPECT_FALSE(ctl3.equals(ctl1)); } + diff --git a/src/lib/process/tests/config_ctl_parser_unittests.cc b/src/lib/process/tests/config_ctl_parser_unittests.cc index bf1be4d1ac..8e5b328fdf 100644 --- a/src/lib/process/tests/config_ctl_parser_unittests.cc +++ b/src/lib/process/tests/config_ctl_parser_unittests.cc @@ -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) {