Commit 58e23d61 authored by Thomas Markwalder's avatar Thomas Markwalder

[#260,!120] Added dhcp-queue-control parser defaults

    Added dhcp-queue-control defaults to SimpleParser<4/6>
    Revamped server config unit tests
parent bab0f0ad
......@@ -639,7 +639,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CONFIG_PACKET_QUEUE)
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_PACKET_QUEUE)
.arg(PacketQueueMgr4::instance().getPacketQueue()->getInfoStr());
}
......
......@@ -121,9 +121,9 @@ configuration is committed by the administrator. Additional information
may be provided.
% DHCP4_CONFIG_PACKET_QUEUE DHCPv4 packet queue info after configuration: %1
This debug message is emitted during DHCPv4 server configuration, immediately
after configuring the DHCPv4 packet queue. The information shown depends
upon the packet queue type selected.
This informational message is emitted during DHCPv4 server configuration,
immediately after configuring the DHCPv4 packet queue. The information
shown depends upon the packet queue type selected.
% DHCP4_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
This error message indicates that the DHCPv4 configuration has failed.
......
......@@ -24,6 +24,7 @@
#include <dhcpsrv/cfg_expiration.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/parsers/simple_parser4.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/testutils/test_config_backend_dhcp4.h>
#include <process/config_ctl_info.h>
......@@ -6469,12 +6470,12 @@ TEST_F(Dhcp4ParserTest, dhcpQueueControl) {
};
// Let's check the default. It should be empty.
data::ConstElementPtr control;
control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
ASSERT_FALSE(control);
data::ConstElementPtr staged_control;
staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
ASSERT_FALSE(staged_control);
// Iterate over the valid scenarios and verify they succeed.
data::ConstElementPtr exp_elems;
data::ElementPtr exp_control;
for (auto scenario : scenarios) {
SCOPED_TRACE(scenario.description_);
{
......@@ -6485,7 +6486,6 @@ TEST_F(Dhcp4ParserTest, dhcpQueueControl) {
std::stringstream os;
os << "{ " + genIfaceConfig();
if (!scenario.json_.empty()) {
os << ",\n \"dhcp-queue-control\": " << scenario.json_;
}
......@@ -6495,20 +6495,28 @@ TEST_F(Dhcp4ParserTest, dhcpQueueControl) {
configure(os.str(), CONTROL_RESULT_SUCCESS, "");
// Fetch the queue control info.
control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
// Make sure the staged queue config exists.
ASSERT_TRUE(staged_control);
// If JSON does not contain queue control,
// the pointer stored in staging should be empty.
// Now build the expected queue control content.
if (scenario.json_.empty()) {
ASSERT_FALSE(control);
continue;
exp_control = Element::createMap();
} else {
try {
exp_control = boost::const_pointer_cast<Element>(Element::fromJSON(scenario.json_));
} catch (const std::exception& ex) {
ADD_FAILURE() << " cannot convert expected JSON, test is broken:"
<< ex.what();
}
}
// Make sure the staged config is correct.
ASSERT_TRUE(control);
ASSERT_NO_THROW(exp_elems = Element::fromJSON(scenario.json_))
<< " cannot convert expected JSON, test is broken";
EXPECT_TRUE(control->equals(*exp_elems));
// Add the defaults to expected queue control.
SimpleParser4::setDefaults(exp_control, SimpleParser4::DHCP_QUEUE_CONTROL4_DEFAULTS);
// Verify that the staged queue control equals the expected queue control.
EXPECT_TRUE(staged_control->equals(*exp_control));
}
}
}
......
This diff is collapsed.
......@@ -658,8 +658,8 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CONFIG_PACKET_QUEUE)
.arg(PacketQueueMgr6::instance().getPacketQueue()->getInfoStr());
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
.arg(PacketQueueMgr6::instance().getPacketQueue()->getInfoStr());
}
} catch (const std::exception& ex) {
......
......@@ -91,9 +91,9 @@ will fail to start. If this is a dynamic reconfiguration attempt the
server will continue to use an old configuration.
% DHCP6_CONFIG_PACKET_QUEUE DHCPv6 packet queue info after configuration: %1
This debug message is emitted during DHCPv6 server configuration, immediately
after configuring the DHCPv6 packet queue. The information shown depends
upon the packet queue type selected.
This informational message is emitted during DHCPv6 server configuration,
immediately after configuring the DHCPv6 packet queue. The information
shown depends upon the packet queue type selected.
% DHCP6_CONFIG_RECEIVED received configuration: %1
A debug message listing the configuration received by the DHCPv6 server.
......
......@@ -21,6 +21,7 @@
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_expiration.h>
#include <dhcpsrv/cfg_hosts.h>
#include <dhcpsrv/parsers/simple_parser6.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet_selector.h>
#include <dhcpsrv/testutils/config_result_check.h>
......@@ -6970,12 +6971,12 @@ TEST_F(Dhcp6ParserTest, dhcpQueueControl) {
};
// Let's check the default. It should be empty.
data::ConstElementPtr control;
control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
ASSERT_FALSE(control);
data::ConstElementPtr staged_control;
staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
ASSERT_FALSE(staged_control);
// Iterate over the valid scenarios and verify they succeed.
data::ConstElementPtr exp_elems;
data::ElementPtr exp_control;
for (auto scenario : scenarios) {
SCOPED_TRACE(scenario.description_);
{
......@@ -6986,7 +6987,6 @@ TEST_F(Dhcp6ParserTest, dhcpQueueControl) {
std::stringstream os;
os << "{ " + genIfaceConfig();
if (!scenario.json_.empty()) {
os << ",\n \"dhcp-queue-control\": " << scenario.json_;
}
......@@ -6996,20 +6996,28 @@ TEST_F(Dhcp6ParserTest, dhcpQueueControl) {
configure(os.str(), CONTROL_RESULT_SUCCESS, "");
// Fetch the queue control info.
control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
// Make sure the staged queue config exists.
ASSERT_TRUE(staged_control);
// If JSON does not contain queue control,
// the pointer stored in staging should be empty.
// Now build the expected queue control content.
if (scenario.json_.empty()) {
ASSERT_FALSE(control);
continue;
exp_control = Element::createMap();
} else {
try {
exp_control = boost::const_pointer_cast<Element>(Element::fromJSON(scenario.json_));
} catch (const std::exception& ex) {
ADD_FAILURE() << " cannot convert expected JSON, test is broken:"
<< ex.what();
}
}
// Make sure the staged config is correct.
ASSERT_TRUE(control);
ASSERT_NO_THROW(exp_elems = Element::fromJSON(scenario.json_))
<< " cannot convert expected JSON, test is broken";
EXPECT_TRUE(control->equals(*exp_elems));
// Add the defaults to expected queue control.
SimpleParser6::setDefaults(exp_control, SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS);
// Verify that the staged queue control equals the expected queue control.
EXPECT_TRUE(staged_control->equals(*exp_control));
}
}
}
......
This diff is collapsed.
......@@ -136,6 +136,14 @@ const ParamsList SimpleParser4::INHERIT_TO_SUBNET4 = {
"valid-lifetime"
};
/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
const SimpleDefaults SimpleParser4::DHCP_QUEUE_CONTROL4_DEFAULTS = {
{ "enable-queue", Element::boolean, "false"},
{ "queue-type", Element::string, "kea-ring4"},
{ "capacity", Element::integer, "500"}
};
/// @}
/// ---------------------------------------------------------------------------
......@@ -189,6 +197,19 @@ size_t SimpleParser4::setAllDefaults(isc::data::ElementPtr global) {
}
}
// Set the defaults for dhcp-queue-control. If the element isn't
// there we'll add it.
ConstElementPtr queue_control = global->get("dhcp-queue-control");
ElementPtr mutable_cfg;
if (queue_control) {
mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
} else {
mutable_cfg = Element::createMap();
global->set("dhcp-queue-control", mutable_cfg);
}
cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
return (cnt);
}
......
......@@ -44,6 +44,7 @@ public:
static const isc::data::SimpleDefaults SHARED_SUBNET4_DEFAULTS;
static const isc::data::SimpleDefaults SHARED_NETWORK4_DEFAULTS;
static const isc::data::SimpleDefaults IFACE4_DEFAULTS;
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL4_DEFAULTS;
static const isc::data::ParamsList INHERIT_TO_SUBNET4;
};
......
......@@ -117,6 +117,15 @@ const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = {
"reservation-mode",
"valid-lifetime"
};
/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
{ "enable-queue", Element::boolean, "false"},
{ "queue-type", Element::string, "kea-ring6"},
{ "capacity", Element::integer, "500"}
};
/// @}
/// ---------------------------------------------------------------------------
......@@ -172,6 +181,19 @@ size_t SimpleParser6::setAllDefaults(isc::data::ElementPtr global) {
}
}
// Set the defaults for dhcp-queue-control. If the element isn't there
// we'll add it.
ConstElementPtr queue_control = global->get("dhcp-queue-control");
ElementPtr mutable_cfg;
if (queue_control) {
mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
} else {
mutable_cfg = Element::createMap();
global->set("dhcp-queue-control", mutable_cfg);
}
cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
return (cnt);
}
......
......@@ -45,6 +45,7 @@ public:
static const isc::data::SimpleDefaults SHARED_SUBNET6_DEFAULTS;
static const isc::data::SimpleDefaults SHARED_NETWORK6_DEFAULTS;
static const isc::data::SimpleDefaults IFACE6_DEFAULTS;
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL6_DEFAULTS;
static const isc::data::ParamsList INHERIT_TO_SUBNET6;
};
......
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