]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4297] Unit-tests updated after recent API change.
authorTomek Mrugalski <tomasz@isc.org>
Wed, 9 Mar 2016 17:59:06 +0000 (18:59 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 9 Mar 2016 17:59:06 +0000 (18:59 +0100)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/lib/Makefile.am
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine_hooks_unittest.cc

index faf0a537222ce37e621a9bc607bf0ecd59a89c86..096c80bc0a61b08a866348d8768bd0147db3503e 100644 (file)
@@ -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<string> loaded = HooksManager::getLibraryNames();
+    HookLibsCollection loaded = HooksManager::getLibraryInfo();
     bool status = HooksManager::loadLibraries(loaded);
     if (!status) {
         LOG_ERROR(dhcp4_logger, DHCP4_HOOKS_LIBS_RELOAD_FAIL);
index 5cf827a4cc2428c218d54460bbe46674a58548c5..77bcb090352b64e0fe38d119287987261f8c9c0e 100644 (file)
@@ -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<std::string> 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<std::string> 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
index 5369174ac60e284e32412e6bcf3390c6daa1255b..17de52612b8f6c629790bcb227bedbcbbdcc3d39 100644 (file)
@@ -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<string> loaded = HooksManager::getLibraryNames();
+    HookLibsCollection loaded = HooksManager::getLibraryInfo();
     bool status = HooksManager::loadLibraries(loaded);
     if (!status) {
         LOG_ERROR(dhcp6_logger, DHCP6_HOOKS_LIBS_RELOAD_FAIL);
index 0b424386bf44c54d552d9bf68828048326ca79fd..9b6ba605be41257f97abced1ab2e23b4266ba231 100644 (file)
@@ -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<std::string> 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<std::string> 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
index 6fd271a24632d560c27b4349a5b763c3b865dd38..99d35053f39e525e4842f78ead2c2163d751599d 100644 (file)
@@ -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
index c34c578141d1b48f7338d3766ed8b4b375d3c3b0..d9767a4688a702bdbe5941778b3cc64485788ca2 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
@@ -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<string> 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<string> error_libs = HooksManager::validateLibraries(libraries_);
+    vector<string> lib_names = isc::hooks::extractNames(libraries_);
+    vector<string> 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<std::string>& libraries,
+HooksLibrariesParser::getLibraries(isc::hooks::HookLibsCollection& libraries,
                                    bool& changed) {
     libraries = libraries_;
     changed = changed_;
index 543a6a9871581970d25745e991324561dd7e5b95..8535b8eab43585748005e98c9e8f2f76160149ab 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
@@ -16,6 +16,7 @@
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/parsers/dhcp_config_parser.h>
+#include <hooks/libinfo.h>
 #include <exceptions/exceptions.h>
 #include <util/optional_value.h>
 
@@ -35,9 +36,6 @@ typedef OptionSpaceContainer<OptionContainer, OptionDescriptor,
 /// @brief Shared pointer to option storage.
 typedef boost::shared_ptr<OptionStorage> OptionStoragePtr;
 
-/// @brief Shared pointer to collection of hooks libraries.
-typedef boost::shared_ptr<std::vector<std::string> > 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<std::string>& libraries, bool& changed);
+    void getLibraries(isc::hooks::HookLibsCollection& libraries, bool& changed);
 
 private:
-    /// List of hooks libraries.
-    std::vector<std::string> libraries_;
+    /// List of hooks libraries with their configuration parameters
+    isc::hooks::HookLibsCollection libraries_;
 
     /// Indicator flagging that the list of libraries has changed.
     bool changed_;
index 817fa6e02fa981f986d762d265880c33e394d457..3c4e314d15c56e3fbc28ffa7205d1797f6da2823 100644 (file)
@@ -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<string> 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<string> 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<string> libraries;
+        HookLibsCollection libraries;
         HooksManager::loadLibraries(libraries);
 
         // Install a callout: lease4_expire or lease6_expire. Each callout
index f3ae3d75b5236063ca89e5f80b3d2164711b5666..d0142c6d24018481f2324284dda4ff4943a6ca33 100644 (file)
@@ -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<string> 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<string> 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<string> 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<string> libraries; // no libraries at this time
+    HookLibsCollection libraries; // no libraries at this time
     HooksManager::loadLibraries(libraries);
 
     // Install a callout