Commit cfbd62e0 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3974] Attached parser for expired leases processing to global parser.

parent c05c0a17
......@@ -24,6 +24,7 @@
#include <dhcpsrv/option_space_container.h>
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/expiration_config_parser.h>
#include <dhcpsrv/parsers/host_reservation_parser.h>
#include <dhcpsrv/parsers/host_reservations_list_parser.h>
#include <dhcpsrv/parsers/ifaces_config_parser.h>
......@@ -405,6 +406,8 @@ namespace dhcp {
parser = new BooleanParser(config_id, globalContext()->boolean_values_);
} else if (config_id.compare("control-socket") == 0) {
parser = new ControlSocketParser(config_id);
} else if (config_id.compare("expired-leases-processing") == 0) {
parser = new ExpirationConfigParser();
} else {
isc_throw(DhcpConfigError,
"unsupported global configuration parameter: "
......
......@@ -29,6 +29,7 @@
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_expiration.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/testutils/config_result_check.h>
......@@ -3712,4 +3713,73 @@ TEST_F(Dhcp4ParserTest, declineTimerError) {
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
}
// Check that configuration for the expired leases processing may be
// specified.
TEST_F(Dhcp4ParserTest, expiredLeasesProcessing) {
// Create basic configuration with the expiration specific parameters.
string config = "{ " + genIfaceConfig() + "," +
"\"expired-leases-processing\": "
"{"
" \"reclaim-timer-wait-time\": 20,"
" \"flush-reclaimed-timer-wait-time\": 35,"
" \"hold-reclaimed-time\": 1800,"
" \"max-reclaim-leases\": 50,"
" \"max-reclaim-time\": 100,"
" \"unwarned-reclaim-cycles\": 10"
"},"
"\"subnet4\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
// Returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// value specified.
CfgExpirationPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgExpiration();
ASSERT_TRUE(cfg);
// Verify that parameters are correct.
EXPECT_EQ(20, cfg->getReclaimTimerWaitTime());
EXPECT_EQ(35, cfg->getFlushReclaimedTimerWaitTime());
EXPECT_EQ(1800, cfg->getHoldReclaimedTime());
EXPECT_EQ(50, cfg->getMaxReclaimLeases());
EXPECT_EQ(100, cfg->getMaxReclaimTime());
EXPECT_EQ(10, cfg->getUnwarnedReclaimCycles());
}
// Check that invalid configuration for the expired leases processing is
// causing an error.
TEST_F(Dhcp4ParserTest, expiredLeasesProcessingError) {
// Create basic configuration with the expiration specific parameters.
// One of the parameters holds invalid value.
string config = "{ " + genIfaceConfig() + "," +
"\"expired-leases-processing\": "
"{"
" \"reclaim-timer-wait-time\": -5,"
" \"flush-reclaimed-timer-wait-time\": 35,"
" \"hold-reclaimed-time\": 1800,"
" \"max-reclaim-leases\": 50,"
" \"max-reclaim-time\": 100,"
" \"unwarned-reclaim-cycles\": 10"
"},"
"\"subnet4\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
// Returned value should be 0 (error)
checkResult(status, 1);
// Check that the error contains error position.
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
}
}
......@@ -30,6 +30,7 @@
#include <dhcpsrv/parsers/dbaccess_parser.h>
#include <dhcpsrv/parsers/dhcp_config_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/expiration_config_parser.h>
#include <dhcpsrv/parsers/host_reservation_parser.h>
#include <dhcpsrv/parsers/host_reservations_list_parser.h>
#include <dhcpsrv/parsers/ifaces_config_parser.h>
......@@ -697,6 +698,8 @@ namespace dhcp {
parser = new RSOOListConfigParser(config_id);
} else if (config_id.compare("control-socket") == 0) {
parser = new ControlSocketParser(config_id);
} else if (config_id.compare("expired-leases-processing") == 0) {
parser = new ExpirationConfigParser();
} else {
isc_throw(DhcpConfigError,
"unsupported global configuration parameter: "
......
......@@ -26,6 +26,7 @@
#include <dhcp6/dhcp6_srv.h>
#include <dhcpsrv/addr_utilities.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_expiration.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
......@@ -4046,5 +4047,74 @@ TEST_F(Dhcp6ParserTest, declineTimerError) {
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
}
// Check that configuration for the expired leases processing may be
// specified.
TEST_F(Dhcp6ParserTest, expiredLeasesProcessing) {
// Create basic configuration with the expiration specific parameters.
string config = "{ " + genIfaceConfig() + "," +
"\"expired-leases-processing\": "
"{"
" \"reclaim-timer-wait-time\": 20,"
" \"flush-reclaimed-timer-wait-time\": 35,"
" \"hold-reclaimed-time\": 1800,"
" \"max-reclaim-leases\": 50,"
" \"max-reclaim-time\": 100,"
" \"unwarned-reclaim-cycles\": 10"
"},"
"\"subnet6\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
// Returned value should be 0 (success)
checkResult(status, 0);
// The value of decline-probation-perion must be equal to the
// value specified.
CfgExpirationPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgExpiration();
ASSERT_TRUE(cfg);
// Verify that parameters are correct.
EXPECT_EQ(20, cfg->getReclaimTimerWaitTime());
EXPECT_EQ(35, cfg->getFlushReclaimedTimerWaitTime());
EXPECT_EQ(1800, cfg->getHoldReclaimedTime());
EXPECT_EQ(50, cfg->getMaxReclaimLeases());
EXPECT_EQ(100, cfg->getMaxReclaimTime());
EXPECT_EQ(10, cfg->getUnwarnedReclaimCycles());
}
// Check that invalid configuration for the expired leases processing is
// causing an error.
TEST_F(Dhcp6ParserTest, expiredLeasesProcessingError) {
// Create basic configuration with the expiration specific parameters.
// One of the parameters holds invalid value.
string config = "{ " + genIfaceConfig() + "," +
"\"expired-leases-processing\": "
"{"
" \"reclaim-timer-wait-time\": -5,"
" \"flush-reclaimed-timer-wait-time\": 35,"
" \"hold-reclaimed-time\": 1800,"
" \"max-reclaim-leases\": 50,"
" \"max-reclaim-time\": 100,"
" \"unwarned-reclaim-cycles\": 10"
"},"
"\"subnet6\": [ ]"
"}";
ElementPtr json = Element::fromJSON(config);
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json));
// Returned value should be 0 (error)
checkResult(status, 1);
// Check that the error contains error position.
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment