]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5095] Second attempt with a shared callout manager
authorFrancis Dupont <fdupont@isc.org>
Sat, 31 Dec 2016 19:17:16 +0000 (20:17 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sat, 31 Dec 2016 19:17:16 +0000 (20:17 +0100)
src/bin/dhcp4/tests/hooks_unittest.cc
src/bin/dhcp6/tests/hooks_unittest.cc
src/lib/hooks/callout_manager.cc
src/lib/hooks/callout_manager.h
src/lib/hooks/library_manager_collection.cc

index b57ba297401f09525c7fd645e92f81362cca5c04..c9cef864cdc8b18e2af42c645aa4bda3a3cf8ece 100644 (file)
@@ -13,6 +13,7 @@
 #include <config/command_mgr.h>
 #include <hooks/server_hooks.h>
 #include <hooks/hooks_manager.h>
+#include <hooks/callout_manager.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp/option.h>
@@ -111,6 +112,7 @@ public:
         HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_release");
         HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_decline");
 
+        CalloutManager::getSharedManager().reset();
         delete srv_;
     }
 
@@ -1607,6 +1609,9 @@ TEST_F(HooksDhcpv4SrvTest, HooksDecline) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
 
+    // Libraries will be reloaded later
+    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+
     // Install a callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
                         "lease4_decline", lease4_decline_callout));
@@ -1653,6 +1658,9 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineDrop) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
 
+    // Libraries will be reloaded later
+    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+
     // Install a callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
                         "lease4_decline", lease4_decline_drop_callout));
index 975fd797fcaef036f8d6006658ec0105ebb154ea..82f928e2f6779cd33e3136f8ff06f457515c0bf1 100644 (file)
@@ -18,6 +18,7 @@
 #include <util/buffer.h>
 #include <util/range_utilities.h>
 #include <hooks/server_hooks.h>
+#include <hooks/callout_manager.h>
 
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/dhcp6_client.h>
@@ -113,10 +114,17 @@ public:
 
         // Clear static buffers
         resetCalloutBuffers();
+
+       // Reset the hook system in its original state
+       HooksManager::unloadLibraries();
     }
 
     /// @brief destructor (deletes Dhcpv6Srv)
     ~HooksDhcpv6SrvTest() {
+
+        // Clear shared manager
+        CalloutManager::getSharedManager().reset();
+
     }
 
     /// @brief creates an option with specified option code
@@ -2082,6 +2090,9 @@ TEST_F(HooksDhcpv6SrvTest, skipLease6Rebind) {
 TEST_F(HooksDhcpv6SrvTest, basicLease6Decline) {
     IfaceMgrTestConfig test_config(true);
 
+    // Libraries will be reloaded later
+    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+
     // Install lease6_decline callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
                         "lease6_decline", lease6_decline_callout));
@@ -2126,10 +2137,12 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Decline) {
 }
 
 // Test that the lease6_decline hook point can handle SKIP status.
-/// @todo: Reenable this once #5095 is fixed.
-TEST_F(HooksDhcpv6SrvTest, DISABLED_lease6DeclineSkip) {
+TEST_F(HooksDhcpv6SrvTest, lease6DeclineSkip) {
     IfaceMgrTestConfig test_config(true);
 
+    // Libraries will be reloaded later
+    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+
     // Install lease6_decline callout. It will set the status to skip
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
                         "lease6_decline", lease6_decline_skip_callout));
@@ -2174,6 +2187,9 @@ TEST_F(HooksDhcpv6SrvTest, DISABLED_lease6DeclineSkip) {
 TEST_F(HooksDhcpv6SrvTest, lease6DeclineDrop) {
     IfaceMgrTestConfig test_config(true);
 
+    // Libraries will be reloaded later
+    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+
     // Install lease6_decline callout. It will set the status to skip
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
                         "lease6_decline", lease6_decline_drop_callout));
index d41f7df44339cb19f9476e3bbad96dd9ff8a360d..2ab33d7c2326f86e93f39ef9f823599c2fac06b4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 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
@@ -24,6 +24,8 @@ using namespace std;
 namespace isc {
 namespace hooks {
 
+boost::shared_ptr<CalloutManager> CalloutManager::shared_manager_;
+
 // Constructor
 CalloutManager::CalloutManager(int num_libraries)
     : server_hooks_(ServerHooks::getServerHooks()),
index 843e1b9cc8c7a10cf4ebaaed8dd6a311583cbb8f..d58855580e0189b5c058fff855baf24a7eedb54d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2016 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
@@ -298,6 +298,13 @@ public:
 
     //@}
 
+    /// @brief Return the shared manager
+    ///
+    /// @return A reference to the shared manager
+    static boost::shared_ptr<CalloutManager>& getSharedManager() {
+        return (shared_manager_);
+    }
+
 private:
     /// @brief Check library index
     ///
@@ -368,6 +375,9 @@ private:
 
     /// Number of libraries.
     int num_libraries_;
+
+    /// Shared manager to survive library reloads
+    static boost::shared_ptr<CalloutManager> shared_manager_;
 };
 
 } // namespace util
index ae2a37aa304a6f52efad449fa03da8f828b16627..1cdc55a1c2fed3fcef13c5b79f3be8b5cbba1873 100644 (file)
@@ -62,7 +62,15 @@ LibraryManagerCollection::loadLibraries() {
     // The upshot of this is that it is therefore safe for the CalloutManager
     // to be deleted after all associated libraries are deleted, hence this
     // link (LibraryManager -> CalloutManager) is safe.
-    callout_manager_.reset(new CalloutManager(library_names_.size()));
+    //
+    // To survive reloads an attempt to re-use the shared manager
+    // is performed when the list of library is empty.
+    if (library_names_.empty()) {
+        callout_manager_ = CalloutManager::getSharedManager();
+    }
+    if (!library_names_.empty() || !callout_manager_) {
+        callout_manager_.reset(new CalloutManager(library_names_.size()));
+    }
 
     // Now iterate through the libraries are load them one by one.  We'll
     for (size_t i = 0; i < library_names_.size(); ++i) {