Browse Source

[5165] Control agent uses configured server address and port.

Marcin Siodelski 8 years ago
parent
commit
2364ac9a1a

+ 21 - 5
src/bin/agent/ca_process.cc

@@ -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.

+ 1 - 1
src/bin/agent/simple_parser.cc

@@ -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"}
 };
 

+ 5 - 2
src/bin/agent/tests/ca_controller_unittests.cc

@@ -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

+ 3 - 0
src/bin/agent/tests/ca_process_unittests.cc

@@ -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