From 2364ac9a1a09f232903e0ee20f0b61dc467c944e Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Thu, 2 Mar 2017 13:16:20 +0100 Subject: [PATCH] [5165] Control agent uses configured server address and port. --- src/bin/agent/ca_process.cc | 26 +++++++++++++++---- src/bin/agent/simple_parser.cc | 2 +- .../agent/tests/ca_controller_unittests.cc | 7 +++-- src/bin/agent/tests/ca_process_unittests.cc | 3 +++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/bin/agent/ca_process.cc b/src/bin/agent/ca_process.cc index 891d193042..7847ac9bc2 100644 --- a/src/bin/agent/ca_process.cc +++ b/src/bin/agent/ca_process.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -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(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. diff --git a/src/bin/agent/simple_parser.cc b/src/bin/agent/simple_parser.cc index 41c642c579..68bf115d85 100644 --- a/src/bin/agent/simple_parser.cc +++ b/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"} }; diff --git a/src/bin/agent/tests/ca_controller_unittests.cc b/src/bin/agent/tests/ca_controller_unittests.cc index c8bbc0f4e5..70d3c10adf 100644 --- a/src/bin/agent/tests/ca_controller_unittests.cc +++ b/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 diff --git a/src/bin/agent/tests/ca_process_unittests.cc b/src/bin/agent/tests/ca_process_unittests.cc index 417d1e463f..7f9101b629 100644 --- a/src/bin/agent/tests/ca_process_unittests.cc +++ b/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 -- 2.47.3