]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#101,!58] Addressed review comments
authorThomas Markwalder <tmark@isc.org>
Thu, 11 Oct 2018 18:15:25 +0000 (14:15 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 11 Oct 2018 18:17:14 +0000 (14:17 -0400)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_mgr_unittest.cc
src/lib/config_backend/base_config_backend_mgr.h
src/lib/dhcpsrv/config_backend_dhcp4_mgr.cc
src/lib/dhcpsrv/config_backend_dhcp4_mgr.h

index c537aa10bb82706fbbd0504848c7f79f660eab73..1a44182085d212556398dd0126677935a60d9b6c 100644 (file)
@@ -2690,12 +2690,14 @@ MySqlConfigBackendDHCPv4::getPort() const {
     return (0);
 }
 
-void
+bool
 MySqlConfigBackendDHCPv4::registerBackendType() {
-    dhcp::ConfigBackendDHCPv4Mgr::instance().registerBackendFactory("mysql",
-        [](const db::DatabaseConnection::ParameterMap& params) -> dhcp::ConfigBackendDHCPv4Ptr {
+    return (
+        dhcp::ConfigBackendDHCPv4Mgr::instance().registerBackendFactory("mysql",
+            [](const db::DatabaseConnection::ParameterMap& params) -> dhcp::ConfigBackendDHCPv4Ptr {
             return (dhcp::MySqlConfigBackendDHCPv4Ptr(new dhcp::MySqlConfigBackendDHCPv4(params)));
-        });
+        })
+    );
 }
 
 void
index da8f918316ac33eb925d6220e37dd5fd56069d67..0e5fba184145aa8c8394a6e0c38c84267a2a138a 100644 (file)
@@ -391,7 +391,8 @@ public:
     /// @brief Registers the MySQL backend factory with backend config manager
     ///
     /// This should be called by the hook lib load() function.
-    static void registerBackendType();
+    /// @return True if the factory was registered successfully, false otherwise.
+    static bool registerBackendType();
 
     /// @brief Unregisters the MySQL backend factory and discards MySQL backends
     ///
index e5d9bae6f25c96e58d7e65a9d3fde16c137f3e55..efbf713367b46046c481c4e5f6b181ee38ba307e 100644 (file)
@@ -9,18 +9,20 @@
 #include <dhcpsrv/config_backend_dhcp4_mgr.h>
 #include <mysql_cb_dhcp4.h>
 #include <mysql/testutils/mysql_schema.h>
+#include <dhcpsrv/testutils/generic_backend_unittest.h>
 #include <boost/shared_ptr.hpp>
 #include <gtest/gtest.h>
 
 using namespace isc::data;
 using namespace isc::dhcp;
+using namespace isc::dhcp::test;
 using namespace isc::db;
 using namespace isc::db::test;
 
 namespace {
 
 /// @brief Test fixture class for @c MySqlConfigBackendDHCPv4Mgr.
-class MySqlConfigBackendDHCPv4MgrTest : public ::testing::Test {
+class MySqlConfigBackendDHCPv4MgrTest : public GenericBackendTest {
 public:
     /// @brief Constructor.
     MySqlConfigBackendDHCPv4MgrTest() {
@@ -34,6 +36,8 @@ public:
 
     /// @brief Destructor.
     virtual ~MySqlConfigBackendDHCPv4MgrTest() {
+        // Destroy the mgr.
+        ConfigBackendDHCPv4Mgr::destroy();
         destroyMySQLSchema();
     }
 };
index bf0dcca0259850eff4533a04e1032df02e65af26..72690369b17bdf871c853b264883d55cf1b5d175 100644 (file)
@@ -107,15 +107,15 @@ public:
 
     /// @brief Unregisters the backend factory function for a given backend type.
     ///
-    /// The typical usage of this function is remove the factory function
-    /// when its type of backend is no longer supported (i.e hook lib is unloaded).
-    /// It should mirror the use @c registerBackendFactory and be called from the
-    /// hooks library @c unload function.
+    /// This function is used to remove the factory function and all backend instances
+    /// for a given backend type.  Typically, it would be called when unloading the
+    /// a config backend hook library, and thus called by the library's @c unload
+    /// function.
     ///
     /// @param db_type Backend type, e.g. "mysql".
     ///
-    /// @return false if no factory for the given type was not registered, true
-    /// true if the factory was removed.
+    /// @return false if no factory for the given type was unregistered, true
+    /// if the factory was removed.
     bool unregisterBackendFactory(const std::string& db_type) {
         // Look for it.
         auto index = factories_.find(db_type);
index d89165eb8853b3375ae1af540761d58289b91058..134f0200c4613986b930982f35a3f02fed564707 100644 (file)
@@ -23,6 +23,11 @@ ConfigBackendDHCPv4Mgr::create() {
     getConfigBackendDHCPv4MgrPtr().reset(new ConfigBackendDHCPv4Mgr());
 }
 
+void
+ConfigBackendDHCPv4Mgr::destroy() {
+    getConfigBackendDHCPv4MgrPtr().reset(new ConfigBackendDHCPv4Mgr());
+}
+
 ConfigBackendDHCPv4Mgr&
 ConfigBackendDHCPv4Mgr::instance() {
     boost::scoped_ptr<ConfigBackendDHCPv4Mgr>& cb_dhcp4_mgr = getConfigBackendDHCPv4MgrPtr();
index c13abe83553c82cecf62ae13187505d6cc623e96..53073c1e38ea88bec322709840e62a9157dcb49b 100644 (file)
@@ -18,33 +18,40 @@ namespace dhcp {
 /// @brief Configuration Backend Manager for DHPCv4 servers.
 ///
 /// Implements the "manager" class which holds information about the
-/// supported and configured backends and provides access to those 
-/// backends. This is similar to @c HostMgr and @c LeaseMgr singletons 
+/// supported and configured backends and provides access to those
+/// backends. This is similar to @c HostMgr and @c LeaseMgr singletons
 /// being used by the DHCP servers.
 ///
 /// It is implemented as a singleton that can be accessed from any place
-/// within the server code. This includes server configuration, data 
-/// fetching during normal server operation and data management, including 
+/// within the server code. This includes server configuration, data
+/// fetching during normal server operation and data management, including
 /// processing of control commands implemented within hooks libraries.
 ///
 /// Unlike @c HostMgr, the it does not directly expose the API to fetch and
 /// manipulate the data in the database. This is done via, the Configuration
-/// Backend Pool, see @c ConfigBackendPoolDHCPv4 for details. 
-class ConfigBackendDHCPv4Mgr : public cb::BaseConfigBackendMgr<ConfigBackendPoolDHCPv4>, 
+/// Backend Pool, see @c ConfigBackendPoolDHCPv4 for details.
+class ConfigBackendDHCPv4Mgr : public cb::BaseConfigBackendMgr<ConfigBackendPoolDHCPv4>,
                                public boost::noncopyable {
 public:
     /// @brief Creates new instance of the @c ConfigBackendDHCPv4Mgr.
     ///
-    /// If an instance of the @c ConfigBackendDHCPv4Mgr already exists, 
-    /// it will be replaced by the new instance. Thus, any instances of 
-    /// config databases will be dropped.
+    /// If an instance of the @c ConfigBackendDHCPv4Mgr already exists,
+    /// it will be replaced by the new instance. Thus, all factories
+    /// will be unregistered and config databases will be dropped.
     static void create();
 
+    /// @brief Destroys the instance of the @c ConfigBackendDHCPv4Mgr.
+    ///
+    /// If an instance of the @c ConfigBackendDHCPv4Mgr exists,
+    /// it will be destroyed.  Thus, all factories will be unregistered
+    /// and config databases will be dropped.
+    static void destroy();
+
     /// @brief Returns a sole instance of the @c ConfigBackendDHCPv4Mgr.
     ///
     /// This method should be used to retrieve an instance of the @c ConfigBackendDHCPv4Mgr
     /// to be used to gather/manage config backends. It returns an instance
-    /// of the @c ConfigBackendDHCPv4Mgr created by the @c create method. If 
+    /// of the @c ConfigBackendDHCPv4Mgr created by the @c create method. If
     /// the instance doesn't exist yet, it is created using the @c create method
     /// with the an empty set of configuration databases.
     static ConfigBackendDHCPv4Mgr& instance();