Browse Source

[5110] Clean up D2Params default and default testing

Thomas Markwalder 8 years ago
parent
commit
19ac635170

+ 4 - 4
src/bin/d2/d2_config.cc

@@ -28,8 +28,8 @@ namespace d2 {
 // *********************** D2Params  *************************
 
 const char *D2Params::DFT_IP_ADDRESS = "127.0.0.1";
-const size_t D2Params::DFT_PORT = 53001;
-const size_t D2Params::DFT_DNS_SERVER_TIMEOUT = 100;
+const char *D2Params::DFT_PORT = "53001";
+const char *D2Params::DFT_DNS_SERVER_TIMEOUT = "100";
 const char *D2Params::DFT_NCR_PROTOCOL = "UDP";
 const char *D2Params::DFT_NCR_FORMAT = "JSON";
 
@@ -48,8 +48,8 @@ D2Params::D2Params(const isc::asiolink::IOAddress& ip_address,
 
 D2Params::D2Params()
     : ip_address_(isc::asiolink::IOAddress(DFT_IP_ADDRESS)),
-     port_(DFT_PORT),
-     dns_server_timeout_(DFT_DNS_SERVER_TIMEOUT),
+     port_(boost::lexical_cast<size_t>(DFT_PORT)),
+     dns_server_timeout_(boost::lexical_cast<size_t>(DFT_DNS_SERVER_TIMEOUT)),
      ncr_protocol_(dhcp_ddns::NCR_UDP),
      ncr_format_(dhcp_ddns::FMT_JSON) {
     validateContents();

+ 3 - 8
src/bin/d2/d2_config.h

@@ -36,10 +36,6 @@ namespace d2 {
 /// a name, the algorithm method name, optionally the minimum truncated
 /// length, and its secret key component.
 ///
-/// @todo  NOTE that TSIG configuration parsing is functional, the use of
-/// TSIG Keys during the actual DNS update transactions is not.  This will be
-/// implemented in a future release.
-///
 /// Each managed domain list consists of a list one or more domains and is
 /// represented by the class DdnsDomainListMgr.
 ///
@@ -140,13 +136,12 @@ public:
 /// @brief Acts as a storage vault for D2 global scalar parameters
 class D2Params {
 public:
+
     /// @brief Default configuration constants.
     //@{
-    /// @todo For now these are hard-coded as configuration layer cannot
-    /// readily provide them (see Trac #3358).
     static const char *DFT_IP_ADDRESS;
-    static const size_t DFT_PORT;
-    static const size_t DFT_DNS_SERVER_TIMEOUT;
+    static const char *DFT_PORT;
+    static const char *DFT_DNS_SERVER_TIMEOUT;
     static const char *DFT_NCR_PROTOCOL;
     static const char *DFT_NCR_FORMAT;
     //@}

+ 8 - 6
src/bin/d2/d2_simple_parser.cc

@@ -4,9 +4,11 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+#include <d2/d2_config.h>
 #include <d2/d2_simple_parser.h>
 #include <cc/data.h>
 #include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
 
 using namespace isc::data;
 
@@ -27,17 +29,17 @@ namespace d2 {
 ///
 /// @{
 
-/// @brief This table defines default global values for D2 
+/// @brief This table defines default global values for D2
 ///
 /// Some of the global parameters defined in the global scope (i.e. directly
 /// in DhcpDdns) are optional. If not defined, the following values will be
 /// used.
 const SimpleDefaults D2SimpleParser::D2_GLOBAL_DEFAULTS = {
-    { "ip-address",         Element::string, "127.0.0.1" },
-    { "port",               Element::integer, "53001" },
-    { "dns-server-timeout", Element::integer, "100" },
-    { "ncr-protocol",       Element::string, "UDP" },
-    { "ncr-format",         Element::string, "JSON" }
+    { "ip-address",         Element::string, D2Params::DFT_IP_ADDRESS },
+    { "port",               Element::integer, D2Params::DFT_PORT },
+    { "dns-server-timeout", Element::integer, D2Params::DFT_DNS_SERVER_TIMEOUT },
+    { "ncr-protocol",       Element::string, D2Params::DFT_NCR_PROTOCOL },
+    { "ncr-format",         Element::string, D2Params::DFT_NCR_FORMAT }
 };
 
 /// @}

+ 21 - 7
src/bin/d2/tests/d2_cfg_mgr_unittests.cc

@@ -9,7 +9,9 @@
 #include <config/module_spec.h>
 #include <d2/d2_config.h>
 #include <d2/d2_cfg_mgr.h>
+#include <d2/d2_simple_parser.h>
 #include <d2/parser_context.h>
+#include <d2/tests/parser_unittest.h>
 #include <dhcpsrv/testutils/config_result_check.h>
 #include <process/testutils/d_test_stubs.h>
 #include <test_data_files_config.h>
@@ -388,6 +390,9 @@ TEST_F(D2CfgMgrTest, validParamsEntry) {
 /// Currently they are all optional.
 TEST_F(D2CfgMgrTest, defaultValues) {
 
+    ElementPtr defaults = isc::d2::test::parseJSON("{ }");
+    ASSERT_NO_THROW(D2SimpleParser::setAllDefaults(defaults));
+
     // Check that omitting ip_address gets you its default
     std::string config =
             "{"
@@ -401,8 +406,10 @@ TEST_F(D2CfgMgrTest, defaultValues) {
             "}";
 
     runConfig(config);
-    EXPECT_EQ(isc::asiolink::IOAddress(D2Params::DFT_IP_ADDRESS),
-              d2_params_->getIpAddress());
+    ConstElementPtr deflt;
+    ASSERT_NO_THROW(deflt = defaults->get("ip-address"));
+    ASSERT_TRUE(deflt);
+    EXPECT_EQ(deflt->stringValue(), d2_params_->getIpAddress().toText());
 
     // Check that omitting port gets you its default
     config =
@@ -417,7 +424,9 @@ TEST_F(D2CfgMgrTest, defaultValues) {
             "}";
 
     runConfig(config);
-    EXPECT_EQ(D2Params::DFT_PORT, d2_params_->getPort());
+    ASSERT_NO_THROW(deflt = defaults->get("port"));
+    ASSERT_TRUE(deflt);
+    EXPECT_EQ(deflt->intValue(), d2_params_->getPort());
 
     // Check that omitting timeout gets you its default
     config =
@@ -432,8 +441,9 @@ TEST_F(D2CfgMgrTest, defaultValues) {
             "}";
 
     runConfig(config);
-    EXPECT_EQ(D2Params::DFT_DNS_SERVER_TIMEOUT,
-              d2_params_->getDnsServerTimeout());
+    ASSERT_NO_THROW(deflt = defaults->get("dns-server-timeout"));
+    ASSERT_TRUE(deflt);
+    EXPECT_EQ(deflt->intValue(), d2_params_->getDnsServerTimeout());
 
     // Check that omitting protocol gets you its default
     config =
@@ -448,7 +458,9 @@ TEST_F(D2CfgMgrTest, defaultValues) {
             "}";
 
     runConfig(config);
-    EXPECT_EQ(dhcp_ddns::stringToNcrProtocol(D2Params::DFT_NCR_PROTOCOL),
+    ASSERT_NO_THROW(deflt = defaults->get("ncr-protocol"));
+    ASSERT_TRUE(deflt);
+    EXPECT_EQ(dhcp_ddns::stringToNcrProtocol(deflt->stringValue()),
               d2_params_->getNcrProtocol());
 
     // Check that omitting format gets you its default
@@ -464,7 +476,9 @@ TEST_F(D2CfgMgrTest, defaultValues) {
             "}";
 
     runConfig(config);
-    EXPECT_EQ(dhcp_ddns::stringToNcrFormat(D2Params::DFT_NCR_FORMAT),
+    ASSERT_NO_THROW(deflt = defaults->get("ncr-format"));
+    ASSERT_TRUE(deflt);
+    EXPECT_EQ(dhcp_ddns::stringToNcrFormat(deflt->stringValue()),
               d2_params_->getNcrFormat());
 }