From: Tomek Mrugalski Date: Wed, 9 Mar 2016 17:59:06 +0000 (+0100) Subject: [4297] Unit-tests updated after recent API change. X-Git-Tag: trac4298_base~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e10309c77ed1055b09b34fc819feedc8b8c427a8;p=thirdparty%2Fkea.git [4297] Unit-tests updated after recent API change. --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index faf0a53722..096c80bc0a 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -45,7 +45,7 @@ ControlledDhcpv4Srv::commandLibReloadHandler(const string&, ConstElementPtr) { /// @todo delete any stored CalloutHandles referring to the old libraries /// Get list of currently loaded libraries and reload them. - vector loaded = HooksManager::getLibraryNames(); + HookLibsCollection loaded = HooksManager::getLibraryInfo(); bool status = HooksManager::loadLibraries(loaded); if (!status) { LOG_ERROR(dhcp4_logger, DHCP4_HOOKS_LIBS_RELOAD_FAIL); diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 5cf827a4cc..77bcb09035 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-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 @@ -233,15 +233,15 @@ TEST_F(CtrlChannelDhcpv4SrvTest, libreload) { ASSERT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE)); // Load two libraries - std::vector libraries; - libraries.push_back(CALLOUT_LIBRARY_1); - libraries.push_back(CALLOUT_LIBRARY_2); + HookLibsCollection libraries; + libraries.push_back(make_pair(CALLOUT_LIBRARY_1, ConstElementPtr())); + libraries.push_back(make_pair(CALLOUT_LIBRARY_2, ConstElementPtr())); HooksManager::loadLibraries(libraries); // Check they are loaded. std::vector loaded_libraries = HooksManager::getLibraryNames(); - ASSERT_TRUE(libraries == loaded_libraries); + ASSERT_TRUE(extractNames(libraries) == loaded_libraries); // ... which also included checking that the marker file created by the // load functions exists and holds the correct value (of "12" - the diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 5369174ac6..17de52612b 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -51,7 +51,7 @@ ConstElementPtr ControlledDhcpv6Srv::commandLibReloadHandler(const string&, ConstElementPtr) { /// @todo delete any stored CalloutHandles referring to the old libraries /// Get list of currently loaded libraries and reload them. - vector loaded = HooksManager::getLibraryNames(); + HookLibsCollection loaded = HooksManager::getLibraryInfo(); bool status = HooksManager::loadLibraries(loaded); if (!status) { LOG_ERROR(dhcp6_logger, DHCP6_HOOKS_LIBS_RELOAD_FAIL); diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 0b424386bf..9b6ba605be 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-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 @@ -249,14 +249,14 @@ TEST_F(CtrlDhcpv6SrvTest, libreload) { ASSERT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE)); // Load two libraries - std::vector libraries; - libraries.push_back(CALLOUT_LIBRARY_1); - libraries.push_back(CALLOUT_LIBRARY_2); + HookLibsCollection libraries; + libraries.push_back(make_pair(CALLOUT_LIBRARY_1, ConstElementPtr())); + libraries.push_back(make_pair(CALLOUT_LIBRARY_2, ConstElementPtr())); HooksManager::loadLibraries(libraries); // Check they are loaded. - std::vector loaded_libraries = - HooksManager::getLibraryNames(); + HookLibsCollection loaded_libraries = + HooksManager::getLibraryInfo(); ASSERT_TRUE(libraries == loaded_libraries); // ... which also included checking that the marker file created by the diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 6fd271a246..99d35053f3 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,3 +1,3 @@ # The following build order must be maintained. -SUBDIRS = exceptions util log hooks cryptolink dns cc asiolink testutils dhcp config \ +SUBDIRS = exceptions util log cryptolink dns cc hooks asiolink testutils dhcp config \ stats asiodns dhcp_ddns eval dhcpsrv cfgrpt diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index c34c578141..d9767a4688 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -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 @@ -251,6 +251,7 @@ HooksLibrariesParser::build(ConstElementPtr value) { // Initialize. libraries_.clear(); changed_ = false; + ConstElementPtr parameters; // This is the new syntax. Iterate through it and get each map. BOOST_FOREACH(ConstElementPtr library_entry, value->listValue()) { @@ -264,6 +265,13 @@ HooksLibrariesParser::build(ConstElementPtr value) { // Iterate iterate through each element in the map. We check // whether we have found a library element. bool lib_found = false; + + string libname = ""; + + // Let's explicitly reset the parameters, so we won't cover old + // values from the previous loop round. + parameters.reset(); + BOOST_FOREACH(ConfigPair entry_item, library_entry->mapValue()) { if (entry_item.first == "library") { if (entry_item.second->getType() != Element::string) { @@ -275,7 +283,7 @@ HooksLibrariesParser::build(ConstElementPtr value) { // Get the name of the library and add it to the list after // removing quotes. - string libname = (entry_item.second)->stringValue(); + libname = (entry_item.second)->stringValue(); // Remove leading/trailing quotes and any leading/trailing // spaces. @@ -287,10 +295,14 @@ HooksLibrariesParser::build(ConstElementPtr value) { " blank (" << entry_item.second->getPosition() << ")"); } - libraries_.push_back(libname); // Note we have found the library name. lib_found = true; + } else { + // If there are parameters, let's remember them. + if (entry_item.first == "parameters") { + parameters = entry_item.second; + } } } if (! lib_found) { @@ -299,19 +311,26 @@ HooksLibrariesParser::build(ConstElementPtr value) { " name of the library" << " (" << library_entry->getPosition() << ")"); } + + libraries_.push_back(make_pair(libname, parameters)); } // Check if the list of libraries has changed. If not, nothing is done // - the command "DhcpN libreload" is required to reload the same // libraries (this prevents needless reloads when anything else in the // configuration is changed). + + // We no longer rely on this. Parameters can change. And even if the + // parameters stay the same, they could point to a files that could + // change. vector current_libraries = HooksManager::getLibraryNames(); - if (current_libraries == libraries_) { + if (current_libraries.empty() && libraries_.empty()) { return; } // Library list has changed, validate each of the libraries specified. - vector error_libs = HooksManager::validateLibraries(libraries_); + vector lib_names = isc::hooks::extractNames(libraries_); + vector error_libs = HooksManager::validateLibraries(lib_names); if (!error_libs.empty()) { // Construct the list of libraries in error for the message. @@ -334,15 +353,15 @@ HooksLibrariesParser::commit() { /// Commits the list of libraries to the configuration manager storage if /// the list of libraries has changed. if (changed_) { - // TODO Delete any stored CalloutHandles before reloading the - // libraries + /// @todo: Delete any stored CalloutHandles before reloading the + /// libraries HooksManager::loadLibraries(libraries_); } } // Method for testing void -HooksLibrariesParser::getLibraries(std::vector& libraries, +HooksLibrariesParser::getLibraries(isc::hooks::HookLibsCollection& libraries, bool& changed) { libraries = libraries_; changed = changed_; diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.h b/src/lib/dhcpsrv/parsers/dhcp_parsers.h index 543a6a9871..8535b8eab4 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.h +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.h @@ -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 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -35,9 +36,6 @@ typedef OptionSpaceContainer OptionStoragePtr; -/// @brief Shared pointer to collection of hooks libraries. -typedef boost::shared_ptr > HooksLibsStoragePtr; - /// @brief A template class that stores named elements of a given data type. /// /// This template class is provides data value storage for configuration @@ -218,7 +216,7 @@ public: /// the list of current names can be obtained from the HooksManager) or it /// is non-null (this is the new list of names, reload the libraries when /// possible). - HooksLibsStoragePtr hooks_libraries_; + isc::hooks::HookLibsCollectionPtr hooks_libraries_; /// @brief The parsing universe of this context. Option::Universe universe_; @@ -508,11 +506,11 @@ public: /// new configuration. /// @param [out] changed true if the list is different from that currently /// loaded. - void getLibraries(std::vector& libraries, bool& changed); + void getLibraries(isc::hooks::HookLibsCollection& libraries, bool& changed); private: - /// List of hooks libraries. - std::vector libraries_; + /// List of hooks libraries with their configuration parameters + isc::hooks::HookLibsCollection libraries_; /// Indicator flagging that the list of libraries has changed. bool changed_; diff --git a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc index 817fa6e02f..3c4e314d15 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-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 @@ -847,7 +847,7 @@ public: } } - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install a callout: lease4_expire or lease6_expire. @@ -877,7 +877,7 @@ public: } } - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install a callout: lease4_expire or lease6_expire. @@ -905,7 +905,7 @@ public: expire(i, 2000 - i); } - vector libraries; + HookLibsCollection libraries; HooksManager::loadLibraries(libraries); // Install a callout: lease4_expire or lease6_expire. Each callout diff --git a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc index f3ae3d75b5..d0142c6d24 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-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 @@ -137,7 +137,7 @@ TEST_F(HookAllocEngine6Test, lease6_select) { ASSERT_TRUE(engine); // Initialize Hooks Manager - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install pkt6_receive_callout @@ -207,7 +207,7 @@ TEST_F(HookAllocEngine6Test, change_lease6_select) { ASSERT_TRUE(engine); // Initialize Hooks Manager - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install a callout @@ -368,7 +368,7 @@ TEST_F(HookAllocEngine4Test, lease4_select) { ASSERT_TRUE(engine); // Initialize Hooks Manager - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install pkt4_receive_callout @@ -435,7 +435,7 @@ TEST_F(HookAllocEngine4Test, change_lease4_select) { ASSERT_TRUE(engine); // Initialize Hooks Manager - vector libraries; // no libraries at this time + HookLibsCollection libraries; // no libraries at this time HooksManager::loadLibraries(libraries); // Install a callout