]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Updated up to syntax
authorFrancis Dupont <fdupont@isc.org>
Sun, 17 Dec 2017 15:06:17 +0000 (16:06 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sun, 17 Dec 2017 15:06:17 +0000 (16:06 +0100)
doc/examples/kea4/advanced.json
doc/examples/kea4/comments.json
doc/examples/kea6/advanced.json
doc/examples/kea6/comments.json
doc/guide/dhcp4-srv.xml
doc/guide/dhcp6-srv.xml
doc/guide/hooks.xml
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp6/dhcp6_parser.yy

index 1d858cacee47d80d8673803b4086cd3ea659737b..624ca2b9fd4c6672670d2b2b2088b92ed3959e3a 100644 (file)
     // used directly.  It is intended to keep anything you may want to
     // put there - comments, extra designations, floor or department
     // names etc. These structures will be made available to Kea hooks.
-    // You can define multiple user-contexts in the same scope without
-    // the last one replacing previous values. A comment entry is
-    // translated into a user-context with a "comment" property so
-    // you can include comments inside the configuration itself.
+    // A comment entry is translated into a user-context with a
+    // "comment" property so you can include comments inside the
+    // configuration itself.
     "subnet4": [
         {
             "pools": [ {
index 245301473aad0f99275663bb168cbccd9217a702..7c23ee7b0b38cce6f54408b6b9d476e1d493a4d2 100644 (file)
        {
           "name": "none"
        },
-       // Two comments (or user contexts) in the same scope are combined
-       {
-          "comment": "first comment",
-          "comment": "second comment",
-          "name": "two"
-       },
-       // Of course this applies to a comment and a user context too
+       // A comment and a user-context can be specified
        {
           "comment": "a comment",
           "name": "both",
@@ -59,7 +53,6 @@
 
    // In control socket (more for the agent)
    "control-socket": {
-       "comment": "REST API",
        "socket-type": "unix",
        "socket-name": "/tmp/kea4-ctrl-socket",
        "user-context": { "comment": "Indirect comment" }
index fc9ab80278afca8f81b84c646da1044e88b7c47c..c7db6da2aecf219e24bca55d01b1e86a4948bb3c 100644 (file)
     // structures. You can put anything you want in the user-context
     // as long as it is a valid JSON and it starts with a map (i.e.
     // is enclosed by curly brackets).
-    // You can define multiple user-contexts in the same scope without
-    // the last one replacing previous values. A comment entry is
-    // translated into a user-context with a "comment" property so
-    // you can include comments inside the configuration itself.
+    // A comment entry is translated into a user-context with a
+    // "comment" property so you can include comments inside the
+    // configuration itself.
     "subnet6": [
     {
         "pools": [
index 8ba919a44ea47f525a557c1e4cd9111c71bfaa7d..7baea70fd0ff24824839f3e031ece24a87624e79 100644 (file)
        {
           "name": "none"
        },
-       // Two comments (or user contexts) in the same scope are combined
-       {
-          "comment": "first comment",
-          "comment": "second comment",
-          "name": "two"
-       },
-       // Of course this applies to a comment and a user context too
+       // A comment and        a user-context can be specified
        {
           "comment": "a comment",
           "name": "both",
@@ -59,7 +53,6 @@
 
    // In control socket (more for the agent)
    "control-socket": {
-       "comment": "REST API",
        "socket-type": "unix",
        "socket-name": "/tmp/kea6-ctrl-socket",
        "user-context": { "comment": "Indirect comment" }
index cf101ab28ceec569361a797843bfa425630d919c..c285396a5c9bdff3fcf2f2a0f0299ab88ab80911 100644 (file)
@@ -4638,9 +4638,8 @@ autogenerated IDs are not stable across configuration changes.</para>
         <para>
           User contexts can be specified on either global scope,
           shared network, subnet, pool, client class, option data or
-          definition level but not yet for a host reservation. One
-          other useful usage is the ability to store comments or
-          descriptions.
+          definition level, and host reservation. One other useful
+          usage is the ability to store comments or descriptions.
         </para>
 
         <para>
@@ -4686,8 +4685,8 @@ autogenerated IDs are not stable across configuration changes.</para>
           It should be noted that Kea will not use that information, but will
           simply store and make it available to hook libraries. It is up to the
           hook library to extract that information and make use of it.
-          The parser translates "comment" entries into a user-context
-          with the entry, this allows to attach comments inside the
+          The parser translates a "comment" entry into a user-context
+          with the entry, this allows to attach a comment inside the
           configuration itself.
         </para>
         <para>
index 9e59aba9b01f5993fb49b2cd245734cc9299690f..c323b76496338e6b2dc6562e0fde5aa1f5c8d277 100644 (file)
@@ -4599,9 +4599,8 @@ autogenerated IDs are not stable across configuration changes.
         <para>
           User contexts can be specified on either global scope,
           shared network, subnet, pool, client class, option data or
-          definition level but not yet for a host reservation. One
-          other useful usage is the ability to store comments or
-          descriptions.
+          definition level, and host reservation. One other useful
+          usage is the ability to store comments or descriptions.
         </para>
 
         <para>
@@ -4653,8 +4652,8 @@ autogenerated IDs are not stable across configuration changes.
           it just stores it, making it available to the hook
           libraries. It is up to each hook library to extract the information
           and make use of it.
-          The parser translates "comment" entries into a user-context
-          with the entry, this allows to attach comments inside the
+          The parser translates a "comment" entry into a user-context
+          with the entry, this allows to attach a comment inside the
           configuration itself.
         </para>
         <para>
index 2fc169d5450996695cf4b65622d696f297d1cc52..87474d317f3184328c0184d456cc7cf438f9198b 100644 (file)
@@ -2545,14 +2545,6 @@ both the command and the response.
       arbitrary complexity. Kea does not use that data on its own, simply stores
       and makes it available for the hook libraries.
       </para>
-      <para>
-        Usually when an entry is defined multiple times in the same scope
-        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.
-      </para>
       <para>
         Another use case for user contexts may be storing comments and other
         information that will be retained by Kea. Regular comments are discarded
index 2dc9968a451b50a42cc6170576beb0fee5195141..e5233c338db3efc687c64c0ba18586522d611241 100644 (file)
@@ -193,7 +193,7 @@ mysql_upgrade_test() {
 
     assert_str_eq "1.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 
-    # Ok, we have a 1.0 database. Let's upgrade it to 5.1
+    # Ok, we have a 1.0 database. Let's upgrade it to 6.0
     ${keaadmin} lease-upgrade mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
     ERRCODE=$?
 
@@ -295,6 +295,7 @@ EOF
     count=`echo $text | grep -ic "order by l\.address"`
     assert_eq 1 $count "lease6DumpData doesn't have order by clause. (returned count %d, expected %d)"
 
+    #table: host_identifier_type (upgrade 4.1 -> 5.0)
     # verify that host_identifier_type table exists.
     qry="select count(*) from host_identifier_type";
     count=`mysql_execute "${qry}"`
@@ -310,6 +311,7 @@ EOF
     assert_eq 0 $ERRCODE "show create table hosts failed. (expected status code %d, returned %d)"
     assert_eq 1 "$count" "show create table hosts did not return correct number of fk_host_identifier_type instances. (expected %d, returned %d)"
 
+    #table: dhcp_option_scope (upgrade 4.1 -> 5.0)
     # verify that dhcp_option_scope table exists.
     qry="select count(*) from dhcp_option_scope";
     count=`mysql_execute "${qry}"`
@@ -317,18 +319,21 @@ EOF
     assert_eq 0 $ERRCODE "select from dhcp_option_scope failed. (expected status code %d, returned %d)"
     assert_eq 4 "$count" "dhcp_option_scope does not contain correct number of entries. (expected %d, returned %d)"
 
+    #table: scope_id columns to dhcp4_options (upgrade 4.1 -> 5.0) 
     # verify that dhcp4_options table includes scope_id
     qry="select scope_id from dhcp4_options";
     count=`mysql_execute "${qry}"`
     ERRCODE=$?
     assert_eq 0 $ERRCODE "select scope_id from dhcp4_options failed. (expected status code %d, returned %d)"
 
+    #table: scope_id columns to dhcp6_options (upgrade 4.1 -> 5.0) 
     # verify that dhcp6_options table includes scope_id
     qry="select scope_id from dhcp6_options";
     count=`mysql_execute "${qry}"`
     ERRCODE=$?
     assert_eq 0 $ERRCODE "select scope_id from dhcp6_options failed. (expected status code %d, returned %d)"
 
+    #table: DHCPv4 fixed field colums (upgrade 4.1 -> 5.0)
     # verify that hosts table has columns holding values for DHCPv4 fixed fields
     qry="select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name from hosts";
     count=`mysql_execute "${qry}"`
@@ -351,9 +356,35 @@ EOF
     count=`echo $text | grep -ic unsigned`
     assert_eq 1 $count "dhcp6_subnet_id is not of unsigned type. (expected count %d, returned %d)"
 
-    # Verify upgraded schema reports version 5.1
+    #host_identifier_type should have rows for types 3 and 4 (upgrade 5.0 -> 5.1)
+    qry="select count(*) from host_identifier_type";
+    count=`mysql_execute "${qry}"`
+    ERRCODE=$?
+    assert_eq 0 $ERRCODE "select from host_identifier_type failed. (expected status code %d, returned %d)"
+    assert_eq 5 "$count" "host_identifier_type does not contain correct number of entries. (expected count %d, returned %d)"
+    
+    #table: user_context columns to hosts, dhcp4_options and dhcp6_options (upgrade 5.1 -> 6.0)
+    # verify that hosts table includes user_context
+    qry="select user_context from hosts";
+    count=`mysql_execute "${qry}"`
+    ERRCODE=$?
+    assert_eq 0 $ERRCODE "select user_context from hosts failed. (expected status code %d, returned %d)"
+
+    # verify that dhcp4_options table includes user_context
+    qry="select user_context from dhcp4_options";
+    count=`mysql_execute "${qry}"`
+    ERRCODE=$?
+    assert_eq 0 $ERRCODE "select user_context from dhcp4_options failed. (expected status code %d, returned %d)"
+
+    # verify that dhcp6_options table includes user_context
+    qry="select user_context from dhcp6_options";
+    count=`mysql_execute "${qry}"`
+    ERRCODE=$?
+    assert_eq 0 $ERRCODE "select user_context from dhcp6_options failed. (expected status code %d, returned %d)"
+
+    # Verify upgraded schema reports version 6.0
     version=$(${keaadmin} lease-version mysql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "5.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "6.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     mysql_wipe
index 41b7437e025f7febc64e564f1ecbe260a5db4906..0e95d2fe233cee3d68064bcbb1c3a6ab4df0f2cf 100644 (file)
@@ -89,7 +89,7 @@ pgsql_lease_version_test() {
 
     # Verify that kea-admin lease-version returns the correct version
     version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name)
-    assert_str_eq "3.2" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "4.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     pgsql_wipe
@@ -199,10 +199,10 @@ pgsql_upgrade_2_0_to_3_0() {
     assert_eq 1 "$output" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
 }
 
-pgsql_upgrade_3_0_to_3_1() {
-    # Verify upgraded schema reports version 3.1.
+pgsql_upgrade_3_0_to_4_0() {
+    # Verify upgraded schema reports version 4.0.
     version=$(${keaadmin} lease-version pgsql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir)
-    assert_str_eq "3.1" ${version} "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "4.0" ${version} "Expected kea-admin to return %s, returned value was %s"
 }
 
 pgsql_upgrade_test() {
@@ -224,8 +224,8 @@ pgsql_upgrade_test() {
     # Check 2.0 to 3.0 upgrade
     pgsql_upgrade_2_0_to_3_0
 
-    # Check 3.0 to 3.1 upgrade
-    pgsql_upgrade_3_0_to_3_1
+    # Check 3.0 to 4.0 upgrade
+    pgsql_upgrade_3_0_to_4_0
 
     # Let's wipe the whole database
     pgsql_wipe
index a701979f081213f752970e6778988e648ab204f8..2d05b23eecf95e80ac7f17958c5ffae072da1469 100644 (file)
@@ -1360,16 +1360,34 @@ pool_entry: POOL {
 user_context: USER_CONTEXT {
     ctx.enter(ctx.NO_KEYWORD);
 } COLON map_value {
-    ctx.stack_.back()->combine_set("user-context", $4);
+    ElementPtr parent = ctx.stack_.back();
+    ElementPtr user_context = $4;
+    ConstElementPtr old = parent->get("user-context");
+    if (old) {
+        if ((old->size() != 1) || !old->contains("comment")) {
+            std::stringstream msg;
+            msg << "duplicate user-context entries (previous at "
+                << old->getPosition().str() << ")";
+            error(@1, msg.str());
+        }
+        user_context->set("comment", old->get("comment"));
+    }
+    parent->set("user-context", user_context);
     ctx.leave();
 };
 
 comment: COMMENT {
     ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
-    ElementPtr e(new MapElement(ctx.loc2pos(@1)));
-    e->set("comment", $4);
-    ctx.stack_.back()->combine_set("user-context", e);
+} COLON STRING {
+    ElementPtr parent = ctx.stack_.back();
+    ConstElementPtr old = parent->get("user-context");
+    if (old) {
+        old->set("comment", $4);
+    } else {
+        ElementPtr e(new MapElement(ctx.loc2pos(@1)));
+        e->set("comment", $4);
+        top->set("user-context", e);
+    }
     ctx.leave();
 };
 
@@ -1633,8 +1651,8 @@ control_socket_params: control_socket_param
 
 control_socket_param: control_socket_type
                     | control_socket_name
-                    | control_socket_user_context
-                    | control_socket_comment
+                    | user_context
+                    | comment
                     | unknown_map_entry
                     ;
 
@@ -1654,15 +1672,6 @@ control_socket_name: SOCKET_NAME {
     ctx.leave();
 };
 
-control_socket_user_context: user_context;
-
-control_socket_comment: COMMENT {
-    ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
-    ctx.stack_.back()->combine_set("comment", $4);
-    ctx.leave();
-};
-
 // --- dhcp ddns ---------------------------------------------
 
 dhcp_ddns: DHCP_DDNS {
index f7bb0592941207ccbd6d73e6342208f526e7a818..ca9f3f4dabe9b4317466efc490b0769dbb07a918 100644 (file)
@@ -1323,16 +1323,34 @@ pool_entry: POOL {
 user_context: USER_CONTEXT {
     ctx.enter(ctx.NO_KEYWORD);
 } COLON map_value {
-    ctx.stack_.back()->combine_set("user-context", $4);
+    ElementPtr parent = ctx.stack_.back();
+    ElementPtr user_context = $4;
+    ConstElementPtr old = parent->get("user-context");
+    if (old) {
+        if ((old->size() != 1) || !old->contains("comment")) {
+            std::stringstream msg;
+            msg << "duplicate user-context entries (previous at "
+                << old->getPosition().str() << ")";
+            error(@1, msg.str());
+        }
+        user_context->set("comment", old->get("comment"));
+    }
+    parent->set("user-context", user_context);
     ctx.leave();
 };
 
 comment: COMMENT {
     ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
-    ElementPtr e(new MapElement(ctx.loc2pos(@1)));
-    e->set("comment", $4);
-    ctx.stack_.back()->combine_set("user-context", e);
+} COLON STRING {
+    ElementPtr parent = ctx.stack_.back();
+    ConstElementPtr old = parent->get("user-context");
+    if (old) {
+        old->set("comment", $4);
+    } else {
+        ElementPtr e(new MapElement(ctx.loc2pos(@1)));
+        e->set("comment", $4);
+        top->set("user-context", e);
+    }
     ctx.leave();
 };
 
@@ -1716,8 +1734,8 @@ control_socket_params: control_socket_param
 
 control_socket_param: socket_type
                     | socket_name
-                    | socket_user_context
-                    | socket_comment
+                    | user_context
+                    | comment
                     | unknown_map_entry
                     ;
 
@@ -1737,15 +1755,6 @@ socket_name: SOCKET_NAME {
     ctx.leave();
 };
 
-socket_user_context: user_context;
-
-socket_comment: COMMENT {
-    ctx.enter(ctx.NO_KEYWORD);
-} COLON value {
-    ctx.stack_.back()->combine_set("comment", $4);
-    ctx.leave();
-};
-
 // --- dhcp ddns ---------------------------------------------
 
 dhcp_ddns: DHCP_DDNS {