]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5165] Control agent uses configured server address and port.
authorMarcin Siodelski <marcin@isc.org>
Thu, 2 Mar 2017 12:16:20 +0000 (13:16 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 2 Mar 2017 12:16:20 +0000 (13:16 +0100)
src/bin/agent/ca_process.cc
src/bin/agent/simple_parser.cc
src/bin/agent/tests/ca_controller_unittests.cc
src/bin/agent/tests/ca_process_unittests.cc

index 891d193042a1ac6ba8c09524e3b6f33ad44ad4d5..7847ac9bc2f33c2448eb70186f6df8ecefe86b2b 100644 (file)
@@ -9,6 +9,7 @@
 #include <agent/ca_response_creator_factory.h>
 #include <agent/ca_log.h>
 #include <asiolink/io_address.h>
+#include <asiolink/io_error.h>
 #include <cc/command_interpreter.h>
 #include <http/listener.h>
 #include <boost/pointer_cast.hpp>
@@ -21,8 +22,6 @@ using namespace isc::process;
 /// @todo: remove once 5134 is merged.
 namespace {
 
-const IOAddress SERVER_ADDRESS("127.0.0.1");
-const unsigned short SERVER_PORT = 8081;
 const long REQUEST_TIMEOUT = 10000;
 
 }
@@ -53,10 +52,27 @@ CtrlAgentProcess::run() {
         // answer to specific request.
         HttpResponseCreatorFactoryPtr rcf(new CtrlAgentResponseCreatorFactory());
 
+        DCfgContextBasePtr base_ctx = getCfgMgr()->getContext();
+        CtrlAgentCfgContextPtr ctx = boost::dynamic_pointer_cast<CtrlAgentCfgContext>(base_ctx);
+        if (!ctx) {
+            isc_throw(Unexpected, "Interal logic error: bad context type");
+        }
+
+        /// @todo: If the parameter is a hostname, we need to resolve it.
+        IOAddress server_address("::");
+        try {
+            server_address = IOAddress(ctx->getHttpHost());
+        } catch (const IOError& e) {
+            isc_throw(BadValue, "Failed to convert " << ctx->getHttpHost()
+                      << " to IP address:" << e.what());
+        }
+
+        uint16_t server_port = ctx->getHttpPort();
+
         // Create http listener. It will open up a TCP socket and be prepared
         // to accept incoming connection.
-        HttpListener http_listener(*getIoService(), SERVER_ADDRESS,
-                                   SERVER_PORT, rcf, REQUEST_TIMEOUT);
+        HttpListener http_listener(*getIoService(), server_address,
+                                   server_port, rcf, REQUEST_TIMEOUT);
 
         // Instruct the http listener to actually open socket, install callback
         // and start listening.
@@ -64,7 +80,7 @@ CtrlAgentProcess::run() {
 
         // Ok, seems we're good to go.
         LOG_INFO(agent_logger, CTRL_AGENT_HTTP_SERVICE_STARTED)
-            .arg(SERVER_ADDRESS.toText()).arg(SERVER_PORT);
+            .arg(server_address.toText()).arg(server_port);
 
         // Let's process incoming data or expiring timers in a loop until
         // shutdown condition is detected.
index 41c642c5794118de6770cd4cda7e16c407a9a996..68bf115d8542f9a568ed3f9a670f76f5767bf0e0 100644 (file)
@@ -33,7 +33,7 @@ namespace agent {
 ///
 /// These are global Control Agent parameters.
 const SimpleDefaults AgentSimpleParser::AGENT_DEFAULTS = {
-    { "http-host",    Element::string,  "localhost"},
+    { "http-host",    Element::string,  "127.0.0.1"},
     { "http-port",    Element::integer,  "8000"}
 };
 
index c8bbc0f4e519b0d6eb61044963be0221850fcd28..70d3c10adfbd55bd31255b5dcbd7c5c07073b0db 100644 (file)
@@ -16,8 +16,11 @@ using namespace isc::process;
 namespace {
 
 /// @brief Valid Control Agent Config used in tests.
-/// @todo Use actual config once configuration parsing is implemented.
-const char* valid_agent_config = "{ }";
+const char* valid_agent_config =
+    "{"
+    "  \"http-host\": \"127.0.0.1\","
+    "  \"http-port\": 8081"
+    "}";
 
 /// @brief test fixture class for testing CtrlAgentController class. This
 /// class derives from DControllerTest and wraps CtrlAgentController. Much
index 417d1e463fe721a744d261cfae633c01aff7977e..7f9101b6297df200b5cc6cab1be24b34a3cc9775 100644 (file)
@@ -29,6 +29,9 @@ public:
     CtrlAgentProcessTest() :
         CtrlAgentProcess("agent-test",
                          IOServicePtr(new isc::asiolink::IOService())) {
+        CtrlAgentCfgContextPtr ctx = getCtrlAgentCfgMgr()->getCtrlAgentCfgContext();
+        ctx->setHttpHost("127.0.0.1");
+        ctx->setHttpPort(8081);
     }
 
     /// @brief Destructor