mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[#103,!277] Added support for config-fetch-wait-time parameter.
This commit is contained in:
@@ -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:
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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_;
|
||||
};
|
||||
|
@@ -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;
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user