From: Razvan Becheriu Date: Wed, 19 Feb 2025 18:01:03 +0000 (+0200) Subject: [#3754] backport #3594 to 2.6.2 X-Git-Tag: Kea-2.6.2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f20444f9f130ccb7ac7662d68b4ba53f1095178;p=thirdparty%2Fkea.git [#3754] backport #3594 to 2.6.2 --- diff --git a/doc/sphinx/arm/logging.rst b/doc/sphinx/arm/logging.rst index 4add84f989..2e91edf49c 100644 --- a/doc/sphinx/arm/logging.rst +++ b/doc/sphinx/arm/logging.rst @@ -628,12 +628,15 @@ where log messages are sent and are explained in detail below. The alias ``output-options`` was added in Kea 2.5.1, to be used interchangeably with the previous ``output_options`` configuration key. This was done to keep all configuration keys consistent, i.e. - using a hyphen (`-`) instead of an underscore (`_`) in the key name. Currently, - both configuration keys are considered correct and mean the same to Kea parsers. + using a hyphen (`-`) instead of an underscore (`_`) in the key name. As of Kea 2.5.2, ``output-options`` becomes the default configuration key and ``output_options`` can be used as an alias. + As of Kea 2.6.2, ``output_options`` configuration key has been deprecated and + will be removed in future versions. Please consider updating your + configuration by switching to using ``output-options`` instead. + The ``output`` (string) Option ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/lib/process/log_parser.cc b/src/lib/process/log_parser.cc index 8db8355c72..c0cc19683d 100644 --- a/src/lib/process/log_parser.cc +++ b/src/lib/process/log_parser.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -88,9 +89,9 @@ void LogConfigParser::parseConfigEntry(isc::data::ConstElementPtr entry) { isc_throw(BadValue, ""); } } catch (...) { - isc_throw(BadValue, "Unsupported debuglevel value '" - << debuglevel_ptr->stringValue() - << "', expected 0-99 (" + isc_throw(BadValue, "Unsupported debuglevel value " + << debuglevel_ptr->intValue() + << ", expected 0-99 (" << debuglevel_ptr->getPosition() << ")"); } } @@ -104,6 +105,19 @@ void LogConfigParser::parseConfigEntry(isc::data::ConstElementPtr entry) { } isc::data::ConstElementPtr output_options = entry->get("output-options"); + isc::data::ConstElementPtr deprecated_output_options = entry->get("output_options"); + + if (output_options && deprecated_output_options) { + isc_throw(BadValue, "Only one of 'output-options' and 'output_options' may be specified."); + } + + if (deprecated_output_options) { + LOG_WARN(dctl_logger, DCTL_DEPRECATED_OUTPUT_OPTIONS); + output_options = deprecated_output_options; + ElementPtr mutable_element = boost::const_pointer_cast(entry); + mutable_element->remove("output_options"); + mutable_element->set("output-options", output_options); + } if (output_options) { parseOutputOptions(info.destinations_, output_options); diff --git a/src/lib/process/process_messages.cc b/src/lib/process/process_messages.cc index bd19813f1c..f6e3e9aa4f 100644 --- a/src/lib/process/process_messages.cc +++ b/src/lib/process/process_messages.cc @@ -22,6 +22,7 @@ extern const isc::log::MessageID DCTL_CONFIG_START = "DCTL_CONFIG_START"; extern const isc::log::MessageID DCTL_CONFIG_STUB = "DCTL_CONFIG_STUB"; extern const isc::log::MessageID DCTL_CONFIG_UPDATE = "DCTL_CONFIG_UPDATE"; extern const isc::log::MessageID DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED = "DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED"; +extern const isc::log::MessageID DCTL_DEPRECATED_OUTPUT_OPTIONS = "DCTL_DEPRECATED_OUTPUT_OPTIONS"; extern const isc::log::MessageID DCTL_DEVELOPMENT_VERSION = "DCTL_DEVELOPMENT_VERSION"; extern const isc::log::MessageID DCTL_INIT_PROCESS = "DCTL_INIT_PROCESS"; extern const isc::log::MessageID DCTL_INIT_PROCESS_FAIL = "DCTL_INIT_PROCESS_FAIL"; @@ -60,6 +61,7 @@ const char* values[] = { "DCTL_CONFIG_STUB", "%1 configuration stub handler called", "DCTL_CONFIG_UPDATE", "%1 updated configuration received: %2", "DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED", "Failed to connect to database: %1 with error: %2", + "DCTL_DEPRECATED_OUTPUT_OPTIONS", "The output_options parameter is deprecated. Use output-options parameter instead.", "DCTL_DEVELOPMENT_VERSION", "This software is a development branch of Kea. It is not recommended for production use.", "DCTL_INIT_PROCESS", "%1 initializing the application", "DCTL_INIT_PROCESS_FAIL", "%1 application initialization failed: %2", diff --git a/src/lib/process/process_messages.h b/src/lib/process/process_messages.h index 8811e5172b..72fa1a148c 100644 --- a/src/lib/process/process_messages.h +++ b/src/lib/process/process_messages.h @@ -23,6 +23,7 @@ extern const isc::log::MessageID DCTL_CONFIG_START; extern const isc::log::MessageID DCTL_CONFIG_STUB; extern const isc::log::MessageID DCTL_CONFIG_UPDATE; extern const isc::log::MessageID DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED; +extern const isc::log::MessageID DCTL_DEPRECATED_OUTPUT_OPTIONS; extern const isc::log::MessageID DCTL_DEVELOPMENT_VERSION; extern const isc::log::MessageID DCTL_INIT_PROCESS; extern const isc::log::MessageID DCTL_INIT_PROCESS_FAIL; diff --git a/src/lib/process/process_messages.mes b/src/lib/process/process_messages.mes index d0eb11e6d5..aa20591cee 100644 --- a/src/lib/process/process_messages.mes +++ b/src/lib/process/process_messages.mes @@ -81,6 +81,10 @@ the configuration database. The operation started a retry to connect procedure. The database access string with password redacted is logged, along with the error and details for the reconnect procedure. +% DCTL_DEPRECATED_OUTPUT_OPTIONS The output_options parameter is deprecated. Use output-options parameter instead. +This warning message is displayed when deprecated output_options is used instead +of output-options. + % DCTL_DEVELOPMENT_VERSION This software is a development branch of Kea. It is not recommended for production use. This warning message is displayed when the version is a development (vs stable) one: the second number of the version is odd. diff --git a/src/lib/process/tests/log_parser_unittests.cc b/src/lib/process/tests/log_parser_unittests.cc index 43c30541d7..448c471551 100644 --- a/src/lib/process/tests/log_parser_unittests.cc +++ b/src/lib/process/tests/log_parser_unittests.cc @@ -132,6 +132,99 @@ TEST_F(LoggingTest, parsingConsoleOutput) { EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_); } +// This test checks that deprecated parameter output_options is accepted. +TEST_F(LoggingTest, parsingDeprecatedOutputOptions) { + + const char* config_txt = + "{ \"loggers\": [" + " {" + " \"name\": \"kea\"," + " \"output_options\": [" + " {" + " \"output\": \"stdout\"," + " \"flush\": true" + " }" + " ]," + " \"debuglevel\": 99," + " \"severity\": \"DEBUG\"" + " }" + "]}"; + + ConfigPtr storage(new ConfigBase()); + + LogConfigParser parser(storage); + + // We need to parse properly formed JSON and then extract + // "loggers" element from it. For some reason fromJSON is + // throwing at opening square bracket + ConstElementPtr config = Element::fromJSON(config_txt); + config = config->get("loggers"); + + ASSERT_EQ(1, config->size()); + ASSERT_TRUE(config->get(0)->get("output_options")); + ASSERT_FALSE(config->get(0)->get("output-options")); + + EXPECT_NO_THROW(parser.parseConfiguration(config)); + + ASSERT_EQ(1, storage->getLoggingInfo().size()); + + EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_); + EXPECT_EQ(99, storage->getLoggingInfo()[0].debuglevel_); + EXPECT_EQ(isc::log::DEBUG, storage->getLoggingInfo()[0].severity_); + + ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size()); + EXPECT_EQ("stdout" , storage->getLoggingInfo()[0].destinations_[0].output_); + EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_); + + ASSERT_TRUE(config->get(0)->get("output-options")); + ASSERT_FALSE(config->get(0)->get("output_options")); +} + +// This test checks that specifying both output-options and deprecated parameter +// output_options is not accepted. +TEST_F(LoggingTest, parsingErrorOutputOptions) { + + const char* config_txt = + "{ \"loggers\": [" + " {" + " \"name\": \"kea\"," + " \"output_options\": [" + " {" + " \"output\": \"stdout\"," + " \"flush\": true" + " }" + " ]," + " \"output-options\": [" + " {" + " \"output\": \"stdout\"," + " \"flush\": true" + " }" + " ]," + " \"debuglevel\": 99," + " \"severity\": \"DEBUG\"" + " }" + "]}"; + + ConfigPtr storage(new ConfigBase()); + + LogConfigParser parser(storage); + + // We need to parse properly formed JSON and then extract + // "loggers" element from it. For some reason fromJSON is + // throwing at opening square bracket + ConstElementPtr config = Element::fromJSON(config_txt); + config = config->get("loggers"); + + ASSERT_EQ(1, config->size()); + ASSERT_TRUE(config->get(0)->get("output_options")); + ASSERT_TRUE(config->get(0)->get("output-options")); + + ASSERT_THROW_MSG(parser.parseConfiguration(config), BadValue, "Only one of " + "'output-options' and 'output_options' may be specified."); + + ASSERT_EQ(0, storage->getLoggingInfo().size()); +} + // Check that LogConfigParser can parse configuration that // lacks a severity entry. TEST_F(LoggingTest, parsingNoSeverity) {