]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#101, !73] Addresses review comments
authorThomas Markwalder <tmark@isc.org>
Wed, 17 Oct 2018 19:05:27 +0000 (15:05 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 17 Oct 2018 19:05:27 +0000 (15:05 -0400)
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.h
src/bin/dhcp4/tests/config_parser_unittest.cc
src/lib/dhcpsrv/testutils/Makefile.am
src/lib/dhcpsrv/testutils/test_config_backend.h [new file with mode: 0644]
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
src/lib/process/config_ctl_info.h
src/lib/process/tests/config_ctl_info_unittests.cc

index d399520b3575f77498462103da5b9a4bbf358251..d41ee87bc948db21755549d1a5fd5f4e07250525 100644 (file)
@@ -11,6 +11,11 @@ This message is printed when DHCPv4 server enabled an interface to be used
 to receive DHCPv4 traffic. IPv4 socket on this interface will be opened once
 Interface Manager starts up procedure of opening sockets.
 
+% DHCP4_ADDING_CONFIG_DB Opening configuration database: %1
+This message is printed when the DHCPv4 server is attempting to open a
+configuration database.  The database access string with password redacted
+is logged.
+
 % DHCP4_ALREADY_RUNNING %1 already running? %2
 This is an error message that occurs when the DHCPv4 server encounters
 a pre-existing PID file which contains the PID of a running process.
index e44e8599580c66c1c2b2d3fb9e0b5089b3d862f9..910810db103dbdb6ee72e4f2dfbdf06389ddfbb4 100644 (file)
@@ -52,6 +52,7 @@ using namespace isc::data;
 using namespace isc::asiolink;
 using namespace isc::hooks;
 using namespace isc::process;
+using namespace isc::config;
 
 namespace {
 
@@ -284,7 +285,7 @@ isc::data::ConstElementPtr
 configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
                      bool check_only) {
     if (!config_set) {
-        ConstElementPtr answer = isc::config::createAnswer(1,
+        ConstElementPtr answer = isc::config::createAnswer(CONTROL_RESULT_ERROR,
                                  string("Can't parse NULL config"));
         return (answer);
     }
@@ -547,7 +548,7 @@ configureDhcp4Server(Dhcpv4Srv& server, 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, ex.what());
+        answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
 
         // An error occurred, so make sure that we restore original data.
         rollback = true;
@@ -555,7 +556,7 @@ configureDhcp4Server(Dhcpv4Srv& server, 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, "undefined configuration"
+        answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
                                            " processing error");
 
         // An error occurred, so make sure that we restore original data.
@@ -565,7 +566,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
     if (check_only) {
         rollback = true;
         if (!answer) {
-            answer = isc::config::createAnswer(0,
+            answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS,
             "Configuration seems sane. Control-socket, hook-libraries, and D2 "
             "configuration were sanity checked, but not applied.");
         }
@@ -600,12 +601,12 @@ configureDhcp4Server(Dhcpv4Srv& server, 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, ex.what());
+            answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, 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, "undefined configuration"
+            answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
                                                " parsing error");
             rollback = true;
         }
@@ -625,7 +626,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
              getConfigSummary(SrvConfig::CFGSEL_ALL4));
 
     // Everything was fine. Configuration is successful.
-    answer = isc::config::createAnswer(0, "Configuration successful.");
+    answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration successful.");
     return (answer);
 }
 
@@ -635,23 +636,25 @@ bool databaseConfigConnect(const SrvConfigPtr& srv_cfg) {
     ConfigBackendDHCPv4Mgr& mgr = ConfigBackendDHCPv4Mgr::instance();
     mgr.delAllBackends();
 
-    // SrvConfigPtr staging_cfg = CfgMgr::instance().getStagingCfg();
+    // Fetch the config-control info.
     ConstConfigControlInfoPtr config_ctl = srv_cfg->getConfigControlInfo();
     if (!config_ctl || config_ctl->getConfigDatabases().empty()) {
         // No config dbs, nothing to do.
         return (false);
     }
 
-    // First step is to create all of the backends.
+    // Iterate over the configured DBs and instantiate them.
     for (auto db : config_ctl->getConfigDatabases()) {
-            // Good place for a log message?
-            mgr.addBackend(db.getAccessString());
+        LOG_INFO(dhcp4_logger, DHCP4_ADDING_CONFIG_DB)
+                 .arg(db.redactedAccessString());
+        mgr.addBackend(db.getAccessString());
     }
 
+    // Let the caller know we have opened DBs.
     return (true);
 }
 
-void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /*global_scope*/) {
+void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /* mutable_cfg */) {
 
     // Close any existing CB databasess, then open all in srv_cfg (if any)
     if (!databaseConfigConnect(srv_cfg)) {
@@ -664,10 +667,10 @@ void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /*global_scope*
     // Next we have to fetch the pieces we care about it and merge them
     // probably in this order?
     // globals
-    // shared networks
-    // subnets
     // option defs
     // options
+    // shared networks
+    // subnets
 }
 
 
index 0c4cae769420caed2014d3c4f44014963a9e1acb..b03cd2d1636f57fab1dd54f4201c4148862e7e89 100644 (file)
@@ -59,33 +59,34 @@ configureDhcp4Server(Dhcpv4Srv&,
                      isc::data::ConstElementPtr config_set,
                      bool check_only = false);
 
-/// @brief Attempts to the configured CB databases  (if any)
+/// @brief Attempts to connect to configured CB databases
 ///
-/// This function will close all the existing CB backends. It
-/// then attempt to connect to all of the CB databases in the
-/// given SrvConfig (if any).
+/// First, this function will close all existing CB backends. It
+/// will then attempt to connect to all of the CB backends defined
+/// in the given SrvConfig (if any).
 ///
-/// It will return true if there are configured CB databases
-/// false, otherwise.  Any errors encountered along the way
+/// It will return true if there are configured CB databases,
+/// and false otherwise.  Any errors encountered along the way
 /// should generate throws.
 ///
 /// @param srv_cfg Server configuration from which to get
 /// the config-control information to use.
 ///
-/// @return True if are configured CB databases, false if not.
+/// @return True if there are configured CB databases, false if not.
 bool
 databaseConfigConnect(const SrvConfigPtr& srv_cfg);
 
 /// @brief Fetch configuration from CB databases and merge it into the given configuration
 ///
-/// It will call @c databaseConfigConnect passing in the given server configuration. If
-/// results in open CB databases it will proceed to fetch configuration components from
-/// those databases and merge them into the given server configuration.
+/// It will call @c databaseConfigConnect, passing in the given server configuration. If
+/// that call results in open CB databases, the function will then proceed to fetch
+/// configuration components from said databases and merge them into the given server
+/// configuration.
 ///
-/// @param srv_config Server configuration to merge into
-/// @param global_scope global configuration as elements
+/// @param srv_cfg Server configuration into which database configuration should be merged
+/// @param mutable_cfg parsed configuration from the configuration file plus default values
 void
-databaseConfigFetch(const SrvConfigPtr& srv_cfg, isc::data::ElementPtr /*global_scope*/);
+databaseConfigFetch(const SrvConfigPtr& srv_cfg, isc::data::ElementPtr /*mutable_scope*/);
 
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
index b1a4cc18f3201e832ec10c4afc38f6b512e8ef54..4168b309d4613ec74f016dcc598103c204fa168e 100644 (file)
@@ -6265,7 +6265,7 @@ TEST_F(Dhcp4ParserTest, configControlInfoNoFactory) {
     extractConfig(config);
 
     // Should fail because "type=mysql" has no factories.
-    configure(config, CONTROL_RESULT_COMMAND_UNSUPPORTED,
+    configure(config, CONTROL_RESULT_ERROR,
               "The type of the configuration backend: 'mysql' is not supported");
 }
 
@@ -6275,7 +6275,7 @@ TEST_F(Dhcp4ParserTest, configControlInfo) {
     extractConfig(config);
 
     // Should be able to register a backend factory for "mysql".
-    ASSERT_TRUE(TestConfigBackendDHCPv4Impl::
+    ASSERT_TRUE(TestConfigBackendDHCPv4::
                 registerBackendType(ConfigBackendDHCPv4Mgr::instance(),
                                     "mysql"));
 
index 829e65da180e8a63e714988ce3a0dfe716d7b460..5d339b9ae2d7feda95ecbf7941456264ea92f92e 100644 (file)
@@ -19,6 +19,7 @@ libdhcpsrvtest_la_SOURCES += memory_host_data_source.cc memory_host_data_source.
 libdhcpsrvtest_la_SOURCES += generic_backend_unittest.cc generic_backend_unittest.h
 libdhcpsrvtest_la_SOURCES += generic_host_data_source_unittest.cc generic_host_data_source_unittest.h
 libdhcpsrvtest_la_SOURCES += lease_file_io.cc lease_file_io.h
+libdhcpsrvtest_la_SOURCES += test_config_backend.h
 libdhcpsrvtest_la_SOURCES += test_config_backend_dhcp4.cc test_config_backend_dhcp4.h
 
 libdhcpsrvtest_la_CXXFLAGS = $(AM_CXXFLAGS)
diff --git a/src/lib/dhcpsrv/testutils/test_config_backend.h b/src/lib/dhcpsrv/testutils/test_config_backend.h
new file mode 100644 (file)
index 0000000..7c644eb
--- /dev/null
@@ -0,0 +1,89 @@
+// 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/.
+#ifndef TEST_CONFIG_BACKEND_H
+#define TEST_CONFIG_BACKEND_H
+
+#include <config.h>
+
+#include <database/database_connection.h>
+#include <dhcpsrv/config_backend_dhcp4_mgr.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+
+namespace isc {
+namespace dhcp {
+namespace test {
+
+/// @brief Base class for implementing fake backends
+template<typename ConfigBackendType>
+class TestConfigBackend : public ConfigBackendType {
+public:
+    /// @brief Constructor
+    ///
+    /// @param params database connection parameters
+    /// @throw BadValue if parameters do not include "type"
+    TestConfigBackend(const db::DatabaseConnection::ParameterMap& params)
+     : connection_(params) {
+        try {
+            db_type_ = connection_.getParameter("type");
+        } catch (...) {
+            isc_throw(BadValue, "Backend parameters must include \"type\"");
+        }
+
+        try {
+            db_type_ = connection_.getParameter("host");
+        } catch (...) {
+            host_ = "default_host";
+        }
+
+        try {
+            port_ = boost::lexical_cast<uint16_t>(connection_.getParameter("host"));
+        } catch (...) {
+            port_ = 0;
+        }
+    }
+
+    /// @brief virtual Destructor.
+    virtual ~TestConfigBackend(){};
+
+    /// @brief Returns backend type.
+    ///
+    /// @return string db_type name
+    virtual std::string getType() const { return (db_type_);
+    }
+
+    /// @brief Returns backend host.
+    ///
+    /// @return string host
+    virtual std::string getHost() const {
+        return (host_);
+    }
+
+    /// @brief Returns backend port.
+    ///
+    /// @return uint16_t port
+    virtual uint16_t getPort() const {
+        return (port_);
+    }
+
+    /// @brief Fake database connection
+    db::DatabaseConnection connection_;
+
+    /// @brief  Back end type
+    std::string db_type_;
+
+    /// @brief  Back end host
+    std::string host_;
+
+    /// @brief  Back end port
+    uint16_t port_;
+};
+
+} // namespace test
+} // namespace dhcp
+} // namespace isc
+
+#endif // TEST_CONFIG_BACKEND_H
index 00aff16c79c36751c0fade67da9b8a904b7cf47d..12c34e8ea2afe2df31d48a0316cc87de44987d99 100644 (file)
@@ -14,240 +14,240 @@ namespace dhcp {
 namespace test {
 
 bool
-TestConfigBackendDHCPv4Impl::registerBackendType(ConfigBackendDHCPv4Mgr& mgr,
-                                                 const std::string& db_type) {
+TestConfigBackendDHCPv4::registerBackendType(ConfigBackendDHCPv4Mgr& mgr,
+                                               const std::string& db_type) {
     return(mgr.registerBackendFactory(db_type,
                 [](const db::DatabaseConnection::ParameterMap& params)
                 -> dhcp::ConfigBackendDHCPv4Ptr {
-                return (TestConfigBackendDHCPv4ImplPtr(new TestConfigBackendDHCPv4Impl(params)));
+                return (TestConfigBackendDHCPv4Ptr(new TestConfigBackendDHCPv4(params)));
             })
     );
 }
 
 void
-TestConfigBackendDHCPv4Impl::unregisterBackendType(ConfigBackendDHCPv4Mgr& mgr,
-                                                   const std::string& db_type) {
+TestConfigBackendDHCPv4::unregisterBackendType(ConfigBackendDHCPv4Mgr& mgr,
+                                                 const std::string& db_type) {
     mgr.unregisterBackendFactory(db_type);
 }
 
 Subnet4Ptr
-TestConfigBackendDHCPv4Impl::getSubnet4(const db::ServerSelector& /* server_selector */,
-                                        const std::string& /* subnet_prefix */) const{
+TestConfigBackendDHCPv4::getSubnet4(const db::ServerSelector& /* server_selector */,
+                                      const std::string& /* subnet_prefix */) const{
     return (Subnet4Ptr());
 }
 
 Subnet4Ptr
-TestConfigBackendDHCPv4Impl::getSubnet4(const db::ServerSelector& /* server_selector */,
-                                        const SubnetID& /* subnet_id */) const {
+TestConfigBackendDHCPv4::getSubnet4(const db::ServerSelector& /* server_selector */,
+                                      const SubnetID& /* subnet_id */) const {
     return (Subnet4Ptr());
 }
 
 Subnet4Collection
-TestConfigBackendDHCPv4Impl::getAllSubnets4(const db::ServerSelector& /* server_selector */) const {
+TestConfigBackendDHCPv4::getAllSubnets4(const db::ServerSelector& /* server_selector */) const {
     return(subnets_);
 }
 
 Subnet4Collection
-TestConfigBackendDHCPv4Impl::getModifiedSubnets4(const db::ServerSelector& /* server_selector */,
-                                                 const boost::posix_time::ptime& /* modification_time */) const {
+TestConfigBackendDHCPv4::getModifiedSubnets4(const db::ServerSelector& /* server_selector */,
+                                               const boost::posix_time::ptime& /* modification_time */) const {
     return(subnets_);
 }
 
 SharedNetwork4Ptr
-TestConfigBackendDHCPv4Impl::getSharedNetwork4(const db::ServerSelector& /* server_selector */,
-                                               const std::string& /* name */) const {
+TestConfigBackendDHCPv4::getSharedNetwork4(const db::ServerSelector& /* server_selector */,
+                                             const std::string& /* name */) const {
     return(SharedNetwork4Ptr());
 }
 
 SharedNetwork4Collection
-TestConfigBackendDHCPv4Impl::getAllSharedNetworks4(const db::ServerSelector& /* server_selector */) const{
+TestConfigBackendDHCPv4::getAllSharedNetworks4(const db::ServerSelector& /* server_selector */) const{
     return(shared_networks_);
 }
 
 SharedNetwork4Collection
-TestConfigBackendDHCPv4Impl::getModifiedSharedNetworks4(const db::ServerSelector& /* server_selector */,
-                                                        const boost::posix_time::ptime& /* modification_time */) const {
+TestConfigBackendDHCPv4::getModifiedSharedNetworks4(const db::ServerSelector& /* server_selector */,
+                                                      const boost::posix_time::ptime& /* modification_time */) const {
     return(shared_networks_);
 }
 
 OptionDefinitionPtr
-TestConfigBackendDHCPv4Impl::getOptionDef4(const db::ServerSelector& /* server_selector */,
-                                           const uint16_t /* code */,
-                                           const std::string& /* space */) const {
+TestConfigBackendDHCPv4::getOptionDef4(const db::ServerSelector& /* server_selector */,
+                                         const uint16_t /* code */,
+                                         const std::string& /* space */) const {
     return (OptionDefinitionPtr());
 }
 
 OptionDefContainer
-TestConfigBackendDHCPv4Impl::getAllOptionDefs4(const db::ServerSelector& /* server_selector */) const {
+TestConfigBackendDHCPv4::getAllOptionDefs4(const db::ServerSelector& /* server_selector */) const {
     return (option_defs_);
 }
 
 OptionDefContainer
-TestConfigBackendDHCPv4Impl::getModifiedOptionDefs4(const db::ServerSelector& /* server_selector */,
-                                                    const boost::posix_time::ptime& /* modification_time */) const {
+TestConfigBackendDHCPv4::getModifiedOptionDefs4(const db::ServerSelector& /* server_selector */,
+                                                  const boost::posix_time::ptime& /* modification_time */) const {
     return (option_defs_);
 }
 
 OptionDescriptorPtr
-TestConfigBackendDHCPv4Impl::getOption4(const db::ServerSelector& /* server_selector */,
-                                        const uint16_t /* code */,
-                                        const std::string& /* space */) const {
+TestConfigBackendDHCPv4::getOption4(const db::ServerSelector& /* server_selector */,
+                                      const uint16_t /* code */,
+                                      const std::string& /* space */) const {
     return (OptionDescriptorPtr());
 }
 
 OptionContainer
-TestConfigBackendDHCPv4Impl::getAllOptions4(const db::ServerSelector& /* server_selector */) const {
+TestConfigBackendDHCPv4::getAllOptions4(const db::ServerSelector& /* server_selector */) const {
     return (options_);
 }
 
 OptionContainer
-TestConfigBackendDHCPv4Impl::getModifiedOptions4(const db::ServerSelector& /* selector */,
-                                                 const boost::posix_time::ptime& /* modification_time */) const {
+TestConfigBackendDHCPv4::getModifiedOptions4(const db::ServerSelector& /* server_selector */,
+                                               const boost::posix_time::ptime& /* modification_time */) const {
     return (options_);
 }
 
 data::StampedValuePtr
-TestConfigBackendDHCPv4Impl::getGlobalParameter4(const db::ServerSelector& /* selector */,
-                                                 const std::string& /* name */) const {
+TestConfigBackendDHCPv4::getGlobalParameter4(const db::ServerSelector& /* server_selector */,
+                                               const std::string& /* name */) const {
     return(data::StampedValuePtr());
 }
 
 
 data::StampedValueCollection
-TestConfigBackendDHCPv4Impl::getAllGlobalParameters4(const db::ServerSelector& /* selector */) const {
+TestConfigBackendDHCPv4::getAllGlobalParameters4(const db::ServerSelector& /* server_selector */) const {
     return (globals_);
 }
 
 data::StampedValueCollection
-TestConfigBackendDHCPv4Impl::getModifiedGlobalParameters4(const db::ServerSelector& /* selector */,
-                                                          const boost::posix_time::ptime& /* modification_time */) const {
+TestConfigBackendDHCPv4::getModifiedGlobalParameters4(const db::ServerSelector& /* server_selector */,
+                                                        const boost::posix_time::ptime& /* modification_time */) const {
     return (globals_);
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateSubnet4(const db::ServerSelector& /* server_selector */,
-                                                 const Subnet4Ptr& /* subnet */) {
+TestConfigBackendDHCPv4::createUpdateSubnet4(const db::ServerSelector& /* server_selector */,
+                                               const Subnet4Ptr& /* subnet */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateSharedNetwork4(const db::ServerSelector& /* server_selector */,
-                                                        const SharedNetwork4Ptr& /* shared_network */) {
+TestConfigBackendDHCPv4::createUpdateSharedNetwork4(const db::ServerSelector& /* server_selector */,
+                                                      const SharedNetwork4Ptr& /* shared_network */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateOptionDef4(const db::ServerSelector& /* server_selector */,
-                                                    const OptionDefinitionPtr& /* option_def */) {
+TestConfigBackendDHCPv4::createUpdateOptionDef4(const db::ServerSelector& /* server_selector */,
+                                                  const OptionDefinitionPtr& /* option_def */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
-                                                 const OptionDescriptorPtr& /* option */) {
+TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
+                                               const OptionDescriptorPtr& /* option */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* selector */,
-                                                 const std::string& /* shared_network_name */,
-                                                 const OptionDescriptorPtr& /* option */) {
+TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
+                                               const std::string& /* shared_network_name */,
+                                               const OptionDescriptorPtr& /* option */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
-                                                 const SubnetID& /* subnet_id */,
-                                                 const OptionDescriptorPtr& /* option */) {
+TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
+                                               const SubnetID& /* subnet_id */,
+                                               const OptionDescriptorPtr& /* option */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateOption4(const db::ServerSelector& /* server_selector */,
-                                                 const asiolink::IOAddress& /* pool_start_address */,
-                                                 const asiolink::IOAddress& /* pool_end_address */,
-                                                 const OptionDescriptorPtr& /* option */) {
+TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& /* server_selector */,
+                                               const asiolink::IOAddress& /* pool_start_address */,
+                                               const asiolink::IOAddress& /* pool_end_address */,
+                                               const OptionDescriptorPtr& /* option */) {
 }
 
 void
-TestConfigBackendDHCPv4Impl::createUpdateGlobalParameter4(const db::ServerSelector& /* server_selector */,
-                                                          const data::StampedValuePtr& /* value */) {
+TestConfigBackendDHCPv4::createUpdateGlobalParameter4(const db::ServerSelector& /* server_selector */,
+                                                        const data::StampedValuePtr& /* value */) {
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteSubnet4(const db::ServerSelector& /* server_selector */,
-                                           const std::string& /* subnet_prefix */) {
+TestConfigBackendDHCPv4::deleteSubnet4(const db::ServerSelector& /* server_selector */,
+                                         const std::string& /* subnet_prefix */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteSubnet4(const db::ServerSelector& /* server_selector */,
-                                           const SubnetID& /* subnet_id */) {
+TestConfigBackendDHCPv4::deleteSubnet4(const db::ServerSelector& /* server_selector */,
+                                         const SubnetID& /* subnet_id */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteAllSubnets4(const db::ServerSelector& /* server_selector */) {
+TestConfigBackendDHCPv4::deleteAllSubnets4(const db::ServerSelector& /* server_selector */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteSharedNetwork4(const db::ServerSelector& /* server_selector */,
-                                                  const std::string& /* name */) {
+TestConfigBackendDHCPv4::deleteSharedNetwork4(const db::ServerSelector& /* server_selector */,
+                                                const std::string& /* name */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteAllSharedNetworks4(const db::ServerSelector& /* server_selector */) {
+TestConfigBackendDHCPv4::deleteAllSharedNetworks4(const db::ServerSelector& /* server_selector */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteOptionDef4(const db::ServerSelector& /* server_selector */,
-                                              const uint16_t /* code */,
-                                              const std::string& /* space */) {
+TestConfigBackendDHCPv4::deleteOptionDef4(const db::ServerSelector& /* server_selector */,
+                                            const uint16_t /* code */,
+                                            const std::string& /* space */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteAllOptionDefs4(const db::ServerSelector& /* server_selector */) {
+TestConfigBackendDHCPv4::deleteAllOptionDefs4(const db::ServerSelector& /* server_selector */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
-                                           const uint16_t /* code */,
-                                           const std::string& /* space */) {
+TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
+                                         const uint16_t /* code */,
+                                         const std::string& /* space */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
-                                           const std::string& /* shared_network_name */,
-                                           const uint16_t /* code */,
-                                           const std::string& /* space */) {
+TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
+                                         const std::string& /* shared_network_name */,
+                                         const uint16_t /* code */,
+                                         const std::string& /* space */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
-                                           const SubnetID& /* subnet_id */,
-                                           const uint16_t /* code */,
-                                           const std::string& /* space */) {
+TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
+                                         const SubnetID& /* subnet_id */,
+                                         const uint16_t /* code */,
+                                         const std::string& /* space */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteOption4(const db::ServerSelector& /* server_selector */,
-                                           const asiolink::IOAddress& /* pool_start_address */,
-                                           const asiolink::IOAddress& /* pool_end_address */,
-                                           const uint16_t /* code */,
-                                           const std::string& /* space */) {
+TestConfigBackendDHCPv4::deleteOption4(const db::ServerSelector& /* server_selector */,
+                                         const asiolink::IOAddress& /* pool_start_address */,
+                                         const asiolink::IOAddress& /* pool_end_address */,
+                                         const uint16_t /* code */,
+                                         const std::string& /* space */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteGlobalParameter4(const db::ServerSelector& /* server_selector */,
-                                                    const std::string& /* name */) {
+TestConfigBackendDHCPv4::deleteGlobalParameter4(const db::ServerSelector& /* server_selector */,
+                                                  const std::string& /* name */) {
     return (0);
 }
 
 uint64_t
-TestConfigBackendDHCPv4Impl::deleteAllGlobalParameters4(const db::ServerSelector& /* server_selector */) {
+TestConfigBackendDHCPv4::deleteAllGlobalParameters4(const db::ServerSelector& /* server_selector */) {
     return (0);
 }
 
index 8ce6bc8a4ede49e61e899d4e061c1a052d8f763e..03e6b5fa1a2a2690355f1a8f0859e7b30e5f5eb8 100644 (file)
@@ -4,10 +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 TEST_CONFIG_BACKEND_DHCP4
+#define TEST_CONFIG_BACKEND_DHCP4
+
 #include <config.h>
 
 #include <database/database_connection.h>
 #include <dhcpsrv/config_backend_dhcp4_mgr.h>
+#include <dhcpsrv/testutils/test_config_backend.h>
+
 #include <boost/shared_ptr.hpp>
 #include <boost/lexical_cast.hpp>
 
@@ -15,71 +20,6 @@ namespace isc {
 namespace dhcp {
 namespace test {
 
-/// @brief Base class for implementing fake backends
-class TestConfigBackendDHCPv4 : public ConfigBackendDHCPv4 {
-public:
-    /// @brief Constructor
-    ///
-    /// @param params database connection parameters
-    /// @throw BadValue if parameters do not include "type"
-    TestConfigBackendDHCPv4(const db::DatabaseConnection::ParameterMap& params)
-     : connection_(params) {
-        try {
-            db_type_ = connection_.getParameter("type");
-        } catch (...) {
-            isc_throw(BadValue, "Backend parameters must include \"type\"");
-        }
-
-        try {
-            db_type_ = connection_.getParameter("host");
-        } catch (...) {
-            host_ = "default_host";
-        }
-
-        try {
-            port_ = boost::lexical_cast<uint16_t>(connection_.getParameter("host"));
-        } catch (...) {
-            port_ = 0;
-        }
-    }
-
-    /// @brief virtual Destructor.
-    virtual ~TestConfigBackendDHCPv4(){};
-
-    /// @brief Returns backend type.
-    ///
-    /// @return string db_type name
-    virtual std::string getType() const {
-        return (db_type_);
-    }
-
-    /// @brief Returns backend host.
-    ///
-    /// @return string host
-    virtual std::string getHost() const {
-        return (host_);
-    }
-
-    /// @brief Returns backend port.
-    ///
-    /// @return uint16_t port
-    virtual uint16_t getPort() const {
-        return (port_);
-    }
-
-    /// @brief Fake database connection
-    db::DatabaseConnection connection_;
-
-    /// @brief  Back end type
-    std::string db_type_;
-
-    /// @brief  Back end host
-    std::string host_;
-
-    /// @brief  Back end port
-    uint16_t port_;
-};
-
 /// @brief Test backend for that implements all of the DHCPv4 API calls
 ///
 /// Currently all API get calls which return a single entry, will return an
@@ -88,17 +28,17 @@ public:
 ///
 /// In addition provides static register and unregister methods so it may be
 /// registered with a configuration backend manager.
-class TestConfigBackendDHCPv4Impl : public TestConfigBackendDHCPv4 {
+class TestConfigBackendDHCPv4 : public TestConfigBackend<ConfigBackendDHCPv4> {
 public:
     /// @brief Constructor
     ///
     ///
-    TestConfigBackendDHCPv4Impl(const db::DatabaseConnection::ParameterMap& params)
-        : TestConfigBackendDHCPv4(params) {
+    TestConfigBackendDHCPv4(const db::DatabaseConnection::ParameterMap& params)
+        : TestConfigBackend(params) {
     }
 
     /// @brief virtual Destructor.
-    virtual ~TestConfigBackendDHCPv4Impl(){};
+    virtual ~TestConfigBackendDHCPv4(){};
 
     /// @brief Registers the backend type with the given backend manager
     ///
@@ -229,7 +169,7 @@ public:
     /// @return Collection of global options or empty collection if no
     /// option found.
     virtual OptionContainer
-    getModifiedOptions4(const db::ServerSelector& selector,
+    getModifiedOptions4(const db::ServerSelector& server_selector,
                         const boost::posix_time::ptime& modification_time) const;
 
     /// @brief Retrieves global parameter value.
@@ -239,19 +179,19 @@ public:
     /// @return Value of the global parameter or null if parameter doesn't
     /// exist.
     virtual data::StampedValuePtr
-    getGlobalParameter4(const db::ServerSelector& selector,
+    getGlobalParameter4(const db::ServerSelector& server_selector,
                         const std::string& name) const;
 
     /// @return Collection of global parameters.
     virtual data::StampedValueCollection
-    getAllGlobalParameters4(const db::ServerSelector& selector) const;
+    getAllGlobalParameters4(const db::ServerSelector& server_selector) const;
 
     /// @brief Retrieves global parameters modified after specified time.
     ///
     /// @param selector Server selector.
     /// @return Collection of modified global parameters.
     virtual data::StampedValueCollection
-    getModifiedGlobalParameters4(const db::ServerSelector& selector,
+    getModifiedGlobalParameters4(const db::ServerSelector& server_selector,
                                  const boost::posix_time::ptime& modification_time) const;
 
     /// @brief Creates or updates a subnet.
@@ -293,7 +233,7 @@ public:
     /// belongs.
     /// @param option Option to be added or updated.
     virtual void
-    createUpdateOption4(const db::ServerSelector& selector,
+    createUpdateOption4(const db::ServerSelector& server_selector,
                         const std::string& shared_network_name,
                         const OptionDescriptorPtr& option);
 
@@ -404,7 +344,7 @@ public:
     /// @param code Code of the option to be deleted.
     /// @param space Option space of the option to be deleted.
     virtual uint64_t
-    deleteOption4(const db::ServerSelector& selector,
+    deleteOption4(const db::ServerSelector& server_selector,
                   const std::string& shared_network_name,
                   const uint16_t code,
                   const std::string& space);
@@ -464,9 +404,11 @@ public:
 /// @}
 };
 
-/// @brief Shared pointer to the @c TestConfigBackendImpl.
-typedef boost::shared_ptr<TestConfigBackendDHCPv4Impl> TestConfigBackendDHCPv4ImplPtr;
+/// @brief Shared pointer to the @c TestConfigBackend.
+typedef boost::shared_ptr<TestConfigBackendDHCPv4> TestConfigBackendDHCPv4Ptr;
 
 } // namespace test
 } // namespace dhcp
 } // namespace isc
+
+#endif // TEST_CONFIG_BACKEND_DHCP4
index 097231f90bc6a38b6b2abb3890ead50342470de9..b5c94eff5b185e73a2d257c9aa7e269c05b272ef 100644 (file)
@@ -43,6 +43,13 @@ public:
         return (access_str_);
     }
 
+    /// @brief Retrieves the database access string with password redacted.
+    ///
+    /// @return database access string with password redacted
+    std::string redactedAccessString() const {
+        return(db::DatabaseConnection::redactedAccessString(access_params_));
+    }
+
     /// @brief Retrieve the map of parameter values.
     ///
     /// @return Constant reference to the database's parameter map.
index 40b49b6e9e014cbd89834331a301ccfca1585e9b..5f0c50f5d6f0a6ed4b487d2c084bb0238e29b44b 100644 (file)
@@ -22,6 +22,7 @@ using namespace isc::data;
 TEST(ConfigDbInfo, basicOperation) {
     ConfigDbInfo db;
     std::string access = "type=mysql user=tom password=terrific";
+    std::string redacted_access = "password=***** type=mysql user=tom";
     std::string access_json = "{\n"
         " \"type\":\"mysql\", \n"
         " \"user\":\"tom\", \n"
@@ -37,6 +38,8 @@ TEST(ConfigDbInfo, basicOperation) {
     db.setAccessString(access);
     EXPECT_EQ(access, db.getAccessString());
 
+    EXPECT_EQ(redacted_access, db.redactedAccessString());
+
     // Convert the db into Elements and make sure they are as expected.
     ElementPtr db_elems;
     ASSERT_NO_THROW(db_elems = db.toElement());