From: Thomas Markwalder Date: Fri, 28 Sep 2018 18:06:04 +0000 (-0400) Subject: [#32,!23] Added storage of ConfigControlInfo to process:ConfigBase X-Git-Tag: 153-netconf-control-socket_base~4^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92a3a920fecfe59b152b1366418fdcb57e904d38;p=thirdparty%2Fkea.git [#32,!23] Added storage of ConfigControlInfo to process:ConfigBase ConfigBase now houses ConfigControlInfo Relocated ConfigControl from libconfig to libprocess --- diff --git a/src/lib/config/Makefile.am b/src/lib/config/Makefile.am index 62b613891d..2199752b73 100644 --- a/src/lib/config/Makefile.am +++ b/src/lib/config/Makefile.am @@ -19,8 +19,6 @@ libkea_cfgclient_la_SOURCES = cmds_impl.h libkea_cfgclient_la_SOURCES += base_command_mgr.cc base_command_mgr.h libkea_cfgclient_la_SOURCES += client_connection.cc client_connection.h libkea_cfgclient_la_SOURCES += command_mgr.cc command_mgr.h -libkea_cfgclient_la_SOURCES += config_ctl_info.h config_ctl_info.cc -libkea_cfgclient_la_SOURCES += config_ctl_parser.h config_ctl_parser.cc libkea_cfgclient_la_SOURCES += config_log.h config_log.cc libkea_cfgclient_la_SOURCES += hooked_command_mgr.cc hooked_command_mgr.h libkea_cfgclient_la_SOURCES += timeouts.h diff --git a/src/lib/config/tests/Makefile.am b/src/lib/config/tests/Makefile.am index c98f7b6188..69e2854578 100644 --- a/src/lib/config/tests/Makefile.am +++ b/src/lib/config/tests/Makefile.am @@ -22,8 +22,6 @@ TESTS += run_unittests run_unittests_SOURCES = client_connection_unittests.cc run_unittests_SOURCES += run_unittests.cc run_unittests_SOURCES += command_mgr_unittests.cc -run_unittests_SOURCES += config_ctl_info_unittests.cc -run_unittests_SOURCES += config_ctl_parser_unittests.cc run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) run_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS) diff --git a/src/lib/database/dbaccess_parser.h b/src/lib/database/dbaccess_parser.h index c2be71ef9e..e1ca821e0f 100644 --- a/src/lib/database/dbaccess_parser.h +++ b/src/lib/database/dbaccess_parser.h @@ -9,6 +9,7 @@ #include #include +#include #include #include diff --git a/src/lib/process/Makefile.am b/src/lib/process/Makefile.am index 5f343eac0a..70129578ce 100644 --- a/src/lib/process/Makefile.am +++ b/src/lib/process/Makefile.am @@ -39,6 +39,8 @@ DISTCLEANFILES = spec_config.h.pre lib_LTLIBRARIES = libkea-process.la libkea_process_la_SOURCES = config_base.cc config_base.h +libkea_process_la_SOURCES += config_ctl_info.cc config_control_info.h +libkea_process_la_SOURCES += config_ctl_parser.cc config_control_parser.h libkea_process_la_SOURCES += d_cfg_mgr.cc d_cfg_mgr.h libkea_process_la_SOURCES += d_controller.cc d_controller.h libkea_process_la_SOURCES += d_log.cc d_log.h diff --git a/src/lib/process/config_base.cc b/src/lib/process/config_base.cc index e032155a2b..74b4ca788f 100644 --- a/src/lib/process/config_base.cc +++ b/src/lib/process/config_base.cc @@ -1,3 +1,9 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + #include #include #include @@ -48,6 +54,14 @@ ConfigBase::equals(const ConfigBase& other) const { } } + // Check config control info for equality. + if ((config_ctl_info_ && !other.config_ctl_info_) || + (!config_ctl_info_ && other.config_ctl_info_) || + ((config_ctl_info_ && other.config_ctl_info_) && + (!config_ctl_info_->equals(*(other.config_ctl_info_))))) { + return (false); + } + return (true); } @@ -59,6 +73,13 @@ ConfigBase::copy(ConfigBase& other) const { it != logging_info_.end(); ++it) { other.addLoggingInfo(*it); } + + // Clone the config control info + if (config_ctl_info_) { + other.config_ctl_info_.reset(new ConfigControlInfo(*config_ctl_info_)); + } else { + other.config_ctl_info_.reset(); + } } ElementPtr @@ -79,6 +100,10 @@ ConfigBase::toElement() const { result->set("Logging", logging); } + // We do NOT output ConfigControlInfo here, as it is not a + // top level element, but rather belongs within the process + // element. + return (result); } diff --git a/src/lib/process/config_base.h b/src/lib/process/config_base.h index c9e3671384..bdf8fbc884 100644 --- a/src/lib/process/config_base.h +++ b/src/lib/process/config_base.h @@ -9,6 +9,7 @@ #include #include +#include #include namespace isc { @@ -26,7 +27,7 @@ namespace process { /// DDNS update daemon, Control Agent, Netconf daemon, DHCP relay, /// DHCP client. /// -/// This class currently holds information about logging configuration. +/// This class currently holds information about common server configuration. class ConfigBase : public isc::data::UserContext, public isc::data::CfgToElement { public: /// @name Modifiers and accesors for the configuration objects. @@ -58,9 +59,43 @@ public: /// @brief Converts to Element representation /// + /// This creates a Map element with the following content (expressed + /// as JSON): + /// {{{ + /// { + /// "Logging": { + /// : + /// } + /// } + /// }}} + /// + /// Note that it will not contain the configuration control information + /// (i.e. "config-control"), as this is not a top-level element, rather + /// it belongs within the configured process element. + /// /// @return Element representation. virtual isc::data::ElementPtr toElement() const; + /// @brief Fetches a read-only copy of the configuration control + /// information + /// @return pointer to the const ConfigControlInfo + process::ConstConfigControlInfoPtr getConfigControlInfo() const { + return (config_ctl_info_); + } + + /// @brief Set the configuration control information + /// + /// Updates the internal pointer to the configuration control + /// information with the given pointer value. If the given pointer + /// is empty, the internal pointer will be reset. + /// + /// @param config_ctl_info pointer to the configuration value + /// to store. + void setConfigControlInfo(const process::ConfigControlInfoPtr& + config_ctl_info) { + config_ctl_info_ = config_ctl_info; + } + protected: /// @brief Copies the current configuration to a new configuration. /// @@ -76,6 +111,8 @@ private: /// @brief Logging specific information. process::LoggingInfoStorage logging_info_; + /// @brief Configuration control information. + process::ConfigControlInfoPtr config_ctl_info_; }; /// @brief Non-const pointer to the @c SrvConfig. @@ -84,5 +121,4 @@ typedef boost::shared_ptr ConfigPtr; }; }; - #endif /* CONFIG_BASE_H */ diff --git a/src/lib/config/config_ctl_info.cc b/src/lib/process/config_ctl_info.cc similarity index 85% rename from src/lib/config/config_ctl_info.cc rename to src/lib/process/config_ctl_info.cc index 190773182a..8d9ab66978 100644 --- a/src/lib/config/config_ctl_info.cc +++ b/src/lib/process/config_ctl_info.cc @@ -5,12 +5,12 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include -#include +#include using namespace isc::data; namespace isc { -namespace config { +namespace process { void ConfigDbInfo::setAccessString(const std::string access_str) { @@ -40,6 +40,14 @@ ConfigDbInfo::getParameterValue(const std::string& name, std::string& value) con return(true); } +//********* ConfiControlInfo ************// + +ConfigControlInfo::ConfigControlInfo(const ConfigControlInfo& other) { + for (auto db : other.db_infos_) { + addConfigDatabase(db.getAccessString()); + } +} + void ConfigControlInfo::addConfigDatabase(const std::string& access_str) { ConfigDbInfo new_db; @@ -94,5 +102,10 @@ ConfigControlInfo::toElement() const { return(result); } -} // end of namespace isc::config +bool +ConfigControlInfo::equals(const ConfigControlInfo& other) const { + return (db_infos_ == other.db_infos_); +} + +} // end of namespace isc::process } // end of namespace isc diff --git a/src/lib/config/config_ctl_info.h b/src/lib/process/config_ctl_info.h similarity index 90% rename from src/lib/config/config_ctl_info.h rename to src/lib/process/config_ctl_info.h index b188e527fc..27ff7bb46a 100644 --- a/src/lib/config/config_ctl_info.h +++ b/src/lib/process/config_ctl_info.h @@ -4,8 +4,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef CONFIG_CONFIG_CTL_H -#define CONFIG_CONFIG_CTL_H +#ifndef PROCESS_CONFIG_CTL_INFO_H +#define PROCESS_CONFIG_CTL_INFO_H #include #include @@ -15,7 +15,7 @@ #include namespace isc { -namespace config { +namespace process { /// @brief Provides configuration information used during a server's /// configuration process @@ -131,6 +131,9 @@ public: /// @brief Constructor. ConfigControlInfo() {}; + /// @brief Copy Constructor. + ConfigControlInfo(const ConfigControlInfo& other); + /// @brief Sets host database access string. /// /// @param host_db_access New host database access string. @@ -166,6 +169,13 @@ public: /// @return a reference to the empty ConfigDBInfo static const ConfigDbInfo& EMPTY_DB(); + /// @brief Compares two objects for equality. + /// + /// @param other An object to be compared with this object. + /// + /// @return true if objects are equal, false otherwise. + bool equals(const ConfigControlInfo& other) const; + private: /// @brief List of configuration databases @@ -174,8 +184,10 @@ private: /// @brief Defines a pointer to a ConfigControlInfo typedef boost::shared_ptr ConfigControlInfoPtr; +/// @brief Defines a pointer to a const ConfigControlInfo +typedef boost::shared_ptr ConstConfigControlInfoPtr; -} // namespace config +} // namespace process } // end namespace isc -#endif // CONFIG_CONFIG_CTL_H +#endif // PROCESS_CONFIG_CTL_INFO_H diff --git a/src/lib/config/config_ctl_parser.cc b/src/lib/process/config_ctl_parser.cc similarity index 91% rename from src/lib/config/config_ctl_parser.cc rename to src/lib/process/config_ctl_parser.cc index aba1c59109..fe017a81e7 100644 --- a/src/lib/config/config_ctl_parser.cc +++ b/src/lib/process/config_ctl_parser.cc @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ using namespace isc; using namespace isc::data; namespace isc { -namespace config { +namespace process { ConfigControlInfoPtr ConfigControlParser::parse(const data::ConstElementPtr& config_control) { @@ -38,7 +38,7 @@ ConfigControlParser::parse(const data::ConstElementPtr& config_control) { } #if 0 - // @todo, should it have user_context and what about comment? + // @todo Should it have user_context and what about comment? ConstElementPtr user_context = shared_network_data->get("user-context"); if (user_context) { shared_network->setContext(user_context); @@ -56,6 +56,6 @@ ConfigControlParser::parse(const data::ConstElementPtr& config_control) { return (ctl_info); } -} // end of namespace isc::config +} // end of namespace isc::process } // end of namespace isc diff --git a/src/lib/config/config_ctl_parser.h b/src/lib/process/config_ctl_parser.h similarity index 80% rename from src/lib/config/config_ctl_parser.h rename to src/lib/process/config_ctl_parser.h index 5e254bf075..e898456a76 100644 --- a/src/lib/config/config_ctl_parser.h +++ b/src/lib/process/config_ctl_parser.h @@ -4,15 +4,15 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef CONFIG_CONTROL_PARSER_H -#define CONFIG_CONTROL_PARSER_H +#ifndef PROCESS_CONFIG_CONTROL_PARSER_H +#define PROCESS_CONFIG_CONTROL_PARSER_H #include #include -#include +#include namespace isc { -namespace config { +namespace process { /// @brief Implements parser for config control information, "config-control" class ConfigControlParser : isc::data::SimpleParser { @@ -29,7 +29,7 @@ public: parse(const data::ConstElementPtr& config_control); }; -} // enf of namespace isc::config +} // enf of namespace isc::process } // end of namespace isc -#endif // CONFIG_CONTROL_PARSER_H +#endif // PROCESS_CONFIG_CONTROL_PARSER_H diff --git a/src/lib/process/tests/Makefile.am b/src/lib/process/tests/Makefile.am index f6c11b0468..ccdcf87ffd 100644 --- a/src/lib/process/tests/Makefile.am +++ b/src/lib/process/tests/Makefile.am @@ -22,6 +22,9 @@ if HAVE_GTEST TESTS += libprocess_unittests libprocess_unittests_SOURCES = d_cfg_mgr_unittests.cc +libprocess_unittests_SOURCES += config_base_unittests.cc +libprocess_unittests_SOURCES += config_ctl_info_unittests.cc +libprocess_unittests_SOURCES += config_ctl_parser_unittests.cc libprocess_unittests_SOURCES += d_controller_unittests.cc libprocess_unittests_SOURCES += daemon_unittest.cc libprocess_unittests_SOURCES += io_service_signal_unittests.cc diff --git a/src/lib/process/tests/config_base_unittests.cc b/src/lib/process/tests/config_base_unittests.cc new file mode 100644 index 0000000000..a749c98c69 --- /dev/null +++ b/src/lib/process/tests/config_base_unittests.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include +#include + +#include + +using namespace isc; +using namespace isc::process; + +/// @brief Derived ConfigBase class +/// We use this derivation to test the +/// copy and equality functions. +class ConfigBaseImpl : public ConfigBase { +public: + void + copy(ConfigBaseImpl& other) const { + ConfigBase::copy(other); + } +}; + +// Verifies construction, copy, and equality of +// ConfigBase with respect to ConfigControInfo. +TEST(ConfigBase, configControlInfoTests) { + + // Create a control info instance + ConfigControlInfoPtr ctl_info1(new ConfigControlInfo()); + ctl_info1->addConfigDatabase("type=mysql host=example.com"); + ctl_info1->addConfigDatabase("type=mysql host=example2.com"); + + // Create a ConfigBase + ConfigBaseImpl base1; + base1.setConfigControlInfo(ctl_info1); + + // Clone the ConfigBase + ConfigBaseImpl base2; + base1.copy(base2); + + // They should be equal. + EXPECT_TRUE(base1.equals(base2)); + + // Reset control info for one of them. + base1.setConfigControlInfo(ConfigControlInfoPtr()); + + // They should not be equal. + EXPECT_FALSE(base1.equals(base2)); + + // Reset control info for the other one. + base2.setConfigControlInfo(ConfigControlInfoPtr()); + + // They should be equal again. + EXPECT_TRUE(base1.equals(base2)); +} diff --git a/src/lib/config/tests/config_ctl_info_unittests.cc b/src/lib/process/tests/config_ctl_info_unittests.cc similarity index 86% rename from src/lib/config/tests/config_ctl_info_unittests.cc rename to src/lib/process/tests/config_ctl_info_unittests.cc index f2726f6b3f..40b49b6e9e 100644 --- a/src/lib/config/tests/config_ctl_info_unittests.cc +++ b/src/lib/process/tests/config_ctl_info_unittests.cc @@ -5,7 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include -#include +#include #include #include @@ -13,7 +13,7 @@ #include #include -using namespace isc::config; +using namespace isc::process; using namespace isc::data; // Verifies initializing via an access string and unparsing into elements @@ -141,3 +141,25 @@ TEST(ConfigControlInfo, basicOperation) { ctl.clear(); EXPECT_EQ(0, ctl.getConfigDatabases().size()); } + +// Verifies the copy ctor and equality functions ConfigControlInfo +TEST(ConfigControlInfo, copyAndEquality) { + + // Make an instance with two dbs. + ConfigControlInfo ctl1; + ASSERT_NO_THROW(ctl1.addConfigDatabase("type=mysql host=mach1.org")); + ASSERT_NO_THROW(ctl1.addConfigDatabase("type=postgresql host=mach2.org")); + + // Clone that instance. + ConfigControlInfo ctl2(ctl1); + + // They should be equal. + EXPECT_TRUE(ctl1.equals(ctl2)); + + // Make a third instance with a different db. + ConfigControlInfo ctl3; + ASSERT_NO_THROW(ctl1.addConfigDatabase("type=cql host=other.org")); + + // They should not equal. + EXPECT_FALSE(ctl3.equals(ctl1)); +} diff --git a/src/lib/config/tests/config_ctl_parser_unittests.cc b/src/lib/process/tests/config_ctl_parser_unittests.cc similarity index 97% rename from src/lib/config/tests/config_ctl_parser_unittests.cc rename to src/lib/process/tests/config_ctl_parser_unittests.cc index 845acd1d1a..9a1f136431 100644 --- a/src/lib/config/tests/config_ctl_parser_unittests.cc +++ b/src/lib/process/tests/config_ctl_parser_unittests.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -14,7 +14,7 @@ #include #include -using namespace isc::config; +using namespace isc::process; using namespace isc::data; // Verifies valid configurations are parsed correctly. The test