/// @brief creates Dhcpv4Srv and prepares buffers for callouts
HooksDhcpv4SrvTest() {
+ HooksManager::getHooksManager().setTestMode(false);
// Allocate new DHCPv6 Server
srv_ = new NakedDhcpv4Srv(0);
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_decline");
HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("host4_identifier");
- HooksManager::getHooksManager().setSharedCalloutManager();
delete srv_;
+ HooksManager::getHooksManager().setTestMode(false);
}
/// @brief creates an option with specified option code
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install a callout
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease4_decline", lease4_decline_callout));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Conduct the actual DORA + Decline.
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install a callout
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease4_decline", lease4_decline_skip_callout));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Conduct the actual DORA + Decline. The DECLINE should fail, as the
// hook will set the status to SKIP.
Dhcp4Client client(Dhcp4Client::SELECTING);
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install a callout
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease4_decline", lease4_decline_drop_callout));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Conduct the actual DORA + Decline. The DECLINE should fail, as the
// hook will set the status to DROP.
Dhcp4Client client(Dhcp4Client::SELECTING);
HooksDhcpv6SrvTest()
: Dhcpv6SrvTest() {
+ HooksManager::getHooksManager().setTestMode(false);
+
// Allocate new DHCPv6 Server
srv_.reset(new NakedDhcpv6Srv(0));
/// @brief destructor (deletes Dhcpv6Srv)
~HooksDhcpv6SrvTest() {
-
- // Clear shared manager
- HooksManager::getHooksManager().setSharedCalloutManager();
-
+ HooksManager::getHooksManager().setTestMode(false);
}
/// @brief creates an option with specified option code
TEST_F(HooksDhcpv6SrvTest, basicLease6Decline) {
IfaceMgrTestConfig test_config(true);
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install lease6_decline callout
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease6_decline", lease6_decline_callout));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Get an address and decline it. DUIDs, IAID match and we send valid
// address, so the decline procedure should be successful.
Dhcp6Client client;
TEST_F(HooksDhcpv6SrvTest, lease6DeclineSkip) {
IfaceMgrTestConfig test_config(true);
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install lease6_decline_skip callout. It will set the status to skip
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease6_decline", lease6_decline_skip));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Get an address and decline it. DUIDs, IAID match and we send valid
// address, so the decline procedure should be successful.
Dhcp6Client client;
TEST_F(HooksDhcpv6SrvTest, lease6DeclineDrop) {
IfaceMgrTestConfig test_config(true);
- // Libraries will be reloaded later
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Install lease6_decline_drop callout. It will set the status to drop
EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
"lease6_decline", lease6_decline_drop));
+ HooksManager::getHooksManager().setTestMode(true);
+
// Get an address and decline it. DUIDs, IAID match and we send valid
// address, so it would work, but the callout sets status to DROP, so
// the server should not update the lease and should not send back any
namespace isc {
namespace hooks {
-boost::shared_ptr<CalloutManager> HooksManager::shared_callout_manager_;
-bool HooksManager::loaded_;
-
// Constructor
HooksManager::HooksManager() {
bool
HooksManager::loadLibrariesInternal(const HookLibsCollection& libraries) {
+ if (test_mode_) {
+ return (true);
+ }
// Unload current set of libraries (if any are loaded).
unloadLibrariesInternal(false);
init();
}
- loaded_ = true;
-
return (status);
}
lm_collection_.reset();
callout_manager_.reset();
}
-
- loaded_ = false;
}
void HooksManager::unloadLibraries() {
return (LibraryManagerCollection::validateLibraries(libraries));
}
-boost::shared_ptr<CalloutManager>
-HooksManager::getSharedCalloutManager() {
- return (shared_callout_manager_);
-}
+bool HooksManager::test_mode_;
-void
-HooksManager::setSharedCalloutManager(boost::shared_ptr<CalloutManager> manager) {
- shared_callout_manager_ = manager;
- if (!loaded_) {
- unloadLibraries();
- }
+void HooksManager::setTestMode(bool mode) {
+ test_mode_ = mode;
}
} // namespace util
static const int CONTEXT_CREATE = ServerHooks::CONTEXT_CREATE;
static const int CONTEXT_DESTROY = ServerHooks::CONTEXT_DESTROY;
- /// @brief Get the shared callout manager
- ///
- /// @return A reference to the shared callout manager
- static boost::shared_ptr<CalloutManager> getSharedCalloutManager();
-
- /// @brief Set the shared callout manager
- ///
- /// This function sets the shared callout manager and explicitly updates
- /// @ref callout_manager_ (by calling @ref init) if @ref loadLibraries has
- /// not yet been called.
- ///
- /// @param manager The shared callout manager
- static void setSharedCalloutManager(boost::shared_ptr<CalloutManager> manager =
- boost::shared_ptr<CalloutManager>());
-
/// @brief Park an object (packet).
///
/// The typical use case for parking an object is when the server needs to
getHooksManager().clearParkingLotsInternal();
}
+ /// @brief Set test mode which enables the tests to resister callouts before
+ /// calling @ref loadLibraries and the @ref callout_manager_ is preserved.
+ ///
+ /// @param mode the flag which enables or disabled @ref test_mode_.
+ void setTestMode(bool mode);
+
private:
/// @brief Constructor
/// Callout manager for the set of library managers.
boost::shared_ptr<CalloutManager> callout_manager_;
- /// Shared callout manager to survive library reloads.
- static boost::shared_ptr<CalloutManager> shared_callout_manager_;
-
- /// Loaded flag to indicate if @ref loadLibraries has been called
- static bool loaded_;
+ /// Test flag to keep @ref callout_manager_ when calling @ref loadLibraries
+ /// from unittests (called by @ref configureDhcp[46]Server)
+ static bool test_mode_;
};
} // namespace util
// where the hooks-libraries clause was empty and is not changed), try
// to re-use the existing callout manager (so retaining registered pre-
// and post-library callouts).
- if (library_names_.empty()) {
- callout_manager_ = HooksManager::getSharedCalloutManager();
- }
if (!library_names_.empty() || !callout_manager_) {
callout_manager_.reset(new CalloutManager(library_names_.size()));
}
/// Unload all libraries and reset the shared manager.
~HooksManagerTest() {
HooksManager::unloadLibraries();
- HooksManager::getHooksManager().setSharedCalloutManager();
}
// Test with a shared manager the pre- and post- callout functions survive
// a reload
-TEST_F(HooksManagerTest, PrePostCalloutShared) {
+TEST_F(HooksManagerTest, DISABLED_PrePostCalloutShared) {
HookLibsCollection library_names;
- // Initialize the shared manager.
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
// Load the pre- and post- callouts.
HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",
// Test with a shared manager the pre- and post- callout functions survive
// a reload but not with a not empty list of libraries
-TEST_F(HooksManagerTest, PrePostCalloutSharedNotEmpty) {
+TEST_F(HooksManagerTest, DISABLED_PrePostCalloutSharedNotEmpty) {
HookLibsCollection library_names;
library_names.push_back(make_pair(std::string(FULL_CALLOUT_LIBRARY),
data::ConstElementPtr()));
- // Initialize the shared manager.
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Load the pre- and post- callouts.
HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",
testPreCallout);
// Test with a shared manager the pre- and post- callout functions don't
// survive a reload if the shared manager is initialized too late.
-TEST_F(HooksManagerTest, PrePostCalloutSharedTooLate) {
+TEST_F(HooksManagerTest, DISABLED_PrePostCalloutSharedTooLate) {
HookLibsCollection library_names;
EXPECT_TRUE(HooksManager::loadLibraries(library_names));
- // Initialize the shared manager (after loadLibraries so too late)
- HooksManager::getHooksManager().setSharedCalloutManager(
- boost::shared_ptr<CalloutManager>(new CalloutManager(0)));
-
// Load the pre- and post- callouts.
HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",
testPreCallout);