mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 13:37:55 +00:00
[#2235] Refactored remaining hooks lib libloadtests
src/hooks/dhcp/flex_option/libloadtests/Makefile.am src/hooks/dhcp/flex_option/libloadtests/load_unload_unittests.cc src/hooks/dhcp/high_availability/libloadtests/Makefile.am src/hooks/dhcp/high_availability/libloadtests/load_unload_unittests.cc src/hooks/dhcp/run_script/libloadtests/Makefile.am src/hooks/dhcp/run_script/libloadtests/load_unload_unittests.cc src/lib/testutils/lib_load_test_fixture.h LibLoadTest added SetUp() and validConfigParams()
This commit is contained in:
committed by
Francis Dupont
parent
9807f740af
commit
088f79c079
@@ -45,6 +45,7 @@ flex_option_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
|
||||
flex_option_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <dhcpsrv/cfgmgr.h>
|
||||
#include <hooks/hooks_manager.h>
|
||||
#include <process/daemon.h>
|
||||
#include <testutils/lib_load_test_fixture.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <errno.h>
|
||||
@@ -30,124 +31,46 @@ using namespace isc::process;
|
||||
namespace {
|
||||
|
||||
/// @brief Test fixture for testing loading and unloading the flex-option library
|
||||
class LibLoadTest : public ::testing::Test {
|
||||
class FlexOptionLibLoadTest : public isc::test::LibLoadTest {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
LibLoadTest() {
|
||||
reset();
|
||||
FlexOptionLibLoadTest() : LibLoadTest(FLEX_OPTION_LIB_SO) {
|
||||
}
|
||||
|
||||
/// @brief Destructor
|
||||
/// Removes files that may be left over from previous tests
|
||||
virtual ~LibLoadTest() {
|
||||
reset();
|
||||
virtual ~FlexOptionLibLoadTest() {
|
||||
}
|
||||
|
||||
/// @brief Removes files that may be left over from previous tests
|
||||
virtual void reset() {
|
||||
HooksManager::unloadLibraries();
|
||||
/// @brief Creates a set configuration parameters valid for the library.
|
||||
virtual ElementPtr validConfigParams() {
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
return (params);
|
||||
}
|
||||
|
||||
void addLib(const std::string& lib, ConstElementPtr params) {
|
||||
libraries_.push_back(make_pair(lib, params));
|
||||
}
|
||||
|
||||
bool loadLibs() {
|
||||
return (HooksManager::loadLibraries(libraries_));
|
||||
}
|
||||
|
||||
void unloadLibs() {
|
||||
EXPECT_NO_THROW(HooksManager::unloadLibraries());
|
||||
}
|
||||
|
||||
HookLibsCollection libraries_;
|
||||
};
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp4) {
|
||||
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(FLEX_OPTION_LIB_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
// Simple V4 test that checks the library can be loaded and unloaded several times.
|
||||
TEST_F(FlexOptionLibLoadTest, validLoadDhcp4) {
|
||||
validDaemonTest("kea-dhcp4", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp6) {
|
||||
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(FLEX_OPTION_LIB_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
TEST_F(FlexOptionLibLoadTest, validLoadDhcp6) {
|
||||
validDaemonTest("kea-dhcp6", AF_INET6, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server
|
||||
// only if it is set for IPv4.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp4) {
|
||||
// Simple test that checks the library cannot by loaded by invalid daemons.
|
||||
TEST_F(FlexOptionLibLoadTest, invalidDaemonLoad) {
|
||||
// V4 is invalid when family is AF_INET6
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET6, valid_params_);
|
||||
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
// V6 is invalid when family is AF_INET
|
||||
invalidDaemonTest("kea-dhcp6", AF_INET, valid_params_);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(FLEX_OPTION_LIB_SO, params);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server
|
||||
// only if it is set for IPv6.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp6) {
|
||||
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(FLEX_OPTION_LIB_SO, params);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded and unloaded several times.
|
||||
TEST_F(LibLoadTest, validLoad) {
|
||||
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr options = Element::createList();
|
||||
params->set("options", options);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(FLEX_OPTION_LIB_SO, params);
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
invalidDaemonTest("kea-ctrl-agent", AF_INET, valid_params_);
|
||||
invalidDaemonTest("kea-dhcp-ddns", AF_INET, valid_params_);
|
||||
invalidDaemonTest("bogus", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
@@ -45,6 +45,7 @@ ha_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
|
||||
ha_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2019-2022 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/cfgmgr.h>
|
||||
#include <hooks/hooks_manager.h>
|
||||
#include <process/daemon.h>
|
||||
#include <testutils/lib_load_test_fixture.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <errno.h>
|
||||
@@ -30,187 +31,79 @@ using namespace isc::process;
|
||||
namespace {
|
||||
|
||||
/// @brief Test fixture for testing loading and unloading the HA library
|
||||
class LibLoadTest : public ::testing::Test {
|
||||
class HALibLoadTest : public isc::test::LibLoadTest {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
LibLoadTest() {
|
||||
reset();
|
||||
HALibLoadTest() : LibLoadTest(LIBDHCP_HA_SO) {
|
||||
}
|
||||
|
||||
/// @brief Destructor
|
||||
/// Removes files that may be left over from previous tests
|
||||
virtual ~LibLoadTest() {
|
||||
reset();
|
||||
virtual ~HALibLoadTest() {
|
||||
}
|
||||
|
||||
/// @brief Removes files that may be left over from previous tests
|
||||
virtual void reset() {
|
||||
HooksManager::unloadLibraries();
|
||||
/// @brief Creates valid HA configuration with three servers.
|
||||
virtual ElementPtr validConfigParams() {
|
||||
std::string config_text =
|
||||
"["
|
||||
" {"
|
||||
" \"this-server-name\": \"server1\","
|
||||
" \"mode\": \"hot-standby\","
|
||||
" \"sync-page-limit\": 3,"
|
||||
" \"heartbeat-delay\": 1000,"
|
||||
" \"max-response-delay\": 1000,"
|
||||
" \"max-ack-delay\": 10000,"
|
||||
" \"max-unacked-clients\": 10,"
|
||||
" \"peers\": ["
|
||||
" {"
|
||||
" \"name\": \"server1\","
|
||||
" \"url\": \"http://127.0.0.1:18123/\","
|
||||
" \"role\": \"primary\","
|
||||
" \"auto-failover\": true"
|
||||
" },"
|
||||
" {"
|
||||
" \"name\": \"server2\","
|
||||
" \"url\": \"http://127.0.0.1:18124/\","
|
||||
" \"role\": \"standby\","
|
||||
" \"auto-failover\": true"
|
||||
" },"
|
||||
" {"
|
||||
" \"name\": \"server3\","
|
||||
" \"url\": \"http://127.0.0.1:18125/\","
|
||||
" \"role\": \"backup\","
|
||||
" \"auto-failover\": false"
|
||||
" }"
|
||||
" ]"
|
||||
" }"
|
||||
"]";
|
||||
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", Element::fromJSON(config_text));
|
||||
return (params);
|
||||
}
|
||||
|
||||
/// @brief Adds library/parameters to list of libraries to be loaded
|
||||
void addLib(const std::string& lib, ConstElementPtr params) {
|
||||
libraries_.push_back(make_pair(lib, params));
|
||||
}
|
||||
|
||||
/// @brief Load all specified libraries.
|
||||
///
|
||||
/// The libraries are stored in libraries_
|
||||
bool loadLibs() {
|
||||
return (HooksManager::loadLibraries(libraries_));
|
||||
}
|
||||
|
||||
/// @brief Unloads all libraries.
|
||||
void unloadLibs() {
|
||||
EXPECT_NO_THROW(HooksManager::unloadLibraries());
|
||||
}
|
||||
|
||||
/// @brief Return HA configuration with three servers in JSON format.
|
||||
ConstElementPtr createValidJsonConfiguration() const;
|
||||
|
||||
HookLibsCollection libraries_;
|
||||
};
|
||||
|
||||
ConstElementPtr
|
||||
LibLoadTest::createValidJsonConfiguration() const {
|
||||
std::string config_text =
|
||||
"["
|
||||
" {"
|
||||
" \"this-server-name\": \"server1\","
|
||||
" \"mode\": \"hot-standby\","
|
||||
" \"sync-page-limit\": 3,"
|
||||
" \"heartbeat-delay\": 1000,"
|
||||
" \"max-response-delay\": 1000,"
|
||||
" \"max-ack-delay\": 10000,"
|
||||
" \"max-unacked-clients\": 10,"
|
||||
" \"peers\": ["
|
||||
" {"
|
||||
" \"name\": \"server1\","
|
||||
" \"url\": \"http://127.0.0.1:18123/\","
|
||||
" \"role\": \"primary\","
|
||||
" \"auto-failover\": true"
|
||||
" },"
|
||||
" {"
|
||||
" \"name\": \"server2\","
|
||||
" \"url\": \"http://127.0.0.1:18124/\","
|
||||
" \"role\": \"standby\","
|
||||
" \"auto-failover\": true"
|
||||
" },"
|
||||
" {"
|
||||
" \"name\": \"server3\","
|
||||
" \"url\": \"http://127.0.0.1:18125/\","
|
||||
" \"role\": \"backup\","
|
||||
" \"auto-failover\": false"
|
||||
" }"
|
||||
" ]"
|
||||
" }"
|
||||
"]";
|
||||
|
||||
return (Element::fromJSON(config_text));
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp4) {
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
// Simple V4 test that checks the library can be loaded and unloaded several times.
|
||||
TEST_F(HALibLoadTest, validLoadDhcp4) {
|
||||
validDaemonTest("kea-dhcp4", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp6) {
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
TEST_F(HALibLoadTest, validLoadDhcp6) {
|
||||
validDaemonTest("kea-dhcp6", AF_INET6, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server
|
||||
// only if it is set for IPv4.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp4) {
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
// Simple test that checks the library cannot by loaded by invalid daemons.
|
||||
TEST_F(HALibLoadTest, invalidDaemonLoad) {
|
||||
// V4 is invalid when family is AF_INET6
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET6, valid_params_);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
// V6 is invalid when family is AF_INET
|
||||
invalidDaemonTest("kea-dhcp6", AF_INET, valid_params_);
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
|
||||
// The process name must be kea-dhcp4 so load shall fail.
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server
|
||||
// only if it is set for IPv6.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp6) {
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
|
||||
// The process name must be kea-dhcp6 so load shall fail.
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded and unloaded several times
|
||||
// in a DHCPv4 server.
|
||||
TEST_F(LibLoadTest, validLoadsDhcp4) {
|
||||
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded and unloaded several times
|
||||
// in a DHCPv6 server.
|
||||
TEST_F(LibLoadTest, validLoadsDhcp6) {
|
||||
|
||||
// Prepare parameters,
|
||||
ElementPtr params = Element::createMap();
|
||||
params->set("high-availability", createValidJsonConfiguration());
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(LIBDHCP_HA_SO, params);
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
unloadLibs();
|
||||
invalidDaemonTest("kea-ctrl-agent", AF_INET, valid_params_);
|
||||
invalidDaemonTest("kea-dhcp-ddns", AF_INET, valid_params_);
|
||||
invalidDaemonTest("bogus", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
@@ -45,6 +45,7 @@ run_script_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
|
||||
run_script_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <dhcpsrv/cfgmgr.h>
|
||||
#include <hooks/hooks_manager.h>
|
||||
#include <process/daemon.h>
|
||||
#include <testutils/lib_load_test_fixture.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <errno.h>
|
||||
@@ -30,174 +31,73 @@ using namespace std;
|
||||
namespace {
|
||||
|
||||
/// @brief Test fixture for testing loading and unloading the RunScript library.
|
||||
class LibLoadTest : public ::testing::Test {
|
||||
class RunScriptLibLoadTest : public isc::test::LibLoadTest {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
LibLoadTest() {
|
||||
reset();
|
||||
RunScriptLibLoadTest() : LibLoadTest(LIBRUN_SCRIPT_SO) {
|
||||
}
|
||||
|
||||
/// @brief Destructor
|
||||
///
|
||||
/// Removes files that may be left over from previous tests
|
||||
virtual ~LibLoadTest() {
|
||||
reset();
|
||||
virtual ~RunScriptLibLoadTest() {
|
||||
}
|
||||
|
||||
/// @brief Removes files that may be left over from previous tests
|
||||
virtual void reset() {
|
||||
HooksManager::unloadLibraries();
|
||||
/// @brief Creates a set configuration parameters valid for the library.
|
||||
virtual ElementPtr validConfigParams() {
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
return (params);
|
||||
}
|
||||
|
||||
/// @brief Add library to the collection of tested libraries.
|
||||
///
|
||||
/// @param lib The name of the lib added.
|
||||
/// @param params The parameters of the library.
|
||||
void addLib(const string& lib, ConstElementPtr params) {
|
||||
libraries_.push_back(make_pair(lib, params));
|
||||
}
|
||||
|
||||
/// @brief Load libraries.
|
||||
///
|
||||
/// @return True if loading succeeded, false otherwise.
|
||||
bool loadLibs() {
|
||||
return (HooksManager::loadLibraries(libraries_));
|
||||
}
|
||||
|
||||
/// @brief Unload libraries.
|
||||
///
|
||||
/// @return True if unloading succeeded, false otherwise.
|
||||
bool unloadLibs() {
|
||||
return (HooksManager::unloadLibraries());
|
||||
}
|
||||
|
||||
/// @brief The collection of libraries to be loaded.
|
||||
HookLibsCollection libraries_;
|
||||
};
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp4) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
// Simple V4 test that checks the library can be loaded and unloaded several times.
|
||||
TEST_F(RunScriptLibLoadTest, validLoadDhcp4) {
|
||||
validDaemonTest("kea-dhcp4", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server.
|
||||
TEST_F(LibLoadTest, validLoadDhcp6) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
EXPECT_TRUE(loadLibs());
|
||||
TEST_F(RunScriptLibLoadTest, validLoadDhcp6) {
|
||||
validDaemonTest("kea-dhcp6", AF_INET6, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv4 server
|
||||
// only if it is set for IPv4.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp4) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
// Simple test that checks the library cannot by loaded by invalid daemons.
|
||||
TEST_F(RunScriptLibLoadTest, invalidDaemonLoad) {
|
||||
// V4 is invalid when family is AF_INET6
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET6, valid_params_);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET6);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
// V6 is invalid when family is AF_INET
|
||||
invalidDaemonTest("kea-dhcp6", AF_INET, valid_params_);
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded in a DHCPv6 server
|
||||
// only if it is set for IPv6.
|
||||
TEST_F(LibLoadTest, invalidLoadDhcp6) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp6");
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
}
|
||||
|
||||
// Simple test that checks the library can be loaded and unloaded several times.
|
||||
TEST_F(LibLoadTest, validLoad) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
ElementPtr params = Element::createMap();
|
||||
ElementPtr name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create(false);
|
||||
params->set("sync", sync);
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
EXPECT_NO_THROW(unloadLibs());
|
||||
|
||||
EXPECT_TRUE(loadLibs());
|
||||
EXPECT_NO_THROW(unloadLibs());
|
||||
invalidDaemonTest("kea-ctrl-agent", AF_INET, valid_params_);
|
||||
invalidDaemonTest("kea-dhcp-ddns", AF_INET, valid_params_);
|
||||
invalidDaemonTest("bogus", AF_INET, valid_params_);
|
||||
}
|
||||
|
||||
// Simple test that checks the library can not be loaded if using wrong
|
||||
// parameters.
|
||||
TEST_F(LibLoadTest, invalidLoad) {
|
||||
// Prepare parameters for the callout parameters library.
|
||||
TEST_F(RunScriptLibLoadTest, invalidParametersLoad) {
|
||||
// The name parameter should be mandatory.
|
||||
ElementPtr params = Element::createMap();
|
||||
|
||||
// Set family and proc name.
|
||||
CfgMgr::instance().setFamily(AF_INET);
|
||||
Daemon::setProcName("kea-dhcp4");
|
||||
|
||||
addLib(LIBRUN_SCRIPT_SO, params);
|
||||
|
||||
// The name parameter is mandatory.
|
||||
EXPECT_FALSE(loadLibs());
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET, params);
|
||||
|
||||
// Use invalid name parameter type.
|
||||
ElementPtr name = Element::create(false);
|
||||
params->set("name", name);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET, params);
|
||||
|
||||
// Use invalid name parameter.
|
||||
name = Element::create("script_name.sh");
|
||||
params->set("name", name);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET, params);
|
||||
|
||||
// Use valid name parameter type but use invalid sync parameter type.
|
||||
name = Element::create(RUN_SCRIPT_TEST_SH);
|
||||
params->set("name", name);
|
||||
ElementPtr sync = Element::create("data");
|
||||
params->set("sync", sync);
|
||||
EXPECT_FALSE(loadLibs());
|
||||
invalidDaemonTest("kea-dhcp4", AF_INET, params);
|
||||
}
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
@@ -27,6 +27,10 @@ public:
|
||||
unloadLibraries();
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
valid_params_ = validConfigParams();
|
||||
}
|
||||
|
||||
/// @brief Destructor. Unloads any previously loaded libraries.
|
||||
~LibLoadTest() {
|
||||
unloadLibraries();
|
||||
@@ -91,11 +95,19 @@ public:
|
||||
uint16_t family = AF_INET,
|
||||
const isc::data::ElementPtr& params = isc::data::ElementPtr());
|
||||
|
||||
/// @brief Creates a set configuration parameters valid for the library.
|
||||
virtual isc::data::ElementPtr validConfigParams() {
|
||||
return (isc::data::Element::createMap());
|
||||
}
|
||||
|
||||
/// @brief full pathname to the library so file under test;
|
||||
std::string lib_so_name_;
|
||||
|
||||
/// @brief Libraries
|
||||
isc::hooks::HookLibsCollection libraries_;
|
||||
|
||||
/// @brief Contains a set configuration parameters valid for the library.
|
||||
isc::data::ElementPtr valid_params_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
Reference in New Issue
Block a user