From: Tomek Mrugalski Date: Thu, 2 Mar 2017 00:34:02 +0000 (+0100) Subject: [5134_rebase] bug in setAllDefaults fixed, unit-tests added. X-Git-Tag: trac5137_base~3^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6accbe4bb1a32abe50102042f5726e41412a4e67;p=thirdparty%2Fkea.git [5134_rebase] bug in setAllDefaults fixed, unit-tests added. --- diff --git a/src/bin/agent/simple_parser.cc b/src/bin/agent/simple_parser.cc index 9b9ec5bb75..bb00b32ca3 100644 --- a/src/bin/agent/simple_parser.cc +++ b/src/bin/agent/simple_parser.cc @@ -69,7 +69,7 @@ size_t AgentSimpleParser::setAllDefaults(isc::data::ElementPtr global) { } ElementPtr d6 = boost::const_pointer_cast(sockets->get("dhcp6-server")); - if (d2) { + if (d6) { cnt += SimpleParser::setDefaults(d6, SOCKET_DEFAULTS); } } diff --git a/src/bin/agent/tests/ctrl_agent_cfg_mgr_unittest.cc b/src/bin/agent/tests/ctrl_agent_cfg_mgr_unittest.cc index f1d33807fd..e39a47e9c7 100644 --- a/src/bin/agent/tests/ctrl_agent_cfg_mgr_unittest.cc +++ b/src/bin/agent/tests/ctrl_agent_cfg_mgr_unittest.cc @@ -233,6 +233,28 @@ const char* AGENT_CONFIGS[] = { " }\n" " }\n" " ]\n" + "}", + + // Configuration 5: http and 1 socket (d2 only) + "{\n" + " \"http-host\": \"betelguese\",\n" + " \"http-port\": 8001,\n" + " \"control-sockets\": {\n" + " \"d2-server\": {\n" + " \"socket-name\": \"/tmp/socket-d2\"\n" + " }\n" + " }\n" + "}", + + // Configuration 6: http and 1 socket (dhcp6 only) + "{\n" + " \"http-host\": \"betelguese\",\n" + " \"http-port\": 8001,\n" + " \"control-sockets\": {\n" + " \"dhcp6-server\": {\n" + " \"socket-name\": \"/tmp/socket-v6\"\n" + " }\n" + " }\n" "}" }; @@ -289,7 +311,7 @@ TEST_F(AgentParserTest, configParseHttpOnly) { // Tests if a single socket can be configured. BTW this test also checks // if default value for socket-type is specified (the config doesn't have it, // so the default value should be filed in). -TEST_F(AgentParserTest, configParse1Socket) { +TEST_F(AgentParserTest, configParseSocketDhcp4) { configParse(AGENT_CONFIGS[2], 0); CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext(); @@ -302,6 +324,39 @@ TEST_F(AgentParserTest, configParse1Socket) { EXPECT_FALSE(ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_D2)); } +// Tests if a single socket can be configured. BTW this test also checks +// if default value for socket-type is specified (the config doesn't have it, +// so the default value should be filed in). +TEST_F(AgentParserTest, configParseSocketD2) { + configParse(AGENT_CONFIGS[5], 0); + + CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext(); + ASSERT_TRUE(ctx); + ConstElementPtr socket = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_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)); +} + +// Tests if a single socket can be configured. BTW this test also checks +// if default value for socket-type is specified (the config doesn't have it, +// so the default value should be filed in). +TEST_F(AgentParserTest, configParseSocketDhcp6) { + configParse(AGENT_CONFIGS[6], 0); + + CtrlAgentCfgContextPtr ctx = cfg_mgr_.getCtrlAgentCfgContext(); + ASSERT_TRUE(ctx); + ConstElementPtr socket = ctx->getControlSocketInfo(CtrlAgentCfgContext::TYPE_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)); +} + // This tests if all 3 sockets can be configured and makes sure the parser // doesn't confuse them. TEST_F(AgentParserTest, configParse3Sockets) {