]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#32,!23] Added storage of ConfigControlInfo to process:ConfigBase
authorThomas Markwalder <tmark@isc.org>
Fri, 28 Sep 2018 18:06:04 +0000 (14:06 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 5 Oct 2018 13:05:44 +0000 (09:05 -0400)
    ConfigBase now houses ConfigControlInfo
    Relocated ConfigControl from libconfig to libprocess

14 files changed:
src/lib/config/Makefile.am
src/lib/config/tests/Makefile.am
src/lib/database/dbaccess_parser.h
src/lib/process/Makefile.am
src/lib/process/config_base.cc
src/lib/process/config_base.h
src/lib/process/config_ctl_info.cc [moved from src/lib/config/config_ctl_info.cc with 85% similarity]
src/lib/process/config_ctl_info.h [moved from src/lib/config/config_ctl_info.h with 90% similarity]
src/lib/process/config_ctl_parser.cc [moved from src/lib/config/config_ctl_parser.cc with 91% similarity]
src/lib/process/config_ctl_parser.h [moved from src/lib/config/config_ctl_parser.h with 80% similarity]
src/lib/process/tests/Makefile.am
src/lib/process/tests/config_base_unittests.cc [new file with mode: 0644]
src/lib/process/tests/config_ctl_info_unittests.cc [moved from src/lib/config/tests/config_ctl_info_unittests.cc with 86% similarity]
src/lib/process/tests/config_ctl_parser_unittests.cc [moved from src/lib/config/tests/config_ctl_parser_unittests.cc with 97% similarity]

index 62b613891d6db1e712284d64be28d14b4e0573f4..2199752b732d13a010577f9c388b6d7874dcaeaf 100644 (file)
@@ -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
index c98f7b6188f7f50d8d04cebe66b65fd1a6861e46..69e28545789d73f2e6a4a8af5a700695793eecc9 100644 (file)
@@ -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)
index c2be71ef9eb6f2f2aa8ed45da10359a3c9b04540..e1ca821e0f978cf7ffa8f30162a155b07da4fbca 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <cc/data.h>
 #include <cc/simple_parser.h>
+#include <database/database_connection.h>
 #include <exceptions/exceptions.h>
 
 #include <string>
index 5f343eac0ac8b1d9ea1468bdb2373bfaa8af47bd..70129578ce23bca81157e67624d70956185fc05d 100644 (file)
@@ -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
index e032155a2bf2c504d6dd963e520b5706a93b838c..74b4ca788f7090a8ae5e610da95d318023f972ae 100644 (file)
@@ -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 <process/config_base.h>
 #include <log/logger_manager.h>
 #include <log/logger_specification.h>
@@ -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);
 }
 
index c9e367138498f002cbaca520df1f1548519cb040..bdf8fbc8843631d4c0223fe44f25d2d0184bf0ca 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <cc/cfg_to_element.h>
 #include <cc/user_context.h>
+#include <process/config_ctl_info.h>
 #include <process/logging_info.h>
 
 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<ConfigBase> ConfigPtr;
 };
 };
 
-
 #endif /* CONFIG_BASE_H */
similarity index 85%
rename from src/lib/config/config_ctl_info.cc
rename to src/lib/process/config_ctl_info.cc
index 190773182ab57c99a4d089cf2433c2e2653ed6c3..8d9ab66978dfe1b0c0c1235077ccf3c0b4503819 100644 (file)
@@ -5,12 +5,12 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <config/config_ctl_info.h>
+#include <process/config_ctl_info.h>
 
 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
similarity index 90%
rename from src/lib/config/config_ctl_info.h
rename to src/lib/process/config_ctl_info.h
index b188e527fc6a3b9686b416117a21dc462d64af13..27ff7bb46ae5612142a12d78f7818e6bb1d1b8d3 100644 (file)
@@ -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 <cc/cfg_to_element.h>
 #include <database/database_connection.h>
@@ -15,7 +15,7 @@
 #include <vector>
 
 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<ConfigControlInfo> ConfigControlInfoPtr;
+/// @brief Defines a pointer to a const ConfigControlInfo
+typedef boost::shared_ptr<const ConfigControlInfo> ConstConfigControlInfoPtr;
 
-} // namespace config
+} // namespace process
 } // end namespace isc
 
-#endif // CONFIG_CONFIG_CTL_H
+#endif // PROCESS_CONFIG_CTL_INFO_H
similarity index 91%
rename from src/lib/config/config_ctl_parser.cc
rename to src/lib/process/config_ctl_parser.cc
index aba1c591094d6e0b3ca6d721debdc3d201c9121f..fe017a81e745ad366b8ba2a65a100d4468f733d4 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 
 #include <cc/dhcp_config_error.h>
-#include <config/config_ctl_parser.h>
+#include <process/config_ctl_parser.h>
 #include <database/dbaccess_parser.h>
 #include <string>
 
@@ -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
 
similarity index 80%
rename from src/lib/config/config_ctl_parser.h
rename to src/lib/process/config_ctl_parser.h
index 5e254bf0752096d0e32d2a5f78e0ae815142e6c0..e898456a76e447a1e6ef285d2325d2569ba21584 100644 (file)
@@ -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 <cc/data.h>
 #include <cc/simple_parser.h>
-#include <config/config_ctl_info.h>
+#include <process/config_ctl_info.h>
 
 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
index f6c11b0468c54cd690a7c6650e5cdf25106b55cd..ccdcf87ffdea5eaf6703ab714d96db51f58ba3f5 100644 (file)
@@ -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 (file)
index 0000000..a749c98
--- /dev/null
@@ -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 <config.h>
+
+#include <exceptions/exceptions.h>
+#include <process/config_base.h>
+
+#include <gtest/gtest.h>
+
+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));
+}
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 f2726f6b3f4774150cefc4d0908e1b6d825a96c2..40b49b6e9e014cbd89834331a301ccfca1585e9b 100644 (file)
@@ -5,7 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
-#include <config/config_ctl_info.h>
+#include <process/config_ctl_info.h>
 #include <exceptions/exceptions.h>
 
 #include <gtest/gtest.h>
@@ -13,7 +13,7 @@
 #include <sstream>
 #include <iostream>
 
-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));
+}
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 845acd1d1afbc8f3d1a23e216b81074ef9648c81..9a1f13643143825c9045752e52bf07079369aef4 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 #include <cc/dhcp_config_error.h>
-#include <config/config_ctl_parser.h>
+#include <process/config_ctl_parser.h>
 #include <exceptions/exceptions.h>
 
 #include <gtest/gtest.h>
@@ -14,7 +14,7 @@
 #include <sstream>
 #include <iostream>
 
-using namespace isc::config;
+using namespace isc::process;
 using namespace isc::data;
 
 // Verifies valid configurations are parsed correctly.  The test