Parcourir la source

[5152] Introduced checkConfig()

Francis Dupont il y a 8 ans
Parent
commit
882eff53c2

+ 4 - 4
src/bin/d2/tests/d2_controller_unittests.cc

@@ -177,24 +177,24 @@ TEST_F(D2ControllerTest, configUpdateTests) {
                                 isc::data::Element::fromJSON(valid_d2_config);
 
     // Verify that given a valid config we get a successful update result.
-    answer = updateConfig(config_set, false);
+    answer = updateConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(0, rcode);
 
     // Verify that given a valid config we get a successful check result.
-    answer = updateConfig(config_set, true);
+    answer = checkConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(0, rcode);
 
     // Use an invalid configuration to verify parsing error return.
     std::string config = "{ \"bogus\": 1000 } ";
     config_set = isc::data::Element::fromJSON(config);
-    answer = updateConfig(config_set, false);
+    answer = updateConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(1, rcode);
 
     // Use an invalid configuration to verify checking error return.
-    answer = updateConfig(config_set, true);
+    answer = checkConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(1, rcode);
 }

+ 10 - 5
src/lib/process/d_controller.cc

@@ -112,7 +112,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
             initProcess();
 
             isc::data::ConstElementPtr answer;
-            answer = updateConfig(module_config, true);
+            answer = checkConfig(module_config);
             int rcode = 0;
             answer = isc::config::parseAnswer(rcode, answer);
             if (rcode != 0) {
@@ -351,7 +351,7 @@ DControllerBase::configFromFile() {
                                  getAppName() << "' entry.");
         }
 
-        answer = updateConfig(module_config, false);
+        answer = updateConfig(module_config);
         int rcode = 0;
         isc::config::parseAnswer(rcode, answer);
         if (!rcode) {
@@ -390,9 +390,14 @@ DControllerBase::runProcess() {
 
 // Instance method for handling new config
 isc::data::ConstElementPtr
-DControllerBase::updateConfig(isc::data::ConstElementPtr new_config,
-                              bool check_only) {
-    return (process_->configure(new_config, check_only));
+DControllerBase::updateConfig(isc::data::ConstElementPtr new_config) {
+    return (process_->configure(new_config, false));
+}
+
+// Instance method for checking new config
+isc::data::ConstElementPtr
+DControllerBase::checkConfig(isc::data::ConstElementPtr new_config) {
+    return (process_->configure(new_config, true));
 }
 
 

+ 18 - 5
src/lib/process/d_controller.h

@@ -155,14 +155,27 @@ public:
     /// configuration and then invoke the application process' configure method.
     ///
     /// @param  new_config is the new configuration
-    /// @param check_only false for normal configuration, true when verifying only
     ///
     /// @return returns an Element that contains the results of configuration
     /// update composed of an integer status value (0 means successful,
     /// non-zero means failure), and a string explanation of the outcome.
-    virtual isc::data::ConstElementPtr
-    updateConfig(isc::data::ConstElementPtr new_config,
-                 bool check_only = false);
+    virtual isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr
+                                                    new_config);
+
+    /// @brief Instance method invoked by the configuration event handler and
+    /// which processes the actual configuration check.  Provides behavioral
+    /// path for both integrated and stand-alone modes. The current
+    /// implementation will merge the configuration update into the existing
+    /// configuration and then invoke the application process' configure method
+    /// with a final rollback.
+    ///
+    /// @param  new_config is the new configuration
+    ///
+    /// @return returns an Element that contains the results of configuration
+    /// update composed of an integer status value (0 means successful,
+    /// non-zero means failure), and a string explanation of the outcome.
+    virtual isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr
+                                                   new_config);
 
     /// @brief Reconfigures the process from a configuration file
     ///
@@ -194,7 +207,7 @@ public:
     ///
     /// It then extracts the set of configuration elements for the
     /// module-name that matches the controller's app_name_ and passes that
-    /// set into @c updateConfig().
+    /// set into @c updateConfig() (or @c checkConfig()).
     ///
     /// The file may contain an arbitrary number of other modules.
     ///

+ 4 - 4
src/lib/process/tests/d_controller_unittests.cc

@@ -268,24 +268,24 @@ TEST_F(DStubControllerTest, configUpdateTests) {
     isc::data::ElementPtr config_set = isc::data::Element::fromJSON(config);
 
     // Verify that a valid config gets a successful update result.
-    answer = updateConfig(config_set, false);
+    answer = updateConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(0, rcode);
 
     // Verify that a valid config gets a successful check result.
-    answer = updateConfig(config_set, true);
+    answer = checkConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(0, rcode);
 
     // Verify that an error in process configure method is handled.
     SimFailure::set(SimFailure::ftProcessConfigure);
-    answer = updateConfig(config_set, false);
+    answer = updateConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(1, rcode);
 
     // Verify that an error is handled too when the config is checked for.
     SimFailure::set(SimFailure::ftProcessConfigure);
-    answer = updateConfig(config_set, true);
+    answer = checkConfig(config_set);
     isc::config::parseAnswer(rcode, answer);
     EXPECT_EQ(1, rcode);
 }

+ 10 - 4
src/lib/process/testutils/d_test_stubs.h

@@ -487,10 +487,16 @@ public:
 
     /// @Wrapper to invoke the Controller's updateConfig method.  Please
     /// refer to DControllerBase::updateConfig for details.
-    isc::data::ConstElementPtr
-    updateConfig(isc::data::ConstElementPtr new_config,
-                 bool check_only) {
-        return (getController()->updateConfig(new_config, check_only));
+    isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr
+                                            new_config) {
+        return (getController()->updateConfig(new_config));
+    }
+
+    /// @Wrapper to invoke the Controller's checkConfig method.  Please
+    /// refer to DControllerBase::checkConfig for details.
+    isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr
+                                           new_config) {
+        return (getController()->checkConfig(new_config));
     }
 
     /// @Wrapper to invoke the Controller's executeCommand method.  Please