Browse Source

[3501] Corrected error messages reported when configuration error occurs.

Also, removed multiple references to DHCP4_CONFIG_LOAD_FAIL from the
DHCPv4 server and DHCP6_CONFIG_LOAD_FAIL from the DHCPv6 server.
Marcin Siodelski 10 years ago
parent
commit
05d934f2eb

+ 5 - 4
src/bin/dhcp4/dhcp4_messages.mes

@@ -50,10 +50,11 @@ new configuration. It is output during server startup, and when an updated
 configuration is committed by the administrator.  Additional information
 configuration is committed by the administrator.  Additional information
 may be provided.
 may be provided.
 
 
-% DHCP4_CONFIG_LOAD_FAIL failed to load configuration: %1
+% DHCP4_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
-This critical error message indicates that the initial DHCPv4
+This error message indicates that the DHCPv4 configuration has failed.
-configuration has failed. The server will start, but nothing will be
+If this is an initial configuration (during server's startup) the server
-served until the configuration has been corrected.
+will fail to start. If this is a dynamic reconfiguration attempt the
+server will continue to use an old configuration.
 
 
 % DHCP4_CONFIG_NEW_SUBNET a new subnet has been added to configuration: %1
 % DHCP4_CONFIG_NEW_SUBNET a new subnet has been added to configuration: %1
 This is an informational message reporting that the configuration has
 This is an informational message reporting that the configuration has

+ 7 - 9
src/bin/dhcp4/json_config_parser.cc

@@ -594,8 +594,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
     } catch (const isc::Exception& ex) {
     } catch (const isc::Exception& ex) {
         LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
         LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
                   .arg(config_pair.first).arg(ex.what());
                   .arg(config_pair.first).arg(ex.what());
-        answer = isc::config::createAnswer(1,
+        answer = isc::config::createAnswer(1, ex.what());
-                     string("Configuration parsing failed: ") + ex.what());
 
 
         // An error occured, so make sure that we restore original data.
         // An error occured, so make sure that we restore original data.
         rollback = true;
         rollback = true;
@@ -603,8 +602,8 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
     } catch (...) {
     } catch (...) {
         // For things like bad_cast in boost::lexical_cast
         // For things like bad_cast in boost::lexical_cast
         LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
         LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
-        answer = isc::config::createAnswer(1,
+        answer = isc::config::createAnswer(1, "undefined configuration"
-                     string("Configuration parsing failed"));
+                                           " processing error");
 
 
         // An error occured, so make sure that we restore original data.
         // An error occured, so make sure that we restore original data.
         rollback = true;
         rollback = true;
@@ -636,14 +635,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
         }
         }
         catch (const isc::Exception& ex) {
         catch (const isc::Exception& ex) {
             LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
             LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
-            answer = isc::config::createAnswer(2,
+            answer = isc::config::createAnswer(2, ex.what());
-                         string("Configuration commit failed: ") + ex.what());
             rollback = true;
             rollback = true;
         } catch (...) {
         } catch (...) {
             // For things like bad_cast in boost::lexical_cast
             // For things like bad_cast in boost::lexical_cast
             LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
             LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
-            answer = isc::config::createAnswer(2,
+            answer = isc::config::createAnswer(2, "undefined configuration"
-                         string("Configuration commit failed"));
+                                               " parsing error");
             rollback = true;
             rollback = true;
         }
         }
     }
     }
@@ -659,7 +657,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
              getConfigSummary(Configuration::CFGSEL_ALL4));
              getConfigSummary(Configuration::CFGSEL_ALL4));
 
 
     // Everything was fine. Configuration is successful.
     // Everything was fine. Configuration is successful.
-    answer = isc::config::createAnswer(0, "Configuration committed.");
+    answer = isc::config::createAnswer(0, "Configuration successful.");
     return (answer);
     return (answer);
 }
 }
 
 

+ 24 - 37
src/bin/dhcp4/kea_controller.cc

@@ -56,12 +56,8 @@ void configure(const std::string& file_name) {
 
 
         // Read contents of the file and parse it as JSON
         // Read contents of the file and parse it as JSON
         json = isc::data::Element::fromJSONFile(file_name, true);
         json = isc::data::Element::fromJSONFile(file_name, true);
-
         if (!json) {
         if (!json) {
-            LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
+            isc_throw(isc::BadValue, "no configuration found");
-                .arg("Config file " + file_name + " missing or empty.");
-            isc_throw(isc::BadValue, "Unable to process JSON configuration"
-                      " file: " << file_name);
         }
         }
 
 
         // Let's configure logging before applying the configuration,
         // Let's configure logging before applying the configuration,
@@ -75,46 +71,37 @@ void configure(const std::string& file_name) {
 
 
         // Get Dhcp4 component from the config
         // Get Dhcp4 component from the config
         dhcp4 = json->get("Dhcp4");
         dhcp4 = json->get("Dhcp4");
-
         if (!dhcp4) {
         if (!dhcp4) {
-            LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
+            isc_throw(isc::BadValue, "no mandatory 'Dhcp4' entry in"
-                .arg("Config file " + file_name + " does not include 'Dhcp4'"
+                      " the configuration");
-                     " entry.");
-            isc_throw(isc::BadValue, "Unable to process JSON configuration"
-                      " file: " << file_name);
         }
         }
 
 
         // Use parsed JSON structures to configure the server
         // Use parsed JSON structures to configure the server
         result = ControlledDhcpv4Srv::processCommand("config-reload", dhcp4);
         result = ControlledDhcpv4Srv::processCommand("config-reload", dhcp4);
+        if (!result) {
+            // Undetermined status of the configuration. This should never
+            // happen, but as the configureDhcp4Server returns a pointer, it is
+            // theoretically possible that it will return NULL.
+            isc_throw(isc::BadValue, "undefined result of "
+                      "processCommand(\"config-reload\", dhcp4)");
+        }
 
 
-    }  catch (const std::exception& ex) {
+        // Now check is the returned result is successful (rcode=0) or not
-        LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL).arg(ex.what());
+        // (see @ref isc::config::parseAnswer).
-        isc_throw(isc::BadValue, "Unable to process JSON configuration file: "
+        int rcode;
-                  << file_name);
+        isc::data::ConstElementPtr comment =
-    }
+            isc::config::parseAnswer(rcode, result);
+        if (rcode != 0) {
+            string reason = comment ? comment->stringValue() :
+                "no details available";
+            isc_throw(isc::BadValue, reason);
+        }
 
 
-    if (!result) {
+    }  catch (const std::exception& ex) {
-        // Undetermined status of the configuration. This should never happen,
-        // but as the configureDhcp4Server returns a pointer, it is
-        // theoretically possible that it will return NULL.
         LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
         LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
-            .arg("Configuration failed: Undefined result of processCommand("
+            .arg(file_name).arg(ex.what());
-                 "config-reload, " + file_name + ")");
+        isc_throw(isc::BadValue, "configuration error using file '"
-        isc_throw(isc::BadValue, "Configuration failed: Undefined result of "
+                  << file_name << "': " << ex.what());
-                  "processCommand('config-reload', " << file_name << ")");
-    }
-
-    // Now check is the returned result is successful (rcode=0) or not
-    isc::data::ConstElementPtr comment; /// see @ref isc::config::parseAnswer
-    int rcode;
-    comment = isc::config::parseAnswer(rcode, result);
-    if (rcode != 0) {
-        string reason = "";
-        if (comment) {
-            reason = comment->stringValue();
-        }
-        LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL).arg(reason);
-        isc_throw(isc::BadValue, "Failed to apply configuration: " << reason);
     }
     }
 }
 }
 
 

+ 5 - 4
src/bin/dhcp6/dhcp6_messages.mes

@@ -46,10 +46,11 @@ new configuration. it is output during server startup, and when an updated
 configuration is committed by the administrator.  Additional information
 configuration is committed by the administrator.  Additional information
 may be provided.
 may be provided.
 
 
-% DHCP6_CONFIG_LOAD_FAIL failed to load configuration: %1
+% DHCP6_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
-This critical error message indicates that the initial DHCPv6
+This error message indicates that the DHCPv6 configuration has failed.
-configuration has failed. The server will start, but nothing will be
+If this is an initial configuration (during server's startup) the server
-served until the configuration has been corrected.
+will fail to start. If this is a dynamic reconfiguration attempt the
+server will continue to use an old configuration.
 
 
 % DHCP6_CONFIG_NEW_SUBNET a new subnet has been added to configuration: %1
 % DHCP6_CONFIG_NEW_SUBNET a new subnet has been added to configuration: %1
 This is an informational message reporting that the configuration has
 This is an informational message reporting that the configuration has

+ 7 - 9
src/bin/dhcp6/json_config_parser.cc

@@ -798,16 +798,15 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
     } catch (const isc::Exception& ex) {
     } catch (const isc::Exception& ex) {
         LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
         LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
                   .arg(config_pair.first).arg(ex.what());
                   .arg(config_pair.first).arg(ex.what());
-        answer = isc::config::createAnswer(1,
+        answer = isc::config::createAnswer(1, ex.what());
-                     string("Configuration parsing failed: ") + ex.what());
         // An error occured, so make sure that we restore original data.
         // An error occured, so make sure that we restore original data.
         rollback = true;
         rollback = true;
 
 
     } catch (...) {
     } catch (...) {
         // for things like bad_cast in boost::lexical_cast
         // for things like bad_cast in boost::lexical_cast
         LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(config_pair.first);
         LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(config_pair.first);
-        answer = isc::config::createAnswer(1,
+        answer = isc::config::createAnswer(1, "undefined configuration"
-                     string("Configuration parsing failed"));
+                                           " processing error");
         // An error occured, so make sure that we restore original data.
         // An error occured, so make sure that we restore original data.
         rollback = true;
         rollback = true;
     }
     }
@@ -835,15 +834,14 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
         }
         }
         catch (const isc::Exception& ex) {
         catch (const isc::Exception& ex) {
             LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
             LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
-            answer = isc::config::createAnswer(2,
+            answer = isc::config::createAnswer(2, ex.what());
-                         string("Configuration commit failed:") + ex.what());
             // An error occured, so make sure to restore the original data.
             // An error occured, so make sure to restore the original data.
             rollback = true;
             rollback = true;
         } catch (...) {
         } catch (...) {
             // for things like bad_cast in boost::lexical_cast
             // for things like bad_cast in boost::lexical_cast
             LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
             LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
-            answer = isc::config::createAnswer(2,
+            answer = isc::config::createAnswer(2, "undefined configuration"
-                         string("Configuration commit failed"));
+                                               " parsing error");
             // An error occured, so make sure to restore the original data.
             // An error occured, so make sure to restore the original data.
             rollback = true;
             rollback = true;
         }
         }
@@ -860,7 +858,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
              getConfigSummary(Configuration::CFGSEL_ALL6));
              getConfigSummary(Configuration::CFGSEL_ALL6));
 
 
     // Everything was fine. Configuration is successful.
     // Everything was fine. Configuration is successful.
-    answer = isc::config::createAnswer(0, "Configuration committed.");
+    answer = isc::config::createAnswer(0, "Configuration successful.");
     return (answer);
     return (answer);
 }
 }
 
 

+ 24 - 33
src/bin/dhcp6/kea_controller.cc

@@ -60,12 +60,8 @@ void configure(const std::string& file_name) {
 
 
         // Read contents of the file and parse it as JSON
         // Read contents of the file and parse it as JSON
         json = isc::data::Element::fromJSONFile(file_name, true);
         json = isc::data::Element::fromJSONFile(file_name, true);
-
         if (!json) {
         if (!json) {
-            LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
+            isc_throw(isc::BadValue, "no configuration found");
-                .arg("Config file " + file_name + " missing or empty.");
-            isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
-                      + file_name);
         }
         }
 
 
         // Let's configure logging before applying the configuration,
         // Let's configure logging before applying the configuration,
@@ -80,43 +76,38 @@ void configure(const std::string& file_name) {
         dhcp6 = json->get("Dhcp6");
         dhcp6 = json->get("Dhcp6");
 
 
         if (!dhcp6) {
         if (!dhcp6) {
-            LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
+            isc_throw(isc::BadValue, "no mandatory 'Dhcp6' entry in"
-                .arg("Config file " + file_name + " does not include 'Dhcp6' entry.");
+                      " the configuration");
-            isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
-                      + file_name);
         }
         }
 
 
         // Use parsed JSON structures to configure the server
         // Use parsed JSON structures to configure the server
         result = ControlledDhcpv6Srv::processCommand("config-reload", dhcp6);
         result = ControlledDhcpv6Srv::processCommand("config-reload", dhcp6);
+        if (!result) {
+            // Undetermined status of the configuration. This should never
+            // happen, but as the configureDhcp6Server returns a pointer, it is
+            // theoretically possible that it will return NULL.
+            isc_throw(isc::BadValue, "undefined result of "
+                      "processCommand(\"config-reload\", dhcp6)");
+        }
 
 
-    }  catch (const std::exception& ex) {
+        // Now check is the returned result is successful (rcode=0) or not
-        LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL).arg(ex.what());
+        // (see @ref isc::config::parseAnswer).
-        isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
+        int rcode;
-                  + file_name);
+        isc::data::ConstElementPtr comment =
-    }
+            isc::config::parseAnswer(rcode, result);
+        if (rcode != 0) {
+            string reason = comment ? comment->stringValue() :
+                "no details available";
+            isc_throw(isc::BadValue, reason);
+        }
 
 
-    if (!result) {
+    }  catch (const std::exception& ex) {
-        // Undetermined status of the configuration. This should never happen,
-        // but as the configureDhcp6Server returns a pointer, it is theoretically
-        // possible that it will return NULL.
         LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
         LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
-            .arg("Configuration failed: Undefined result of configureDhcp6Server"
+            .arg(file_name).arg(ex.what());
-                 "() function after attempting to read " + file_name);
+        isc_throw(isc::BadValue, "configuration error using file '"
-        return;
+                  << file_name << "': " << ex.what());
     }
     }
 
 
-    // Now check is the returned result is successful (rcode=0) or not
-    isc::data::ConstElementPtr comment; /// see @ref isc::config::parseAnswer
-    int rcode;
-    comment = isc::config::parseAnswer(rcode, result);
-    if (rcode != 0) {
-        string reason = "";
-        if (comment) {
-            reason = comment->stringValue();
-        }
-        LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL).arg(reason);
-        isc_throw(isc::BadValue, "Failed to apply configuration:" << reason);
-    }
 }
 }
 
 
 /// @brief Signals handler for DHCPv6 server.
 /// @brief Signals handler for DHCPv6 server.

+ 2 - 2
src/lib/cc/data.cc

@@ -736,8 +736,8 @@ Element::fromJSONFile(const std::string& file_name,
     if (!infile.is_open())
     if (!infile.is_open())
     {
     {
         const char* error = strerror(errno);
         const char* error = strerror(errno);
-        isc_throw(InvalidOperation, "Failed to read file '" << file_name
+        isc_throw(InvalidOperation, "failed to read file '" << file_name
-                  << "', error:" << error);
+                  << "': " << error);
     }
     }
 
 
     return (fromJSON(infile, file_name, preproc));
     return (fromJSON(infile, file_name, preproc));