Browse Source

[5190] Replace CA ServerType with service name.

Marcin Siodelski 8 years ago
parent
commit
c2b46cb684

+ 27 - 63
src/bin/agent/ca_cfg_mgr.cc

@@ -24,30 +24,9 @@ CtrlAgentCfgContext::CtrlAgentCfgContext()
 }
 
 CtrlAgentCfgContext::CtrlAgentCfgContext(const CtrlAgentCfgContext& orig)
-    : DCfgContextBase(),http_host_(orig.http_host_), http_port_(orig.http_port_),
+    : DCfgContextBase(), ctrl_sockets_(orig.ctrl_sockets_),
+      http_host_(orig.http_host_), http_port_(orig.http_port_),
       hooks_config_(orig.hooks_config_) {
-
-    // We're copying pointers here only. The underlying data will be shared by
-    // old and new context. That's how shared pointers work and I see no reason
-    // why it would be different in this particular here.
-    ctrl_sockets_[TYPE_D2] = orig.ctrl_sockets_[TYPE_D2];
-    ctrl_sockets_[TYPE_DHCP4] = orig.ctrl_sockets_[TYPE_DHCP4];
-    ctrl_sockets_[TYPE_DHCP6] = orig.ctrl_sockets_[TYPE_DHCP6];
-}
-
-CtrlAgentCfgContext::ServerType
-CtrlAgentCfgContext::toServerType(const std::string& service) {
-    if (service == "dhcp4") {
-        return (CtrlAgentCfgContext::TYPE_DHCP4);
-
-    } else if (service == "dhcp6") {
-        return (CtrlAgentCfgContext::TYPE_DHCP6);
-
-    } else if (service == "d2") {
-        return (CtrlAgentCfgContext::TYPE_D2);
-    }
-
-    isc_throw(isc::BadValue, "invalid service value " << service);
 }
 
 CtrlAgentCfgMgr::CtrlAgentCfgMgr()
@@ -68,25 +47,7 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) {
       << ctx->getHttpPort() << ", control sockets: ";
 
     // Then print the control-sockets
-    bool socks = false;
-    if (ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2)) {
-        s << "d2 ";
-        socks = true;
-    }
-    if (ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4)) {
-        s << "dhcp4 ";
-        socks = true;
-    }
-    if (ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6)) {
-        s << "dhcp6 ";
-        socks = true;
-    }
-    if (!socks) {
-        // That's uncommon, but correct scenario. CA can respond to some
-        // commands on its own. Further down the road we will possibly get the
-        // capability to tell CA to start other servers.
-        s << "none";
-    }
+    s << ctx->getControlSocketInfoSummary();
 
     // Finally, print the hook libraries names
     const isc::hooks::HookLibsCollection libs = ctx->getHooksConfig().get();
@@ -156,21 +117,33 @@ CtrlAgentCfgMgr::parse(isc::data::ConstElementPtr config_set, bool check_only) {
     return (answer);
 }
 
-const data::ConstElementPtr
-CtrlAgentCfgContext::getControlSocketInfo(ServerType type) const {
-    if (type > MAX_TYPE_SUPPORTED) {
-        isc_throw(BadValue, "Invalid server type");
-    }
-    return (ctrl_sockets_[static_cast<uint8_t>(type)]);
+data::ConstElementPtr
+CtrlAgentCfgContext::getControlSocketInfo(const std::string& service) const {
+    auto si = ctrl_sockets_.find(service);
+    return ((si != ctrl_sockets_.end()) ? si->second : ConstElementPtr());
 }
 
 void
 CtrlAgentCfgContext::setControlSocketInfo(const isc::data::ConstElementPtr& control_socket,
-                                          ServerType type) {
-    if (type > MAX_TYPE_SUPPORTED) {
-        isc_throw(BadValue, "Invalid server type");
+                                          const std::string& service) {
+    ctrl_sockets_[service] = control_socket;
+}
+
+std::string
+CtrlAgentCfgContext::getControlSocketInfoSummary() const {
+    std::ostringstream s;
+    for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.end(); ++si) {
+        if (s.tellp() != 0) {
+            s << " ";
+        }
+        s << si->first;
+    }
+
+    if (s.tellp() == 0) {
+        s << "none";
     }
-    ctrl_sockets_[static_cast<uint8_t>(type)] = control_socket;
+
+    return (s.str());
 }
 
 ElementPtr
@@ -184,17 +157,8 @@ CtrlAgentCfgContext::toElement() const {
     ca->set("hooks-libraries", hooks_config_.toElement());
     // Set control-sockets
     ElementPtr control_sockets = Element::createMap();
-    // Set dhcp4 server socket
-    if (ctrl_sockets_[TYPE_DHCP4]) {
-        control_sockets->set("dhcp4", ctrl_sockets_[TYPE_DHCP4]);
-    }
-    // Set dhcp6 server socket
-    if (ctrl_sockets_[TYPE_DHCP6]) {
-        control_sockets->set("dhcp6", ctrl_sockets_[TYPE_DHCP6]);
-    }
-    // Set d2 server socket
-    if (ctrl_sockets_[TYPE_D2]) {
-        control_sockets->set("d2", ctrl_sockets_[TYPE_D2]);
+    for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.cend(); ++si) {
+        control_sockets->set(si->first, si->second);
     }
     ca->set("control-sockets", control_sockets);
     // Set Control-agent

+ 10 - 20
src/bin/agent/ca_cfg_mgr.h

@@ -11,6 +11,7 @@
 #include <hooks/hooks_config.h>
 #include <process/d_cfg_mgr.h>
 #include <boost/pointer_cast.hpp>
+#include <map>
 #include <string>
 
 namespace isc {
@@ -33,21 +34,6 @@ public:
     /// @brief Default constructor
     CtrlAgentCfgContext();
 
-    /// @brief Specifies type of the server being controlled.
-    enum ServerType {
-        TYPE_DHCP4 = 0, ///< kea-dhcp4
-        TYPE_DHCP6 = 1, ///< kea-dhcp6
-        TYPE_D2 = 2     ///< kea-dhcp-ddns
-    };
-
-    /// @brief Used check that specified ServerType is within valid range.
-    static const uint32_t MAX_TYPE_SUPPORTED = TYPE_D2;
-
-    /// @brief Converts service specified as a string to ServerType.
-    ///
-    /// @param service Service value as a string: 'dhcp4', 'dhcp6', 'd2'.
-    static ServerType toServerType(const std::string& service);
-
     /// @brief Creates a clone of this context object.
     ///
     /// Note this method does not do deep copy the information about control sockets.
@@ -65,9 +51,10 @@ public:
     /// server type). This information is expected to be compatible with
     /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
     ///
-    /// @param type type of the server being controlled
+    /// @param service server being controlled
     /// @return pointer to the Element that holds control-socket map (or NULL)
-    const isc::data::ConstElementPtr getControlSocketInfo(ServerType type) const;
+    isc::data::ConstElementPtr
+    getControlSocketInfo(const std::string& service) const;
 
     /// @brief Sets information about the control socket
     ///
@@ -76,9 +63,12 @@ public:
     /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
     ///
     /// @param control_socket Element that holds control-socket map
-    /// @param type type of the server being controlled
+    /// @param service server being controlled
     void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket,
-                              ServerType type);
+                              const std::string& service);
+
+    /// @brief Returns socket configuration summary in a textual format.
+    std::string getControlSocketInfoSummary() const;
 
     /// @brief Sets http-host parameter
     ///
@@ -149,7 +139,7 @@ private:
     CtrlAgentCfgContext& operator=(const CtrlAgentCfgContext& rhs);
 
     /// Socket information will be stored here (for all supported servers)
-    isc::data::ConstElementPtr ctrl_sockets_[MAX_TYPE_SUPPORTED + 1];
+    std::map<std::string, isc::data::ConstElementPtr> ctrl_sockets_;
 
     /// Hostname the CA should listen on.
     std::string http_host_;

+ 1 - 12
src/bin/agent/ca_command_mgr.cc

@@ -161,21 +161,10 @@ CtrlAgentCommandMgr::forwardCommand(const std::string& service,
                   " Control Agent configuration information");
     }
 
-    // Convert the service to the server type values. Make sure the client
-    // provided right value.
-    CtrlAgentCfgContext::ServerType server_type;
-    try {
-        server_type = CtrlAgentCfgContext::toServerType(service);
-
-    } catch (const std::exception& ex) {
-        // Invalid value in service list. Can't proceed.
-        isc_throw(CommandForwardingError, ex.what());
-    }
-
     // Now that we know what service it should be forwarded to, we should
     // find a matching forwarding socket. If this socket is not configured,
     // we have to communicate it to the client.
-    ConstElementPtr socket_info = ctx->getControlSocketInfo(server_type);
+    ConstElementPtr socket_info = ctx->getControlSocketInfo(service);
     if (!socket_info) {
         isc_throw(CommandForwardingError, "forwarding socket is not configured"
                   " for the server type " << service);

+ 3 - 14
src/bin/agent/simple_parser.cc

@@ -89,20 +89,9 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
     // Control sockets are second.
     ConstElementPtr ctrl_sockets = config->get("control-sockets");
     if (ctrl_sockets) {
-        ConstElementPtr d2_socket = ctrl_sockets->get("d2");
-        ConstElementPtr d4_socket = ctrl_sockets->get("dhcp4");
-        ConstElementPtr d6_socket = ctrl_sockets->get("dhcp6");
-
-        if (d2_socket) {
-            ctx->setControlSocketInfo(d2_socket, CtrlAgentCfgContext::TYPE_D2);
-        }
-
-        if (d4_socket) {
-            ctx->setControlSocketInfo(d4_socket, CtrlAgentCfgContext::TYPE_DHCP4);
-        }
-
-        if (d6_socket) {
-            ctx->setControlSocketInfo(d6_socket, CtrlAgentCfgContext::TYPE_DHCP6);
+        auto sockets_map = ctrl_sockets->mapValue();
+        for (auto cs = sockets_map.cbegin(); cs != sockets_map.cend(); ++cs) {
+            ctx->setControlSocketInfo(cs->second, cs->first);
         }
     }
 

+ 36 - 48
src/bin/agent/tests/ca_cfg_mgr_unittests.cc

@@ -28,18 +28,6 @@ public:
     using CtrlAgentCfgMgr::parse;
 };
 
-// Tests conversion of the 'service' parameter to ServerType.
-TEST(CtrlAgentCfgContextTest, toServerType) {
-    EXPECT_EQ(CtrlAgentCfgContext::TYPE_DHCP4,
-              CtrlAgentCfgContext::toServerType("dhcp4"));
-    EXPECT_EQ(CtrlAgentCfgContext::TYPE_DHCP6,
-              CtrlAgentCfgContext::toServerType("dhcp6"));
-    EXPECT_EQ(CtrlAgentCfgContext::TYPE_D2,
-              CtrlAgentCfgContext::toServerType("d2"));
-    EXPECT_THROW(CtrlAgentCfgContext::toServerType("other"),
-                 isc::BadValue);
-}
-
 // Tests construction of CtrlAgentCfgMgr class.
 TEST(CtrlAgentCfgMgr, construction) {
     boost::scoped_ptr<CtrlAgentCfgMgr> cfg_mgr;
@@ -84,9 +72,9 @@ TEST(CtrlAgentCfgMgr, contextSocketInfo) {
 
     // Check control socket parameters
     // By default, there are no control sockets stored.
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
+    EXPECT_FALSE(ctx.getControlSocketInfo("d2"));
+    EXPECT_FALSE(ctx.getControlSocketInfo("dhcp4"));
+    EXPECT_FALSE(ctx.getControlSocketInfo("dhcp6"));
 
     ConstElementPtr socket1 = Element::fromJSON("{ \"socket-type\": \"unix\",\n"
                                                 "  \"socket-name\": \"socket1\" }");
@@ -95,26 +83,26 @@ TEST(CtrlAgentCfgMgr, contextSocketInfo) {
     ConstElementPtr socket3 = Element::fromJSON("{ \"socket-type\": \"unix\",\n"
                                                 "  \"socket-name\": \"socket3\" }");
     // Ok, now set the control socket for D2
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket1, CtrlAgentCfgContext::TYPE_D2));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket1, "d2"));
 
     // Now check the values returned
-    EXPECT_EQ(socket1, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
+    EXPECT_EQ(socket1, ctx.getControlSocketInfo("d2"));
+    EXPECT_FALSE(ctx.getControlSocketInfo("dhcp4"));
+    EXPECT_FALSE(ctx.getControlSocketInfo("dhcp6"));
 
     // Now set the v6 socket and sanity check again
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket2, CtrlAgentCfgContext::TYPE_DHCP6));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket2, "dhcp6"));
 
     // Should be possible to retrieve two sockets.
-    EXPECT_EQ(socket1, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
-    EXPECT_EQ(socket2, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
-    EXPECT_FALSE(ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
+    EXPECT_EQ(socket1, ctx.getControlSocketInfo("d2"));
+    EXPECT_EQ(socket2, ctx.getControlSocketInfo("dhcp6"));
+    EXPECT_FALSE(ctx.getControlSocketInfo("dhcp4"));
 
     // Finally, set the third control socket.
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket3, CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_EQ(socket1, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
-    EXPECT_EQ(socket2, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
-    EXPECT_EQ(socket3, ctx.getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket3, "dhcp4"));
+    EXPECT_EQ(socket1, ctx.getControlSocketInfo("d2"));
+    EXPECT_EQ(socket2, ctx.getControlSocketInfo("dhcp6"));
+    EXPECT_EQ(socket3, ctx.getControlSocketInfo("dhcp4"));
 }
 
 // Tests if copied context retains all parameters.
@@ -129,9 +117,9 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
     ConstElementPtr socket3 = Element::fromJSON("{ \"socket-type\": \"unix\",\n"
                                                 "  \"socket-name\": \"socket3\" }");
     // Ok, now set the control sockets
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket1, CtrlAgentCfgContext::TYPE_D2));
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket2, CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket3, CtrlAgentCfgContext::TYPE_DHCP6));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket1, "d2"));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket2, "dhcp4"));
+    EXPECT_NO_THROW(ctx.setControlSocketInfo(socket3, "dhcp6"));
 
     EXPECT_NO_THROW(ctx.setHttpPort(12345));
     EXPECT_NO_THROW(ctx.setHttpHost("bellatrix"));
@@ -151,12 +139,12 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
     EXPECT_EQ("bellatrix", copy->getHttpHost());
 
     // Check socket info
-    ASSERT_TRUE(copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
-    ASSERT_TRUE(copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
-    ASSERT_TRUE(copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
-    EXPECT_EQ(socket1->str(), copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2)->str());
-    EXPECT_EQ(socket2->str(), copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4)->str());
-    EXPECT_EQ(socket3->str(), copy->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6)->str());
+    ASSERT_TRUE(copy->getControlSocketInfo("d2"));
+    ASSERT_TRUE(copy->getControlSocketInfo("dhcp4"));
+    ASSERT_TRUE(copy->getControlSocketInfo("dhcp6"));
+    EXPECT_EQ(socket1->str(), copy->getControlSocketInfo("d2")->str());
+    EXPECT_EQ(socket2->str(), copy->getControlSocketInfo("dhcp4")->str());
+    EXPECT_EQ(socket3->str(), copy->getControlSocketInfo("dhcp6")->str());
 
     // Check hook libs
     const HookLibsCollection& libs2 = copy->getHooksConfig().get();
@@ -327,12 +315,12 @@ TEST_F(AgentParserTest, configParseSocketDhcp4) {
 
     CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext();
     ASSERT_TRUE(ctx);
-    ConstElementPtr socket = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4);
+    ConstElementPtr socket = ctx->getControlSocketInfo("dhcp4");
     ASSERT_TRUE(socket);
     EXPECT_EQ("{ \"socket-name\": \"/tmp/socket-v4\", \"socket-type\": \"unix\" }",
               socket->str());
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
+    EXPECT_FALSE(ctx->getControlSocketInfo("dhcp6"));
+    EXPECT_FALSE(ctx->getControlSocketInfo("d2"));
 }
 
 // Tests if a single socket can be configured. BTW this test also checks
@@ -343,13 +331,13 @@ TEST_F(AgentParserTest, configParseSocketD2) {
 
     CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext();
     ASSERT_TRUE(ctx);
-    ConstElementPtr socket = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2);
+    ConstElementPtr socket = ctx->getControlSocketInfo("d2");
     ASSERT_TRUE(socket);
     EXPECT_EQ("{ \"socket-name\": \"/tmp/socket-d2\", \"socket-type\": \"unix\" }",
               socket->str());
 
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6));
+    EXPECT_FALSE(ctx->getControlSocketInfo("dhcp4"));
+    EXPECT_FALSE(ctx->getControlSocketInfo("dhcp6"));
 }
 
 // Tests if a single socket can be configured. BTW this test also checks
@@ -360,12 +348,12 @@ TEST_F(AgentParserTest, configParseSocketDhcp6) {
 
     CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext();
     ASSERT_TRUE(ctx);
-    ConstElementPtr socket = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6);
+    ConstElementPtr socket = ctx->getControlSocketInfo("dhcp6");
     ASSERT_TRUE(socket);
     EXPECT_EQ("{ \"socket-name\": \"/tmp/socket-v6\", \"socket-type\": \"unix\" }",
               socket->str());
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4));
-    EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2));
+    EXPECT_FALSE(ctx->getControlSocketInfo("dhcp4"));
+    EXPECT_FALSE(ctx->getControlSocketInfo("d2"));
 }
 
 // This tests if all 3 sockets can be configured and makes sure the parser
@@ -374,9 +362,9 @@ TEST_F(AgentParserTest, configParse3Sockets) {
     configParse(AGENT_CONFIGS[3], 0);
     CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext();
     ASSERT_TRUE(ctx);
-    ConstElementPtr socket2 = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2);
-    ConstElementPtr socket4 = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4);
-    ConstElementPtr socket6 = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6);
+    ConstElementPtr socket2 = ctx->getControlSocketInfo("d2");
+    ConstElementPtr socket4 = ctx->getControlSocketInfo("dhcp4");
+    ConstElementPtr socket6 = ctx->getControlSocketInfo("dhcp6");
     ASSERT_TRUE(socket2);
     EXPECT_EQ("{ \"socket-name\": \"/tmp/socket-d2\", \"socket-type\": \"unix\" }",
               socket2->str());

+ 15 - 20
src/bin/agent/tests/ca_command_mgr_unittests.cc

@@ -154,17 +154,16 @@ public:
 
     /// @brief Adds configuration of the control socket.
     ///
-    /// @param server_type Server type for which socket configuration is to
-    /// be added.
+    /// @param service Service for which socket configuration is to be added.
     void
-    configureControlSocket(const CtrlAgentCfgContext::ServerType& server_type) {
+    configureControlSocket(const std::string& service) {
         CtrlAgentCfgContextPtr ctx = getCtrlAgentCfgContext();
         ASSERT_TRUE(ctx);
 
         ElementPtr control_socket = Element::createMap();
         control_socket->set("socket-name",
                             Element::create(unixSocketFilePath()));
-        ctx->setControlSocketInfo(control_socket, server_type);
+        ctx->setControlSocketInfo(control_socket, service);
     }
 
     /// @brief Create and bind server side socket.
@@ -214,7 +213,7 @@ public:
     /// server socket after which the IO service should be stopped.
     /// @param expected_responses Number of responses after which the test finishes.
     /// @param server_response Stub response to be sent by the server.
-    void testForward(const CtrlAgentCfgContext::ServerType& server_type,
+    void testForward(const std::string& configured_service,
                      const std::string& service,
                      const int expected_result0,
                      const int expected_result1 = -1,
@@ -222,7 +221,7 @@ public:
                      const size_t expected_responses = 1,
                      const std::string& server_response = "{ \"result\": 0 }") {
         // Configure client side socket.
-        configureControlSocket(server_type);
+        configureControlSocket(configured_service);
         // Create server side socket.
         bindServerSocket(server_response);
 
@@ -289,37 +288,33 @@ TEST_F(CtrlAgentCommandMgrTest, listCommands) {
 
 /// Check that control command is successfully forwarded to the DHCPv4 server.
 TEST_F(CtrlAgentCommandMgrTest, forwardToDHCPv4Server) {
-    testForward(CtrlAgentCfgContext::TYPE_DHCP4, "dhcp4",
-                isc::config::CONTROL_RESULT_SUCCESS);
+    testForward("dhcp4", "dhcp4", isc::config::CONTROL_RESULT_SUCCESS);
 }
 
 /// Check that control command is successfully forwarded to the DHCPv6 server.
 TEST_F(CtrlAgentCommandMgrTest, forwardToDHCPv6Server) {
-    testForward(CtrlAgentCfgContext::TYPE_DHCP6, "dhcp6",
-                isc::config::CONTROL_RESULT_SUCCESS);
+    testForward("dhcp6", "dhcp6", isc::config::CONTROL_RESULT_SUCCESS);
 }
 
 /// Check that the same command is forwarded to multiple servers.
 TEST_F(CtrlAgentCommandMgrTest, forwardToBothDHCPServers) {
-    configureControlSocket(CtrlAgentCfgContext::TYPE_DHCP6);
+    configureControlSocket("dhcp6");
 
-    testForward(CtrlAgentCfgContext::TYPE_DHCP4, "dhcp4,dhcp6",
-                isc::config::CONTROL_RESULT_SUCCESS,
-                isc::config::CONTROL_RESULT_SUCCESS,
-                -1, 2);
+    testForward("dhcp4", "dhcp4,dhcp6", isc::config::CONTROL_RESULT_SUCCESS,
+                isc::config::CONTROL_RESULT_SUCCESS, -1, 2);
 }
 
 /// Check that the command may forwarded to the second server even if
 /// forwarding to a first server fails.
 TEST_F(CtrlAgentCommandMgrTest, failForwardToServer) {
-    testForward(CtrlAgentCfgContext::TYPE_DHCP6, "dhcp4,dhcp6",
+    testForward("dhcp6", "dhcp4,dhcp6",
                 isc::config::CONTROL_RESULT_ERROR,
                 isc::config::CONTROL_RESULT_SUCCESS);
 }
 
 /// Check that control command is not forwarded if the service is not specified.
 TEST_F(CtrlAgentCommandMgrTest, noService) {
-    testForward(CtrlAgentCfgContext::TYPE_DHCP6, "",
+    testForward("dhcp6", "",
                 isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED,
                 -1, -1, 0);
 }
@@ -327,7 +322,7 @@ TEST_F(CtrlAgentCommandMgrTest, noService) {
 /// Check that error is returned to the client when the server to which the
 /// command was forwarded sent an invalid message.
 TEST_F(CtrlAgentCommandMgrTest, invalidAnswer) {
-    testForward(CtrlAgentCfgContext::TYPE_DHCP6, "dhcp6",
+    testForward("dhcp6", "dhcp6",
                 isc::config::CONTROL_RESULT_ERROR, -1, -1, 1,
                 "{ \"result\": 0");
 }
@@ -345,7 +340,7 @@ TEST_F(CtrlAgentCommandMgrTest, noClientSocket) {
 /// Check that error is returned to the client if the remote server to
 /// which the control command is to be forwarded is not available.
 TEST_F(CtrlAgentCommandMgrTest, noServerSocket) {
-    configureControlSocket(CtrlAgentCfgContext::TYPE_DHCP6);
+    configureControlSocket("dhcp6");
 
     ConstElementPtr command = createCommand("foo", "dhcp6");
     ConstElementPtr answer = mgr_.handleCommand("foo", ConstElementPtr(),
@@ -358,7 +353,7 @@ TEST_F(CtrlAgentCommandMgrTest, noServerSocket) {
 // value is specified.
 TEST_F(CtrlAgentCommandMgrTest, forwardListCommands) {
     // Configure client side socket.
-    configureControlSocket(CtrlAgentCfgContext::TYPE_DHCP4);
+    configureControlSocket("dhcp4");
     // Create server side socket.
     bindServerSocket("{ \"result\" : 3 }");
 

+ 9 - 9
src/bin/agent/tests/ca_controller_unittests.cc

@@ -79,14 +79,14 @@ public:
     /// @brief Tests that socket info structure contains 'unix' socket-type
     /// value and the expected socket-name.
     ///
-    /// @param type Server type.
+    /// @param service Service type.
     /// @param exp_socket_name Expected socket name.
-    void testUnixSocketInfo(const CtrlAgentCfgContext::ServerType& type,
+    void testUnixSocketInfo(const std::string& service,
                             const std::string& exp_socket_name) {
         CtrlAgentCfgContextPtr ctx = getCtrlAgentCfgContext();
         ASSERT_TRUE(ctx);
 
-        ConstElementPtr sock_info = ctx->getControlSocketInfo(type);
+        ConstElementPtr sock_info = ctx->getControlSocketInfo(service);
         ASSERT_TRUE(sock_info);
         ASSERT_TRUE(sock_info->contains("socket-type"));
         EXPECT_EQ("unix", sock_info->get("socket-type")->stringValue());
@@ -304,8 +304,8 @@ TEST_F(CtrlAgentControllerTest, successfulConfigUpdate) {
     EXPECT_EQ(8080, ctx->getHttpPort());
 
     // The forwarding configuration should have been updated too.
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4, "/second/dhcp4/socket");
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6, "/second/dhcp6/socket");
+    testUnixSocketInfo("dhcp4", "/second/dhcp4/socket");
+    testUnixSocketInfo("dhcp6", "/second/dhcp6/socket");
 
     CtrlAgentProcessPtr process = getCtrlAgentProcess();
     ASSERT_TRUE(process);
@@ -359,8 +359,8 @@ TEST_F(CtrlAgentControllerTest, unsuccessfulConfigUpdate) {
     EXPECT_EQ(8081, ctx->getHttpPort());
 
     // Same for forwarding.
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4, "/first/dhcp4/socket");
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6, "/first/dhcp6/socket");
+    testUnixSocketInfo("dhcp4", "/first/dhcp4/socket");
+    testUnixSocketInfo("dhcp6", "/first/dhcp6/socket");
 
     CtrlAgentProcessPtr process = getCtrlAgentProcess();
     ASSERT_TRUE(process);
@@ -412,8 +412,8 @@ TEST_F(CtrlAgentControllerTest, noListenerChange) {
     EXPECT_EQ(8081, ctx->getHttpPort());
 
     // The forwarding configuration should have been updated.
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP4, "/second/dhcp4/socket");
-    testUnixSocketInfo(CtrlAgentCfgContext::TYPE_DHCP6, "/second/dhcp6/socket");
+    testUnixSocketInfo("dhcp4", "/second/dhcp4/socket");
+    testUnixSocketInfo("dhcp6", "/second/dhcp6/socket");
 
     CtrlAgentProcessPtr process = getCtrlAgentProcess();
     ASSERT_TRUE(process);