Commit e10309c7 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[4297] Unit-tests updated after recent API change.

parent 629dee19
......@@ -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);
......
// 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
......
......@@ -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);
......
// 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
......
# 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
// 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_;
......
// 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_;
......
// 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
......
// 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment