Commit 69c2e41c authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3512] Interface list config parser has separation of the commit and build.

parent 4bac0846
...@@ -189,12 +189,14 @@ InterfaceListConfigParser(const std::string& param_name) ...@@ -189,12 +189,14 @@ InterfaceListConfigParser(const std::string& param_name)
void void
InterfaceListConfigParser::build(ConstElementPtr value) { InterfaceListConfigParser::build(ConstElementPtr value) {
// Copy the current interface configuration.
ConfigurationPtr config = CfgMgr::instance().getConfiguration(); ConfigurationPtr config = CfgMgr::instance().getConfiguration();
config->cfg_iface_.reset(); cfg_iface_ = config->cfg_iface_;
cfg_iface_.reset();
BOOST_FOREACH(ConstElementPtr iface, value->listValue()) { BOOST_FOREACH(ConstElementPtr iface, value->listValue()) {
std::string iface_name = iface->stringValue(); std::string iface_name = iface->stringValue();
try { try {
config->cfg_iface_.use(iface_name); cfg_iface_.use(iface_name);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
isc_throw(DhcpConfigError, "Failed to select interface: " isc_throw(DhcpConfigError, "Failed to select interface: "
...@@ -205,7 +207,8 @@ InterfaceListConfigParser::build(ConstElementPtr value) { ...@@ -205,7 +207,8 @@ InterfaceListConfigParser::build(ConstElementPtr value) {
void void
InterfaceListConfigParser::commit() { InterfaceListConfigParser::commit() {
// Do nothing. CfgMgr has been updated during build. // Use the new configuration created in a build time.
CfgMgr::instance().getConfiguration()->cfg_iface_ = cfg_iface_;
} }
bool bool
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <dhcp/option_definition.h> #include <dhcp/option_definition.h>
#include <dhcpsrv/d2_client_cfg.h> #include <dhcpsrv/d2_client_cfg.h>
#include <dhcpsrv/dhcp_config_parser.h> #include <dhcpsrv/dhcp_config_parser.h>
#include <dhcpsrv/cfg_iface.h>
#include <dhcpsrv/option_space_container.h> #include <dhcpsrv/option_space_container.h>
#include <dhcpsrv/subnet.h> #include <dhcpsrv/subnet.h>
#include <exceptions/exceptions.h> #include <exceptions/exceptions.h>
...@@ -406,7 +407,9 @@ public: ...@@ -406,7 +407,9 @@ public:
/// @param value pointer to the content of parsed values /// @param value pointer to the content of parsed values
virtual void build(isc::data::ConstElementPtr value); virtual void build(isc::data::ConstElementPtr value);
/// @brief Does nothing. /// @brief Assignes a parsed list of interfaces to the configuration.
///
/// This is exception safe operation.
virtual void commit(); virtual void commit();
private: private:
...@@ -424,6 +427,9 @@ private: ...@@ -424,6 +427,9 @@ private:
// Parsed parameter name // Parsed parameter name
std::string param_name_; std::string param_name_;
/// Holds the configuration created during
CfgIface cfg_iface_;
}; };
/// @brief Parser for hooks library list /// @brief Parser for hooks library list
......
...@@ -236,6 +236,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) { ...@@ -236,6 +236,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
// This should parse the configuration and add eth0 and eth1 to the list // This should parse the configuration and add eth0 and eth1 to the list
// of interfaces that server should listen on. // of interfaces that server should listen on.
parser->build(list_element); parser->build(list_element);
parser->commit();
// Use CfgMgr instance to check if eth0 and eth1 was added, and that // Use CfgMgr instance to check if eth0 and eth1 was added, and that
// eth2 was not added. // eth2 was not added.
...@@ -257,6 +258,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) { ...@@ -257,6 +258,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
cfg->cfg_iface_.reset(); cfg->cfg_iface_.reset();
parser->build(list_element); parser->build(list_element);
parser->commit();
ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000)); ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000));
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET)); EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));
......
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