ovsdb-data: Verify that named-uuid string is an <id>.
authorBen Pfaff <blp@nicira.com>
Mon, 28 Feb 2011 23:43:29 +0000 (15:43 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 10 Mar 2011 19:23:59 +0000 (11:23 -0800)
The "uuid-name" that creates symbols must be an <id> but we weren't
verifying the same constraint on the "named-uuid"s that refer to symbols,
which was a bit confusing in writing transactions by hand.  This commit
fixes the inconsistency and updates the SPECS file to clarify that a
named-uuid string has to be an <id>.

lib/ovsdb-data.c
ovsdb/SPECS
tests/ovsdb-execution.at

index c373be9a9e61f0fb17979bf57d87a8f4b01d0d17..1a07524472a121a3f69e09c77881b4240d235672 100644 (file)
@@ -26,6 +26,7 @@
 #include "dynamic-string.h"
 #include "hash.h"
 #include "ovsdb-error.h"
+#include "ovsdb-parser.h"
 #include "json.h"
 #include "shash.h"
 #include "sort.h"
@@ -307,6 +308,10 @@ ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
 
             ovsdb_error_destroy(error0);
             *uuid = ovsdb_symbol_table_insert(symtab, name)->uuid;
+            if (!ovsdb_parser_is_id(json_string(value))) {
+                return ovsdb_syntax_error(json, NULL, "named-uuid string is "
+                                          "not a valid <id>");
+            }
             return NULL;
         }
         ovsdb_error_destroy(error1);
index 2c83cf2a66c0514dc2ff22f0f660f0a6106db6c7..d64812ae6589fdb2fcd6ee09d8f677d225adc1ae 100644 (file)
@@ -679,7 +679,7 @@ Notation for the Wire Protocol
     A 2-element JSON array that represents the UUID of a row inserted
     in an "insert" operation within the same transaction.  The first
     element of the array must be the string "named-uuid" and the
-    second element should be the string specified as the "uuid-name"
+    second element should be the <id> specified as the "uuid-name"
     for an "insert" operation within the same transaction.  For
     example, if an "insert" operation within this transaction
     specifies a "uuid-name" of "myrow", the following <named-uuid>
index d4f2380f8931dd9b2b0232b25364c8aec1df98e9..47be1935fe897c1ce84aa9efe67bb632166552d3 100644 (file)
@@ -77,6 +77,25 @@ m4_define([OVSDB_CHECK_EXECUTION],
    AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [$4])
    AT_CLEANUP])
 
+OVSDB_CHECK_EXECUTION([uuid-name must be <id>],
+  [CONSTRAINT_SCHEMA],
+  [[[["constraints",
+      {"op": "insert",
+       "table": "a",
+       "row": {},
+       "uuid-name": "0"}]]]],
+  [[[{"details":"Parsing ovsdb operation 1 of 1 failed: Type mismatch for member 'uuid-name'.","error":"syntax error","syntax":"{\"op\":\"insert\",\"row\":{},\"table\":\"a\",\"uuid-name\":\"0\"}"}]
+]])
+
+OVSDB_CHECK_EXECUTION([named-uuid must be <id>],
+  [CONSTRAINT_SCHEMA],
+  [[[["constraints",
+      {"op": "insert",
+       "table": "a",
+       "row": {"a2a": ["named-uuid", "0"]}}]]]],
+  [[[{"details":"named-uuid string is not a valid <id>","error":"syntax error","syntax":"[\"named-uuid\",\"0\"]"}]
+]])
+
 m4_define([EXECUTION_EXAMPLES], [
 dnl At one point the "commit" code ignored new rows with all-default values,
 dnl so this checks for that problem.