]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Several changes after review
authorTomek Mrugalski <tomasz@isc.org>
Sat, 16 Dec 2017 14:27:31 +0000 (15:27 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Sat, 16 Dec 2017 14:27:31 +0000 (15:27 +0100)
doc/examples/kea4/comments.json
doc/examples/kea6/comments.json
doc/guide/hooks.xml
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/cc/user_context.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc

index 93bfa77d6e099692de2c4ebb2d2f32eefbab21bc..245301473aad0f99275663bb168cbccd9217a702 100644 (file)
@@ -1,5 +1,5 @@
 // This is an example configuration file for the DHCPv4 server in Kea.
-// It uses embedded (i.e., which will be included in configuration objets
+// It uses embedded (i.e., which will be included in configuration objects
 // and not stripped by at lexical analysis) comments.
 
 { "Dhcp4":
index bd10aed258f2738f422cac07cf54e6bcf1cf8771..8ba919a44ea47f525a557c1e4cd9111c71bfaa7d 100644 (file)
@@ -1,5 +1,5 @@
 // This is an example configuration file for the DHCPv6 server in Kea.
-// It uses embedded (i.e., which will be included in configuration objets
+// It uses embedded (i.e., which will be included in configuration objects
 // and not stripped by at lexical analysis) comments.
 
 { "Dhcp6":
index e26829017a7d8b32817bf0372af2a8fae5c406d9..2fc169d5450996695cf4b65622d696f297d1cc52 100644 (file)
@@ -81,7 +81,7 @@
         a library.  The change was made in Kea 1.0 to facilitate the
         specification of library-specific parameters, a capability
         available in Kea 1.1.0 onwards. Libraries should allow a parameter
-        entry where to put documentation as it is done for many configuration
+        entry where to put comments as it is done for many configuration
         scopes with comment and user context.
       </para></note>
 
@@ -2547,8 +2547,8 @@ both the command and the response.
       </para>
       <para>
         Usually when an entry is defined multiple times in the same scope
-        the last value is used overwriting previous values (silently:
-        this behavior should be fixed soon). With user contexts values
+        the last value is used overwriting previous values (this
+        behavior will be fixed some time in the future). With user contexts values
         are combined at the first level, for instance multiple user context
         with a "comment" entry gives an entry with the list of accumulated
         values.
@@ -2561,16 +2561,15 @@ both the command and the response.
         operations for example.
       </para>
       <para>
-        The parser translates "comment" entries at locations user context
-        are valid into a user context with a "comment" entry. The pretty
-        print of a configuration does the opposite operation and puts
-        "comment" entries at the beginning of maps as it seems to be the
-        common usage.
+        If user context is supported in a given context, the parser translates
+        "comment" entries into user context with a "comment" entry. The pretty
+        print of a configuration does the opposite operation and puts "comment"
+        entries at the beginning of maps as it seems to be the common usage.
       </para>
       <para>
         As of Kea 1.3, the structures that allow user contexts are
         pools of all types (addresses and prefixes) and subnets. Kea
-        1.4 extended to the global scope, interfaces config,
+        1.4 extended user context support to the global scope, interfaces config,
         shared networks, subnets, client classes, option datas and definitions,
         host reservations, control socket, dhcp ddns, loggers and server id.
         These are supported in both DHCPv4 and DHCPv6 at the exception
index 0d062321e995beaaa444e5ddfe00c15a801bf0bb..7e823a0b95b3995d77fe8e040121b4f52db6aef4 100644 (file)
@@ -207,7 +207,101 @@ const char* PARSER_CONFIGS[] = {
     "        ],"
     "        \"subnet\": \"2001:db8::/32\""
     "     } ]"
-    "}"
+    "}",
+
+    // Configuration 7: comments everywhere
+    "{\n"
+    "\"comment\": \"A DHCPv6 server\",\n"
+    "\"server-id\": {\n"
+    "    \"comment\": \"DHCPv6 specific\",\n"
+    "    \"type\": \"LL\"\n"
+    "},\n"
+    "\"interfaces-config\": {\n"
+    "    \"comment\": \"Use wildcard\",\n"
+    "    \"interfaces\": [ \"*\" ] },\n"
+    "\"option-def\": [ {\n"
+    "    \"comment\": \"An option definition\",\n"
+    "    \"name\": \"foo\",\n"
+    "    \"code\": 100,\n"
+    "    \"type\": \"ipv6-address\",\n"
+    "    \"space\": \"isc\"\n"
+    " } ],\n"
+    "\"option-data\": [ {\n"
+    "    \"comment\": \"Set option value\",\n"
+    "    \"name\": \"subscriber-id\",\n"
+    "    \"data\": \"ABCDEF0105\",\n"
+    "        \"csv-format\": false\n"
+    " } ],\n"
+    "\"client-classes\": [\n"
+    "    {\n"
+    "       \"comment\": \"match all\",\n"
+    "       \"name\": \"all\",\n"
+    "       \"test\": \"'' == ''\"\n"
+    "    },\n"
+    "    {\n"
+    "       \"name\": \"none\"\n"
+    "    },\n"
+    "    {\n"
+    "       \"comment\": \"first comment\",\n"
+    "       \"comment\": \"second comment\",\n"
+    "       \"name\": \"two\"\n"
+    "    },\n"
+    "    {\n"
+    "       \"comment\": \"a comment\",\n"
+    "       \"name\": \"both\",\n"
+    "       \"user-context\": {\n"
+    "           \"version\": 1\n"
+    "       }\n"
+    "    }\n"
+    "    ],\n"
+    "\"control-socket\": {\n"
+    "    \"comment\": \"REST API\",\n"
+    "    \"socket-type\": \"unix\",\n"
+    "    \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
+    "    \"user-context\": { \"comment\": \"Indirect comment\" }\n"
+    "},\n"
+    "\"shared-networks\": [ {\n"
+    "    \"comment\": \"A shared network\"\n,"
+    "    \"name\": \"foo\"\n,"
+    "    \"subnet6\": [\n"
+    "    { \n"
+    "        \"comment\": \"A subnet\"\n,"
+    "        \"subnet\": \"2001:db1::/48\",\n"
+    "        \"id\": 100,\n"
+    "        \"pools\": [\n"
+    "        {\n"
+    "             \"comment\": \"A pool\",\n"
+    "             \"pool\": \"2001:db1::/64\"\n"
+    "        }\n"
+    "        ],\n"
+    "        \"pd-pools\": [\n"
+    "        {\n"
+    "             \"comment\": \"A prefix pool\",\n"
+    "             \"prefix\": \"2001:db2::\",\n"
+    "             \"prefix-len\": 48,\n"
+    "             \"delegated-len\": 64\n"
+    "        }\n"
+    "        ],\n"
+    "        \"reservations\": [\n"
+    "        {\n"
+    "             \"comment\": \"A host reservation\",\n"
+    "             \"hw-address\": \"AA:BB:CC:DD:EE:FF\",\n"
+    "             \"hostname\": \"foo.example.com\",\n"
+    "             \"option-data\": [ {\n"
+    "                 \"comment\": \"An option in a reservation\",\n"
+    "                 \"name\": \"domain-search\",\n"
+    "                 \"data\": \"example.com\"\n"
+    "             } ]\n"
+    "        }\n"
+    "        ]\n"
+    "    }\n"
+    "    ]\n"
+    " } ],\n"
+    "\"dhcp-ddns\": {\n"
+    "    \"comment\": \"No dynamic DNS\",\n"
+    "    \"enable-updates\": false\n"
+    "}\n"
+    "}\n"
 };
 
 std::string specfile(const std::string& name) {
@@ -814,7 +908,7 @@ public:
     }
 
     int rcode_; ///< Return code (see @ref isc::config::parseAnswer)
-    ControlledDhcpv6Srv srv_; ///< Instance of the ControlledDhcp6Srv used during tests
+    Dhcpv6Srv srv_; ///< Instance of the ControlledDhcp6Srv used during tests
     ConstElementPtr comment_; ///< Comment (see @ref isc::config::parseAnswer)
     string valid_iface_; ///< Valid network interface name (present in system)
     string bogus_iface_; ///< invalid network interface name (not in system)
@@ -6053,101 +6147,8 @@ TEST_F(Dhcp6ParserTest, sharedNetworksRapidCommitMix) {
 // This test checks comments. Please keep it last.
 TEST_F(Dhcp6ParserTest, comments) {
 
-    string config = "{\n"
-        "\"comment\": \"A DHCPv6 server\",\n"
-        "\"server-id\": {\n"
-        "    \"comment\": \"DHCPv6 specific\",\n"
-        "    \"type\": \"LL\"\n"
-        "},\n"
-        "\"interfaces-config\": {\n"
-        "    \"comment\": \"Use wildcard\",\n"
-        "    \"interfaces\": [ \"*\" ] },\n"
-        "\"option-def\": [ {\n"
-        "    \"comment\": \"An option definition\",\n"
-        "    \"name\": \"foo\",\n"
-        "    \"code\": 100,\n"
-        "    \"type\": \"ipv6-address\",\n"
-        "    \"space\": \"isc\"\n"
-        " } ],\n"
-        "\"option-data\": [ {\n"
-        "    \"comment\": \"Set option value\",\n"
-        "    \"name\": \"subscriber-id\",\n"
-        "    \"data\": \"ABCDEF0105\",\n"
-        "        \"csv-format\": false\n"
-        " } ],\n"
-        "\"client-classes\": [\n"
-        "    {\n"
-        "       \"comment\": \"match all\",\n"
-        "       \"name\": \"all\",\n"
-        "       \"test\": \"'' == ''\"\n"
-        "    },\n"
-        "    {\n"
-        "       \"name\": \"none\"\n"
-        "    },\n"
-        "    {\n"
-        "       \"comment\": \"first comment\",\n"
-        "       \"comment\": \"second comment\",\n"
-        "       \"name\": \"two\"\n"
-        "    },\n"
-        "    {\n"
-        "       \"comment\": \"a comment\",\n"
-        "       \"name\": \"both\",\n"
-        "       \"user-context\": {\n"
-        "           \"version\": 1\n"
-        "       }\n"
-        "    }\n"
-        "    ],\n"
-        "\"control-socket\": {\n"
-        "    \"comment\": \"REST API\",\n"
-        "    \"socket-type\": \"unix\",\n"
-        "    \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
-        "    \"user-context\": { \"comment\": \"Indirect comment\" }\n"
-        "},\n"
-        "\"shared-networks\": [ {\n"
-        "    \"comment\": \"A shared network\"\n,"
-        "    \"name\": \"foo\"\n,"
-        "    \"subnet6\": [\n"
-        "    { \n"
-        "        \"comment\": \"A subnet\"\n,"
-        "        \"subnet\": \"2001:db1::/48\",\n"
-        "        \"id\": 100,\n"
-        "        \"pools\": [\n"
-        "        {\n"
-        "             \"comment\": \"A pool\",\n"
-        "             \"pool\": \"2001:db1::/64\"\n"
-        "        }\n"
-        "        ],\n"
-        "        \"pd-pools\": [\n"
-        "        {\n"
-        "             \"comment\": \"A prefix pool\",\n"
-        "             \"prefix\": \"2001:db2::\",\n"
-        "             \"prefix-len\": 48,\n"
-        "             \"delegated-len\": 64\n"
-        "        }\n"
-        "        ],\n"
-        "        \"reservations\": [\n"
-        "        {\n"
-        "             \"comment\": \"A host reservation\",\n"
-        "             \"hw-address\": \"AA:BB:CC:DD:EE:FF\",\n"
-        "             \"hostname\": \"foo.example.com\",\n"
-        "             \"option-data\": [ {\n"
-        "                 \"comment\": \"An option in a reservation\",\n"
-        "                 \"name\": \"domain-search\",\n"
-        "                 \"data\": \"example.com\"\n"
-        "             } ]\n"
-        "        }\n"
-        "        ]\n"
-        "    }\n"
-        "    ]\n"
-        " } ],\n"
-        "\"dhcp-ddns\": {\n"
-        "    \"comment\": \"No dynamic DNS\",\n"
-        "    \"enable-updates\": false\n"
-        "}\n"
-        "}\n";
-
-    extractConfig(config);
-    configure(config, CONTROL_RESULT_SUCCESS, "");
+    extractConfig(PARSER_CONFIGS[7]);
+    configure(PARSER_CONFIGS[7], CONTROL_RESULT_SUCCESS, "");
 
     // Check global user context.
     ConstElementPtr ctx = CfgMgr::instance().getStagingCfg()->getContext();
@@ -6384,16 +6385,6 @@ TEST_F(Dhcp6ParserTest, comments) {
     ASSERT_EQ(1, ctx_d2->size());
     ASSERT_TRUE(ctx_d2->get("comment"));
     EXPECT_EQ("\"No dynamic DNS\"", ctx_d2->get("comment")->str());
-
-#if 0
-    // Loggers section supports comments too.
-
-    string logging = "{\n"
-        "\"loggers\": [ {\n"
-        "    \"comment\": \"A logger\",\n"
-        "    \"name\": \"kea-dhcp6\"\n"
-        "} ]\n";
-#endif
 }
 
 };
index 2487f4d5e0032d93851b940629f005f34564baef..e463a99d2b06cad1c8c592f7e41a3b042b89c997 100644 (file)
 namespace isc {
 namespace dhcp {
 
-/// @brief base class for user context
+/// @brief Base class for user context
+///
+/// Many configuration structures allow attaching and storing arbitrary
+/// user data that we call user context. Each of those configuration
+/// structures need to derive from this class to handle user context.
 class UserContext {
 
 public:
index 8f38e43a2825225aed0814c2659a12591fc4f77e..9456f223fc7d075f6134b11703cd89daec1343cb 100644 (file)
@@ -630,7 +630,7 @@ public:
                 ConstElementPtr ctx = Element::fromJSON(user_context);
                 if (!ctx || (ctx->getType() != Element::map)) {
                     isc_throw(BadValue, "user context '" << user_context
-                              << "' is no a JSON map");
+                              << "' is not a JSON map");
                 }
                 h->setContext(ctx);
             } catch (const isc::data::JSONError& ex) {
index e955fbd5b9d3600026cb81f070f1f9f3af65a8b4..252f22cc4ce31a766b20cd7b3a189e64881b8b18 100644 (file)
@@ -395,7 +395,7 @@ public:
                     ConstElementPtr ctx = Element::fromJSON(user_context);
                     if (!ctx || (ctx->getType() != Element::map)) {
                         isc_throw(BadValue, "user context '" << user_context
-                                  << "' is no a JSON map");
+                                  << "' is not a JSON map");
                     }
                     host->setContext(ctx);
                 } catch (const isc::data::JSONError& ex) {
index 94af03af2f777007d89dc74484420aadaa9c9fbf..bdf606652fafdfb4bdd7b884e77c7ba2a91cbf24 100644 (file)
@@ -813,7 +813,7 @@ GenericHostDataSourceTest::testUserContext(ConstElementPtr user_context) {
 
     // Create a host reservation.
     HostPtr host = initializeHost4("192.0.2.1", Host::IDENT_DUID);
-    ASSERT_TRUE(host); // Make sure the host is generate properly.
+    ASSERT_TRUE(host); // Make sure the host is generated properly.
     host->setContext(user_context);
     SubnetID subnet = host->getIPv4SubnetID();