|
@@ -14,30 +14,37 @@
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
+#include <config/ccsession.h>
|
|
|
#include <dhcp/dhcp6.h>
|
|
|
#include <dhcp6/ctrl_dhcp6_srv.h>
|
|
|
-#include <config/ccsession.h>
|
|
|
+#include <hooks/hooks_manager.h>
|
|
|
+
|
|
|
+#include "marker_file.h"
|
|
|
+#include "test_libraries.h"
|
|
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
-#include <iostream>
|
|
|
#include <fstream>
|
|
|
+#include <iostream>
|
|
|
#include <sstream>
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
+#include <unistd.h>
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace isc;
|
|
|
-using namespace isc::dhcp;
|
|
|
using namespace isc::asiolink;
|
|
|
-using namespace isc::data;
|
|
|
using namespace isc::config;
|
|
|
+using namespace isc::data;
|
|
|
+using namespace isc::dhcp;
|
|
|
+using namespace isc::dhcp::test;
|
|
|
+using namespace isc::hooks;
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
class NakedControlledDhcpv6Srv: public ControlledDhcpv6Srv {
|
|
|
- // "naked" DHCPv6 server, exposes internal fields
|
|
|
+ // "Naked" DHCPv6 server, exposes internal fields
|
|
|
public:
|
|
|
NakedControlledDhcpv6Srv():ControlledDhcpv6Srv(DHCP6_SERVER_PORT + 10000) { }
|
|
|
};
|
|
@@ -45,10 +52,25 @@ public:
|
|
|
class CtrlDhcpv6SrvTest : public ::testing::Test {
|
|
|
public:
|
|
|
CtrlDhcpv6SrvTest() {
|
|
|
+ reset();
|
|
|
}
|
|
|
|
|
|
~CtrlDhcpv6SrvTest() {
|
|
|
+ reset();
|
|
|
};
|
|
|
+
|
|
|
+ /// @brief Reset hooks data
|
|
|
+ ///
|
|
|
+ /// Resets the data for the hooks-related portion of the test by ensuring
|
|
|
+ /// that no libraries are loaded and that any marker files are deleted.
|
|
|
+ void reset() {
|
|
|
+ // Unload any previously-loaded libraries.
|
|
|
+ HooksManager::unloadLibraries();
|
|
|
+
|
|
|
+ // Get rid of any marker files.
|
|
|
+ static_cast<void>(unlink(LOAD_MARKER_FILE));
|
|
|
+ static_cast<void>(unlink(UNLOAD_MARKER_FILE));
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
TEST_F(CtrlDhcpv6SrvTest, commands) {
|
|
@@ -62,12 +84,12 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
|
|
|
ElementPtr params(new isc::data::MapElement());
|
|
|
int rcode = -1;
|
|
|
|
|
|
- // case 1: send bogus command
|
|
|
+ // Case 1: send bogus command
|
|
|
ConstElementPtr result = ControlledDhcpv6Srv::execDhcpv6ServerCommand("blah", params);
|
|
|
ConstElementPtr comment = parseAnswer(rcode, result);
|
|
|
EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
|
|
|
|
|
|
- // case 2: send shutdown command without any parameters
|
|
|
+ // Case 2: send shutdown command without any parameters
|
|
|
result = ControlledDhcpv6Srv::execDhcpv6ServerCommand("shutdown", params);
|
|
|
comment = parseAnswer(rcode, result);
|
|
|
EXPECT_EQ(0, rcode); // expect success
|
|
@@ -76,10 +98,52 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
|
|
|
ConstElementPtr x(new isc::data::IntElement(pid));
|
|
|
params->set("pid", x);
|
|
|
|
|
|
- // case 3: send shutdown command with 1 parameter: pid
|
|
|
+ // Case 3: send shutdown command with 1 parameter: pid
|
|
|
result = ControlledDhcpv6Srv::execDhcpv6ServerCommand("shutdown", params);
|
|
|
comment = parseAnswer(rcode, result);
|
|
|
EXPECT_EQ(0, rcode); // Expect success
|
|
|
}
|
|
|
|
|
|
-} // end of anonymous namespace
|
|
|
+// Check that the "libreload" command will reload libraries
|
|
|
+
|
|
|
+TEST_F(CtrlDhcpv6SrvTest, libreload) {
|
|
|
+ // Ensure no marker files to start with.
|
|
|
+ ASSERT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE));
|
|
|
+ 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);
|
|
|
+ HooksManager::loadLibraries(libraries);
|
|
|
+
|
|
|
+ // Check they are loaded.
|
|
|
+ std::vector<std::string> loaded_libraries =
|
|
|
+ HooksManager::getLibraryNames();
|
|
|
+ ASSERT_TRUE(libraries == loaded_libraries);
|
|
|
+
|
|
|
+ // ... which also included checking that the marker file created by the
|
|
|
+ // load functions exists.
|
|
|
+ EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"));
|
|
|
+ EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE));
|
|
|
+
|
|
|
+ // Now execute the "libreload" command. This should cause the libraries
|
|
|
+ // to unload and to reload.
|
|
|
+
|
|
|
+ // Use empty parameters list
|
|
|
+ ElementPtr params(new isc::data::MapElement());
|
|
|
+ int rcode = -1;
|
|
|
+
|
|
|
+ ConstElementPtr result =
|
|
|
+ ControlledDhcpv6Srv::execDhcpv6ServerCommand("libreload", params);
|
|
|
+ ConstElementPtr comment = parseAnswer(rcode, result);
|
|
|
+ EXPECT_EQ(0, rcode); // Expect success
|
|
|
+
|
|
|
+ // Check that the libraries have unloaded and reloaded. The libraries are
|
|
|
+ // unloaded in the reverse order to which they are loaded. When they load,
|
|
|
+ // they should append information to the loading marker file.
|
|
|
+ EXPECT_TRUE(checkMarkerFile(UNLOAD_MARKER_FILE, "21"));
|
|
|
+ EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "1212"));
|
|
|
+}
|
|
|
+
|
|
|
+} // End of anonymous namespace
|