From a2624b3aed9b85898b545cf5f8fd3f85b3936569 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Mon, 27 Mar 2017 17:40:30 +0200 Subject: [PATCH] [5078] Implemented configUpdate unit test for CA. --- .../agent/tests/ca_controller_unittests.cc | 93 ++++++++++++++++++- .../testutils/test_server_unix_socket.h | 2 +- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/bin/agent/tests/ca_controller_unittests.cc b/src/bin/agent/tests/ca_controller_unittests.cc index 70d3c10adf..58d047a1eb 100644 --- a/src/bin/agent/tests/ca_controller_unittests.cc +++ b/src/bin/agent/tests/ca_controller_unittests.cc @@ -7,11 +7,15 @@ #include #include #include +#include #include #include +#include using namespace isc::agent; +using namespace isc::data; using namespace isc::process; +using namespace boost::posix_time; namespace { @@ -19,7 +23,17 @@ namespace { const char* valid_agent_config = "{" " \"http-host\": \"127.0.0.1\"," - " \"http-port\": 8081" + " \"http-port\": 8081," + " \"control-sockets\": {" + " \"dhcp4-server\": {" + " \"socket-type\": \"unix\"," + " \"socket-name\": \"/first/dhcp4/socket\"" + " }," + " \"dhcp6-server\": {" + " \"socket-type\": \"unix\"," + " \"socket-name\": \"/first/dhcp6/socket\"" + " }" + " }" "}"; /// @brief test fixture class for testing CtrlAgentController class. This @@ -35,6 +49,48 @@ public: : DControllerTest(CtrlAgentController::instance) { } + /// @brief Returns pointer to CtrlAgentProcess instance. + CtrlAgentProcessPtr getCtrlAgentProcess() { + return (boost::dynamic_pointer_cast(getProcess())); + } + + /// @brief Returns pointer to CtrlAgentCfgMgr instance for a process. + CtrlAgentCfgMgrPtr getCtrlAgentCfgMgr() { + CtrlAgentCfgMgrPtr p; + if (getCtrlAgentProcess()) { + p = getCtrlAgentProcess()->getCtrlAgentCfgMgr(); + } + return (p); + } + + /// @brief Returns a pointer to the configuration context. + CtrlAgentCfgContextPtr getCtrlAgentCfgContext() { + CtrlAgentCfgContextPtr p; + if (getCtrlAgentCfgMgr()) { + p = getCtrlAgentCfgMgr()->getCtrlAgentCfgContext(); + } + return (p); + } + + /// @brief Tests that socket info structure contains 'unix' socket-type + /// value and the expected socket-name. + /// + /// @param type Server type. + /// @param exp_socket_name Expected socket name. + void testUnixSocketInfo(const CtrlAgentCfgContext::ServerType& type, + const std::string& exp_socket_name) { + CtrlAgentCfgContextPtr ctx = getCtrlAgentCfgContext(); + ASSERT_TRUE(ctx); + + ConstElementPtr sock_info = ctx->getControlSocketInfo(type); + ASSERT_TRUE(sock_info); + ASSERT_TRUE(sock_info->contains("socket-type")); + EXPECT_EQ("unix", sock_info->get("socket-type")->stringValue()); + ASSERT_TRUE(sock_info->contains("socket-name")); + EXPECT_EQ(exp_socket_name, + sock_info->get("socket-name")->stringValue()); + } + }; // Basic Controller instantiation testing. @@ -142,4 +198,39 @@ TEST_F(CtrlAgentControllerTest, sigtermShutdown) { EXPECT_TRUE(elapsed_time.total_milliseconds() < 300); } +// Tests that the configuration is updated as a result of agent reconfiguration. +TEST_F(CtrlAgentControllerTest, configUpdate) { + const char* second_config = + "{" + " \"http-host\": \"127.0.0.1\"," + " \"http-port\": 8080," + " \"control-sockets\": {" + " \"dhcp4-server\": {" + " \"socket-type\": \"unix\"," + " \"socket-name\": \"/second/dhcp4/socket\"" + " }," + " \"dhcp6-server\": {" + " \"socket-type\": \"unix\"," + " \"socket-name\": \"/second/dhcp6/socket\"" + " }" + " }" + "}"; + + scheduleTimedWrite(second_config, 100); + + TimedSignal sighup(*getIOService(), SIGHUP, 200); + + time_duration elapsed_time; + runWithConfig(valid_agent_config, 500, elapsed_time); + + CtrlAgentCfgContextPtr ctx = getCtrlAgentCfgContext(); + ASSERT_TRUE(ctx); + + EXPECT_EQ("127.0.0.1", ctx->getHttpHost()); + EXPECT_EQ(8080, ctx->getHttpPort()); + + testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4, "/second/dhcp4/socket"); + testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6, "/second/dhcp6/socket"); +} + } diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.h b/src/lib/asiolink/testutils/test_server_unix_socket.h index d659d191a0..1e201b06d6 100644 --- a/src/lib/asiolink/testutils/test_server_unix_socket.h +++ b/src/lib/asiolink/testutils/test_server_unix_socket.h @@ -21,7 +21,7 @@ namespace test { /// @brief Provides unix domain socket functionality for unit tests. class TestServerUnixSocket { -public: +public: /// @brief Constructor. /// -- 2.47.3