Browse Source

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

Marcin Siodelski 10 years ago
parent
commit
69c2e41c8b

+ 6 - 3
src/lib/dhcpsrv/dhcp_parsers.cc

@@ -189,12 +189,14 @@ InterfaceListConfigParser(const std::string& param_name)
 
 void
 InterfaceListConfigParser::build(ConstElementPtr value) {
+    // Copy the current interface configuration.
     ConfigurationPtr config = CfgMgr::instance().getConfiguration();
-    config->cfg_iface_.reset();
+    cfg_iface_ = config->cfg_iface_;
+    cfg_iface_.reset();
     BOOST_FOREACH(ConstElementPtr iface, value->listValue()) {
         std::string iface_name = iface->stringValue();
         try {
-            config->cfg_iface_.use(iface_name);
+            cfg_iface_.use(iface_name);
 
         } catch (const std::exception& ex) {
             isc_throw(DhcpConfigError, "Failed to select interface: "
@@ -205,7 +207,8 @@ InterfaceListConfigParser::build(ConstElementPtr value) {
 
 void
 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

+ 7 - 1
src/lib/dhcpsrv/dhcp_parsers.h

@@ -20,6 +20,7 @@
 #include <dhcp/option_definition.h>
 #include <dhcpsrv/d2_client_cfg.h>
 #include <dhcpsrv/dhcp_config_parser.h>
+#include <dhcpsrv/cfg_iface.h>
 #include <dhcpsrv/option_space_container.h>
 #include <dhcpsrv/subnet.h>
 #include <exceptions/exceptions.h>
@@ -406,7 +407,9 @@ public:
     /// @param value pointer to the content of parsed values
     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();
 
 private:
@@ -424,6 +427,9 @@ private:
 
     // Parsed parameter name
     std::string param_name_;
+
+    /// Holds the configuration created during
+    CfgIface cfg_iface_;
 };
 
 /// @brief Parser for hooks library list

+ 2 - 0
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

@@ -236,6 +236,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
     // This should parse the configuration and add eth0 and eth1 to the list
     // of interfaces that server should listen on.
     parser->build(list_element);
+    parser->commit();
 
     // Use CfgMgr instance to check if eth0 and eth1 was added, and that
     // eth2 was not added.
@@ -257,6 +258,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
     cfg->cfg_iface_.reset();
 
     parser->build(list_element);
+    parser->commit();
     ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000));
 
     EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));