Commit ce6e519c authored by Marcin Siodelski's avatar Marcin Siodelski

[master] Merge branch 'trac3501'

parents c00f72b2 05d934f2
......@@ -50,10 +50,11 @@ new configuration. It is output during server startup, and when an updated
configuration is committed by the administrator. Additional information
may be provided.
% DHCP4_CONFIG_LOAD_FAIL failed to load configuration: %1
This critical error message indicates that the initial DHCPv4
configuration has failed. The server will start, but nothing will be
served until the configuration has been corrected.
% DHCP4_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
This error message indicates that the DHCPv4 configuration has failed.
If this is an initial configuration (during server's startup) the server
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
This is an informational message reporting that the configuration has
......
......@@ -594,8 +594,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
} catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_FAIL)
.arg(config_pair.first).arg(ex.what());
answer = isc::config::createAnswer(1,
string("Configuration parsing failed: ") + ex.what());
answer = isc::config::createAnswer(1, ex.what());
// An error occured, so make sure that we restore original data.
rollback = true;
......@@ -603,8 +602,8 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
} catch (...) {
// For things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_EXCEPTION).arg(config_pair.first);
answer = isc::config::createAnswer(1,
string("Configuration parsing failed"));
answer = isc::config::createAnswer(1, "undefined configuration"
" processing error");
// An error occured, so make sure that we restore original data.
rollback = true;
......@@ -636,14 +635,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
}
catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
answer = isc::config::createAnswer(2,
string("Configuration commit failed: ") + ex.what());
answer = isc::config::createAnswer(2, ex.what());
rollback = true;
} catch (...) {
// For things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_EXCEPTION);
answer = isc::config::createAnswer(2,
string("Configuration commit failed"));
answer = isc::config::createAnswer(2, "undefined configuration"
" parsing error");
rollback = true;
}
}
......@@ -659,7 +657,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
getConfigSummary(Configuration::CFGSEL_ALL4));
// Everything was fine. Configuration is successful.
answer = isc::config::createAnswer(0, "Configuration committed.");
answer = isc::config::createAnswer(0, "Configuration successful.");
return (answer);
}
......
......@@ -56,12 +56,8 @@ void configure(const std::string& file_name) {
// Read contents of the file and parse it as JSON
json = isc::data::Element::fromJSONFile(file_name, true);
if (!json) {
LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
.arg("Config file " + file_name + " missing or empty.");
isc_throw(isc::BadValue, "Unable to process JSON configuration"
" file: " << file_name);
isc_throw(isc::BadValue, "no configuration found");
}
// 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
dhcp4 = json->get("Dhcp4");
if (!dhcp4) {
LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
.arg("Config file " + file_name + " does not include 'Dhcp4'"
" entry.");
isc_throw(isc::BadValue, "Unable to process JSON configuration"
" file: " << file_name);
isc_throw(isc::BadValue, "no mandatory 'Dhcp4' entry in"
" the configuration");
}
// Use parsed JSON structures to configure the server
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) {
LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL).arg(ex.what());
isc_throw(isc::BadValue, "Unable to process JSON configuration file: "
<< file_name);
}
// Now check is the returned result is successful (rcode=0) or not
// (see @ref isc::config::parseAnswer).
int rcode;
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) {
// 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.
} catch (const std::exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_CONFIG_LOAD_FAIL)
.arg("Configuration failed: Undefined result of processCommand("
"config-reload, " + file_name + ")");
isc_throw(isc::BadValue, "Configuration failed: Undefined result of "
"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);
.arg(file_name).arg(ex.what());
isc_throw(isc::BadValue, "configuration error using file '"
<< file_name << "': " << ex.what());
}
}
......
......@@ -46,10 +46,11 @@ new configuration. it is output during server startup, and when an updated
configuration is committed by the administrator. Additional information
may be provided.
% DHCP6_CONFIG_LOAD_FAIL failed to load configuration: %1
This critical error message indicates that the initial DHCPv6
configuration has failed. The server will start, but nothing will be
served until the configuration has been corrected.
% DHCP6_CONFIG_LOAD_FAIL configuration error using file: %1, reason: %2
This error message indicates that the DHCPv6 configuration has failed.
If this is an initial configuration (during server's startup) the server
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
This is an informational message reporting that the configuration has
......
......@@ -798,16 +798,15 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
} catch (const isc::Exception& ex) {
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_FAIL)
.arg(config_pair.first).arg(ex.what());
answer = isc::config::createAnswer(1,
string("Configuration parsing failed: ") + ex.what());
answer = isc::config::createAnswer(1, ex.what());
// An error occured, so make sure that we restore original data.
rollback = true;
} catch (...) {
// for things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(config_pair.first);
answer = isc::config::createAnswer(1,
string("Configuration parsing failed"));
answer = isc::config::createAnswer(1, "undefined configuration"
" processing error");
// An error occured, so make sure that we restore original data.
rollback = true;
}
......@@ -835,15 +834,14 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
}
catch (const isc::Exception& ex) {
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
answer = isc::config::createAnswer(2,
string("Configuration commit failed:") + ex.what());
answer = isc::config::createAnswer(2, ex.what());
// An error occured, so make sure to restore the original data.
rollback = true;
} catch (...) {
// for things like bad_cast in boost::lexical_cast
LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_EXCEPTION);
answer = isc::config::createAnswer(2,
string("Configuration commit failed"));
answer = isc::config::createAnswer(2, "undefined configuration"
" parsing error");
// An error occured, so make sure to restore the original data.
rollback = true;
}
......@@ -860,7 +858,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
getConfigSummary(Configuration::CFGSEL_ALL6));
// Everything was fine. Configuration is successful.
answer = isc::config::createAnswer(0, "Configuration committed.");
answer = isc::config::createAnswer(0, "Configuration successful.");
return (answer);
}
......
......@@ -60,12 +60,8 @@ void configure(const std::string& file_name) {
// Read contents of the file and parse it as JSON
json = isc::data::Element::fromJSONFile(file_name, true);
if (!json) {
LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
.arg("Config file " + file_name + " missing or empty.");
isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
+ file_name);
isc_throw(isc::BadValue, "no configuration found");
}
// Let's configure logging before applying the configuration,
......@@ -80,43 +76,38 @@ void configure(const std::string& file_name) {
dhcp6 = json->get("Dhcp6");
if (!dhcp6) {
LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
.arg("Config file " + file_name + " does not include 'Dhcp6' entry.");
isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
+ file_name);
isc_throw(isc::BadValue, "no mandatory 'Dhcp6' entry in"
" the configuration");
}
// Use parsed JSON structures to configure the server
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) {
LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL).arg(ex.what());
isc_throw(isc::BadValue, "Unable to process JSON configuration file:"
+ file_name);
}
// Now check is the returned result is successful (rcode=0) or not
// (see @ref isc::config::parseAnswer).
int rcode;
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) {
// 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.
} catch (const std::exception& ex) {
LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL)
.arg("Configuration failed: Undefined result of configureDhcp6Server"
"() function after attempting to read " + file_name);
return;
.arg(file_name).arg(ex.what());
isc_throw(isc::BadValue, "configuration error using file '"
<< 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.
......
......@@ -736,8 +736,8 @@ Element::fromJSONFile(const std::string& file_name,
if (!infile.is_open())
{
const char* error = strerror(errno);
isc_throw(InvalidOperation, "Failed to read file '" << file_name
<< "', error:" << error);
isc_throw(InvalidOperation, "failed to read file '" << file_name
<< "': " << error);
}
return (fromJSON(infile, file_name, preproc));
......
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